@@ -225,11 +225,9 @@ func TestStackDepsE2EBasic(t *testing.T) {
225225
226226 helpers .RunTerragrunt (t , "terragrunt run --all --non-interactive --experiment stack-dependencies --working-dir " + rootPath + " -- apply -auto-approve" )
227227
228- inputFiles , err := filepath .Glob (filepath .Join (rootPath , ".terragrunt-stack" , "unit-w-inputs" , ".terragrunt-cache" , "*" , "*" , "input.txt" ))
229- require .NoError (t , err )
230- require .Len (t , inputFiles , 1 )
228+ inputPath := helpers .FindCachedFile (t , filepath .Join (rootPath , ".terragrunt-stack" , "unit-w-inputs" ), "input.txt" )
231229
232- inputContent , err := os .ReadFile (inputFiles [ 0 ] )
230+ inputContent , err := os .ReadFile (inputPath )
233231 require .NoError (t , err )
234232 assert .Equal (t , "Received: Hello!" , string (inputContent ))
235233
@@ -258,28 +256,24 @@ func TestStackDepsE2EChain(t *testing.T) {
258256 helpers .RunTerragrunt (t , "terragrunt run --all --non-interactive --experiment stack-dependencies --working-dir " + rootPath + " -- apply -auto-approve" )
259257
260258 // Verify unit-a received chained output: from-b(from-c)
261- markerA , err := filepath .Glob (filepath .Join (rootPath , ".terragrunt-stack" , "unit-a" , ".terragrunt-cache" , "*" , "*" , "marker.txt" ))
262- require .NoError (t , err )
263- require .Len (t , markerA , 1 )
259+ markerA := helpers .FindCachedFile (t , filepath .Join (rootPath , ".terragrunt-stack" , "unit-a" ), "marker.txt" )
264260
265- contentA , err := os .ReadFile (markerA [ 0 ] )
261+ contentA , err := os .ReadFile (markerA )
266262 require .NoError (t , err )
267263 assert .Equal (t , "unit-a received: from-b(from-c)" , string (contentA ))
268264
269265 // Verify unit-b received: from-c
270- markerB , err := filepath .Glob (filepath .Join (rootPath , ".terragrunt-stack" , "unit-b" , ".terragrunt-cache" , "*" , "*" , "marker.txt" ))
271- require .NoError (t , err )
272- require .Len (t , markerB , 1 )
266+ markerB := helpers .FindCachedFile (t , filepath .Join (rootPath , ".terragrunt-stack" , "unit-b" ), "marker.txt" )
273267
274- contentB , err := os .ReadFile (markerB [ 0 ] )
268+ contentB , err := os .ReadFile (markerB )
275269 require .NoError (t , err )
276270 assert .Equal (t , "unit-b received: from-c" , string (contentB ))
277271
278272 helpers .RunTerragrunt (t , "terragrunt run --all --non-interactive --experiment stack-dependencies --working-dir " + rootPath + " -- destroy -auto-approve" )
279273
280274 // Destroy must remove the marker files produced by apply.
281- assert .NoFileExists (t , markerA [ 0 ] )
282- assert .NoFileExists (t , markerB [ 0 ] )
275+ assert .NoFileExists (t , markerA )
276+ assert .NoFileExists (t , markerB )
283277}
284278
285279// TestStackDepsE2ECrossStack tests stack generation with cross-stack dependencies:
@@ -523,14 +517,14 @@ func TestStackDepsFindJSON(t *testing.T) {
523517 continue
524518 }
525519
526- if strings . HasSuffix (c .Path , "unit-w-inputs" ) {
520+ if filepath . Base (c .Path ) == "unit-w-inputs" {
527521 foundInputs = true
528522
529523 require .Len (t , c .Dependencies , 1 )
530524 assert .Contains (t , c .Dependencies [0 ], "unit-w-outputs" )
531525 }
532526
533- if strings . HasSuffix (c .Path , "unit-w-outputs" ) {
527+ if filepath . Base (c .Path ) == "unit-w-outputs" {
534528 foundOutputs = true
535529
536530 assert .Empty (t , c .Dependencies )
@@ -652,11 +646,11 @@ func TestStackDepsFindChain(t *testing.T) {
652646
653647 for path := range depsByPath {
654648 switch {
655- case strings . HasSuffix (path , "unit-a" ) :
649+ case filepath . Base (path ) == "unit-a" :
656650 unitAPath = path
657- case strings . HasSuffix (path , "unit-b" ) :
651+ case filepath . Base (path ) == "unit-b" :
658652 unitBPath = path
659- case strings . HasSuffix (path , "unit-c" ) :
653+ case filepath . Base (path ) == "unit-c" :
660654 unitCPath = path
661655 }
662656 }
@@ -713,15 +707,15 @@ func TestStackDepsFindTree(t *testing.T) {
713707
714708 for path := range depsByPath {
715709 switch {
716- case strings . HasSuffix (path , "unit-a" ) :
710+ case filepath . Base (path ) == "unit-a" :
717711 aPath = path
718- case strings . HasSuffix (path , "unit-b" ) :
712+ case filepath . Base (path ) == "unit-b" :
719713 bPath = path
720- case strings . HasSuffix (path , "unit-c" ) :
714+ case filepath . Base (path ) == "unit-c" :
721715 cPath = path
722- case strings . HasSuffix (path , "unit-d" ) :
716+ case filepath . Base (path ) == "unit-d" :
723717 dPath = path
724- case strings . HasSuffix (path , "unit-e" ) :
718+ case filepath . Base (path ) == "unit-e" :
725719 ePath = path
726720 }
727721 }
@@ -802,26 +796,22 @@ func TestStackDepsE2ETree(t *testing.T) {
802796 helpers .RunTerragrunt (t , "terragrunt run --all --non-interactive --experiment stack-dependencies --working-dir " + rootPath + " -- apply -auto-approve" )
803797
804798 // Verify unit-b received outputs from D and E
805- markerB , err := filepath .Glob (filepath .Join (rootPath , ".terragrunt-stack" , "unit-b" , ".terragrunt-cache" , "*" , "*" , "marker.txt" ))
806- require .NoError (t , err )
807- require .Len (t , markerB , 1 )
799+ markerB := helpers .FindCachedFile (t , filepath .Join (rootPath , ".terragrunt-stack" , "unit-b" ), "marker.txt" )
808800
809- contentB , err := os .ReadFile (markerB [ 0 ] )
801+ contentB , err := os .ReadFile (markerB )
810802 require .NoError (t , err )
811803 assert .Equal (t , "unit-b(from-d,from-e)" , string (contentB ))
812804
813805 // Verify unit-a received outputs from B and C
814- markerA , err := filepath .Glob (filepath .Join (rootPath , ".terragrunt-stack" , "unit-a" , ".terragrunt-cache" , "*" , "*" , "marker.txt" ))
815- require .NoError (t , err )
816- require .Len (t , markerA , 1 )
806+ markerA := helpers .FindCachedFile (t , filepath .Join (rootPath , ".terragrunt-stack" , "unit-a" ), "marker.txt" )
817807
818- contentA , err := os .ReadFile (markerA [ 0 ] )
808+ contentA , err := os .ReadFile (markerA )
819809 require .NoError (t , err )
820810 assert .Equal (t , "unit-a(from-b(from-d,from-e),from-c)" , string (contentA ))
821811
822812 helpers .RunTerragrunt (t , "terragrunt run --all --non-interactive --experiment stack-dependencies --working-dir " + rootPath + " -- destroy -auto-approve" )
823813
824814 // Destroy must remove the marker files produced by apply.
825- assert .NoFileExists (t , markerA [ 0 ] )
826- assert .NoFileExists (t , markerB [ 0 ] )
815+ assert .NoFileExists (t , markerA )
816+ assert .NoFileExists (t , markerB )
827817}
0 commit comments