diff --git a/pkg/filter/driftignore_test.go b/pkg/filter/driftignore_test.go index 62fd2d5b..b0fa736f 100644 --- a/pkg/filter/driftignore_test.go +++ b/pkg/filter/driftignore_test.go @@ -109,6 +109,48 @@ func TestDriftIgnore_IsResourceIgnored(t *testing.T) { true, }, }, + { + name: "drift_ignore_wildcard", + resources: []resource.Resource{ + &resource2.FakeResource{ + Type: "type1", + Id: "id1", + }, + &resource2.FakeResource{ + Type: "type2", + Id: "id1", + }, + &resource2.FakeResource{ + Type: "type2", + Id: "id11", + }, + &resource2.FakeResource{ + Type: "type2", + Id: "id2", + }, + &resource2.FakeResource{ + Type: "type3", + Id: "id100", + }, + &resource2.FakeResource{ + Type: "type3", + Id: "id101", + }, + &resource2.FakeResource{ + Type: "type4", + Id: "id\\WithBac*slash***\\*\\", + }, + }, + want: []bool{ + false, + true, + true, + false, + true, + false, + true, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -280,6 +322,31 @@ func Test_escapableSplit(t *testing.T) { line: "*.subfoobar", want: []string{"*", "subfoobar"}, }, + { + name: "text wildcard dot", + line: "res*.subfoobar", + want: []string{"res*", "subfoobar"}, + }, + { + name: "missing text multiple wildcard dot", + line: "r*s*.s**ub***ob********a*r", + want: []string{"r*s*", "s*ub*ob*a*r"}, + }, + { + name: "prefix wildcard dot", + line: "*res.subfoobar", + want: []string{"*res", "subfoobar"}, + }, + { + name: "suffix multiple wildcard dot", + line: "res.subfoobar*****", + want: []string{"res", "subfoobar*"}, + }, + { + name: "dot wildcard", + line: "res.*", + want: []string{"res", "*"}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/filter/testdata/drift_ignore_wildcard/.driftignore b/pkg/filter/testdata/drift_ignore_wildcard/.driftignore new file mode 100644 index 00000000..af4b7484 --- /dev/null +++ b/pkg/filter/testdata/drift_ignore_wildcard/.driftignore @@ -0,0 +1,5 @@ +*2**.**d1* +type3.id1***0 +*.id\\WithBa*slas*\\**\\ + +# this is *** comment