2020-12-15 10:07:03 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-07-21 08:37:03 +00:00
|
|
|
"github.com/snyk/driftctl/pkg/resource/aws"
|
2020-12-15 10:07:03 +00:00
|
|
|
|
2022-06-28 07:23:29 +00:00
|
|
|
"github.com/snyk/driftctl/enumeration/resource"
|
2020-12-15 10:07:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAwsDefaultVPCShouldBeIgnored(t *testing.T) {
|
|
|
|
middleware := NewAwsDefaultVPC()
|
2021-08-09 14:03:04 +00:00
|
|
|
remoteResources := []*resource.Resource{
|
|
|
|
{
|
2021-05-10 16:02:57 +00:00
|
|
|
Id: "foobar",
|
|
|
|
Type: aws.AwsDefaultVpcResourceType,
|
|
|
|
Attrs: &resource.Attributes{
|
|
|
|
"id": "foobar",
|
|
|
|
},
|
2020-12-15 10:07:03 +00:00
|
|
|
},
|
|
|
|
}
|
2021-08-09 14:03:04 +00:00
|
|
|
stateResources := []*resource.Resource{}
|
2020-12-15 10:07:03 +00:00
|
|
|
err := middleware.Execute(&remoteResources, &stateResources)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(remoteResources) != 0 {
|
|
|
|
t.Error("Default VPC was not ignored")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAwsDefaultVPCShouldNotBeIgnoredWhenManaged(t *testing.T) {
|
|
|
|
middleware := NewAwsDefaultVPC()
|
2021-08-09 14:03:04 +00:00
|
|
|
remoteResources := []*resource.Resource{
|
|
|
|
{
|
2021-05-10 16:02:57 +00:00
|
|
|
Id: "foobar",
|
|
|
|
Type: aws.AwsDefaultVpcResourceType,
|
|
|
|
Attrs: &resource.Attributes{
|
|
|
|
"id": "foobar",
|
|
|
|
},
|
2020-12-15 10:07:03 +00:00
|
|
|
},
|
|
|
|
}
|
2021-08-09 14:03:04 +00:00
|
|
|
stateResources := []*resource.Resource{
|
|
|
|
{
|
2021-05-21 14:09:45 +00:00
|
|
|
Id: "foobar",
|
|
|
|
Type: aws.AwsDefaultVpcResourceType,
|
|
|
|
Attrs: &resource.Attributes{
|
|
|
|
"id": "foobar",
|
|
|
|
},
|
2020-12-15 10:07:03 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
err := middleware.Execute(&remoteResources, &stateResources)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(remoteResources) != 1 {
|
|
|
|
t.Error("Default VPC was ignored")
|
|
|
|
}
|
|
|
|
}
|