test(middlewares): aws security group rule defaults

main
sundowndev 2021-03-31 14:07:26 +02:00
parent f01227d35a
commit 2c8a0f7fc1
3 changed files with 15 additions and 8 deletions

View File

@ -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
}

View File

@ -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{}

View File

@ -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)