@@ -3,9 +3,11 @@ package filter_test
33import (
44 "testing"
55
6+ "github.com/gruntwork-io/terragrunt/config"
67 "github.com/gruntwork-io/terragrunt/internal/component"
78 "github.com/gruntwork-io/terragrunt/internal/filter"
89 "github.com/gruntwork-io/terragrunt/pkg/log"
10+ "github.com/gruntwork-io/terragrunt/test/helpers"
911 "github.com/stretchr/testify/assert"
1012 "github.com/stretchr/testify/require"
1113)
@@ -263,6 +265,67 @@ func TestEvaluate_AttributeFilter_Reading(t *testing.T) {
263265 }
264266}
265267
268+ func TestEvaluate_AttributeFilter_Source (t * testing.T ) {
269+ t .Parallel ()
270+
271+ components := []component.Component {
272+ component .NewUnit ("./apps/app1" ).WithConfig (
273+ & config.TerragruntConfig {
274+ Terraform : & config.TerraformConfig {
275+ Source : helpers .PointerTo ("github.com/acme/foo" ),
276+ },
277+ },
278+ ),
279+ component .NewUnit ("./apps/app2" ).WithConfig (
280+ & config.TerragruntConfig {
281+ Terraform : & config.TerraformConfig {
282+ Source :
helpers .
PointerTo (
"git::[email protected] :acme/bar?ref=v1.0.0" ),
283+ },
284+ },
285+ ),
286+ }
287+
288+ tests := []struct {
289+ name string
290+ filter * filter.AttributeFilter
291+ expected []component.Component
292+ }{
293+ {
294+ name : "glob pattern with single wildcard - github.com/acme/*" ,
295+ filter : & filter.AttributeFilter {Key : "source" , Value : "github.com/acme/*" },
296+ expected : []component.Component {
297+ components [0 ],
298+ },
299+ },
300+ {
301+ name :
"glob pattern with double wildcard - git::[email protected] :acme/**" ,
302+ filter :
& filter.
AttributeFilter {
Key :
"source" ,
Value :
"git::[email protected] :acme/**" },
303+ expected : []component.Component {
304+ components [1 ],
305+ },
306+ },
307+ {
308+ name : "glob pattern with double wildcard - **github.com**" ,
309+ filter : & filter.AttributeFilter {Key : "source" , Value : "**github.com**" },
310+ expected : []component.Component {
311+ components [0 ],
312+ components [1 ],
313+ },
314+ },
315+ }
316+
317+ for _ , tt := range tests {
318+ t .Run (tt .name , func (t * testing.T ) {
319+ t .Parallel ()
320+
321+ l := log .New ()
322+ result , err := filter .Evaluate (l , tt .filter , components )
323+ require .NoError (t , err )
324+ assert .ElementsMatch (t , tt .expected , result )
325+ })
326+ }
327+ }
328+
266329func TestEvaluate_AttributeFilter_Reading_ComponentAddedOnlyOnce (t * testing.T ) {
267330 t .Parallel ()
268331
0 commit comments