367367}
368368
369369func TestIncludes (t * testing.T ) {
370- files := []string {}
371- cleanFiles := func () {
372- for _ , file := range files {
373- os .Remove (file )
374- }
375- files = files [:0 ]
376- }
377- defer cleanFiles ()
378-
379370 createFile := func (t * testing.T , suffix , content string ) string {
380371 t .Helper ()
381372 name := ""
@@ -384,7 +375,9 @@ func TestIncludes(t *testing.T) {
384375 defer file .Close ()
385376 _ , err = file .WriteString (content )
386377 name = file .Name ()
387- files = append (files , name )
378+ t .Cleanup (func () {
379+ _ = os .Remove (name )
380+ })
388381 }
389382 require .NoError (t , err )
390383 return name
@@ -400,7 +393,6 @@ func TestIncludes(t *testing.T) {
400393 testID := fmt .Sprintf ("%d" , time .Now ().Unix ())
401394
402395 t .Run ("multiple-includes" , func (t * testing.T ) {
403- defer cleanFiles ()
404396 content := fmt .Sprintf (`includes=['*%[1]s.inc.toml','*%[1]s.inc.yaml','*%[1]s.inc.json']` , testID )
405397
406398 configFile := createFile (t , "profiles.conf" , content )
@@ -416,8 +408,6 @@ func TestIncludes(t *testing.T) {
416408 })
417409
418410 t .Run ("overrides" , func (t * testing.T ) {
419- defer cleanFiles ()
420-
421411 configFile := createFile (t , "profiles.conf" , `
422412includes = "*` + testID + `.inc.toml"
423413[default]
@@ -436,8 +426,6 @@ repository = "overridden-repo"`)
436426 })
437427
438428 t .Run ("mixins" , func (t * testing.T ) {
439- defer cleanFiles ()
440-
441429 configFile := createFile (t , "profiles.conf" , `
442430version = 2
443431includes = "*` + testID + `.inc.toml"
@@ -464,8 +452,6 @@ use = "another-run-before2"`)
464452 })
465453
466454 t .Run ("hcl-includes-only-hcl" , func (t * testing.T ) {
467- defer cleanFiles ()
468-
469455 configFile := createFile (t , "profiles.hcl" , `includes = "*` + testID + `.inc.*"` )
470456 createFile (t , "pass-" + testID + ".inc.hcl" , `one { }` )
471457
@@ -474,13 +460,11 @@ use = "another-run-before2"`)
474460
475461 createFile (t , "fail-" + testID + ".inc.toml" , `[two]` )
476462 _ , err := LoadFile (configFile , "" )
477- assert .Error (t , err )
463+ require .Error (t , err )
478464 assert .Regexp (t , ".+ is in hcl format, includes must use the same format" , err .Error ())
479465 })
480466
481467 t .Run ("non-hcl-include-no-hcl" , func (t * testing.T ) {
482- defer cleanFiles ()
483-
484468 configFile := createFile (t , "profiles.toml" , `includes = "*` + testID + `.inc.*"` )
485469 createFile (t , "pass-" + testID + ".inc.toml" , "[one]\n k='v'" )
486470
@@ -489,12 +473,11 @@ use = "another-run-before2"`)
489473
490474 createFile (t , "fail-" + testID + ".inc.hcl" , `one { }` )
491475 _ , err := LoadFile (configFile , "" )
492- assert .Error (t , err )
476+ require .Error (t , err )
493477 assert .Regexp (t , "hcl format .+ cannot be used in includes from toml" , err .Error ())
494478 })
495479
496480 t .Run ("cannot-load-different-versions" , func (t * testing.T ) {
497- defer cleanFiles ()
498481 content := fmt .Sprintf (`includes=['*%s.inc.json']` , testID )
499482
500483 configFile := createFile (t , "profiles.conf" , content )
@@ -506,7 +489,6 @@ use = "another-run-before2"`)
506489 })
507490
508491 t .Run ("cannot-load-different-versions" , func (t * testing.T ) {
509- defer cleanFiles ()
510492 content := fmt .Sprintf (`{"version": 2, "includes":["*%s.inc.json"]}` , testID )
511493
512494 configFile := createFile (t , "profiles.json" , content )
0 commit comments