From 2c8a0f7fc1edcb670b867214af8d299ad9cb67aa Mon Sep 17 00:00:00 2001 From: sundowndev Date: Wed, 31 Mar 2021 14:07:26 +0200 Subject: [PATCH] test(middlewares): aws security group rule defaults --- pkg/middlewares/aws_security_group_defaults.go | 4 +++- .../aws_security_group_rules_defaults.go | 2 -- .../aws_security_group_rules_defaults_test.go | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/middlewares/aws_security_group_defaults.go b/pkg/middlewares/aws_security_group_defaults.go index 06213b54..9923d876 100644 --- a/pkg/middlewares/aws_security_group_defaults.go +++ b/pkg/middlewares/aws_security_group_defaults.go @@ -7,6 +7,8 @@ import ( "github.com/cloudskiff/driftctl/pkg/resource/aws" ) +const defaultAwsSecurityGroupName = "default" + // When scanning a brand new AWS account, some users may see irrelevant results about default AWS role policies. // We ignore these resources by default when strict mode is disabled. type AwsSecurityGroupDefaults struct{} @@ -33,7 +35,7 @@ func (m AwsSecurityGroupDefaults) Execute(remoteResources, resourcesFromState *[ } } - if existInState || *remoteResource.(*aws.AwsSecurityGroup).Name != "default" { + if existInState || *remoteResource.(*aws.AwsSecurityGroup).Name != defaultAwsSecurityGroupName { newRemoteResources = append(newRemoteResources, remoteResource) continue } diff --git a/pkg/middlewares/aws_security_group_rules_defaults.go b/pkg/middlewares/aws_security_group_rules_defaults.go index 3e4586a8..da05d2ed 100644 --- a/pkg/middlewares/aws_security_group_rules_defaults.go +++ b/pkg/middlewares/aws_security_group_rules_defaults.go @@ -7,8 +7,6 @@ import ( "github.com/cloudskiff/driftctl/pkg/resource/aws" ) -const defaultAwsSecurityGroupName = "default" - // When scanning a brand new AWS account, some users may see irrelevant results about default AWS role policies. // We ignore these resources by default when strict mode is disabled. type AwsSecurityGroupRuleDefaults struct{} diff --git a/pkg/middlewares/aws_security_group_rules_defaults_test.go b/pkg/middlewares/aws_security_group_rules_defaults_test.go index 2ed5bf1f..87f6e67d 100644 --- a/pkg/middlewares/aws_security_group_rules_defaults_test.go +++ b/pkg/middlewares/aws_security_group_rules_defaults_test.go @@ -54,7 +54,17 @@ func TestAwsSecurityGroupRuleDefaults_Execute(t *testing.T) { GatewayId: awssdk.String("local"), }, }, - diff.Changelog{}, + diff.Changelog{ + { + Type: "delete", + Path: []string{"0"}, + From: &aws.AwsSecurityGroup{ + Id: defaultSecurityGroupId, + Name: &defaultSecurityGroupName, + }, + To: nil, + }, + }, }, { "default security group when they're managed by IaC", @@ -110,10 +120,7 @@ func TestAwsSecurityGroupRuleDefaults_Execute(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - m := NewChain( - NewAwsSecurityGroupDefaults(), - NewAwsSecurityGroupRuleDefaults(), - ) + m := NewAwsSecurityGroupRuleDefaults() err := m.Execute(&tt.remoteResources, &tt.resourcesFromState) if err != nil { t.Fatal(err)