Skip to content

Commit 31e9565

Browse files
committed
Update TestFindConfigFilesIgnoresTerraformDataDirEnvRoot for tests
1 parent 9f01e74 commit 31e9565

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

config/config_test.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"sort"
910
"testing"
1011

1112
"github.com/gruntwork-io/terragrunt/codegen"
@@ -714,7 +715,6 @@ func TestParseTerragruntConfigThreeLevels(t *testing.T) {
714715
}
715716

716717
opts := mockOptionsForTestWithConfigPath(t, configPath)
717-
718718
ctx := config.NewParsingContext(context.Background(), opts)
719719

720720
_, actualErr := config.ParseConfigString(ctx, configPath, cfg, nil)
@@ -1127,20 +1127,38 @@ func TestFindConfigFilesIgnoresTerraformDataDirEnvRoot(t *testing.T) {
11271127
cwd, err := os.Getwd()
11281128
require.NoError(t, err)
11291129

1130-
expected := []string{
1131-
filepath.Join(cwd, "../test/fixtures/config-files/ignore-terraform-data-dir/subdir/terragrunt.hcl"),
1132-
filepath.Join(cwd, "../test/fixtures/config-files/ignore-terraform-data-dir/subdir/.terraform/modules/mod/terragrunt.hcl"),
1133-
filepath.Join(cwd, "../test/fixtures/config-files/ignore-terraform-data-dir/subdir/.tf_data/modules/mod/terragrunt.hcl"),
1134-
}
11351130
workingDir := filepath.Join(cwd, "../test/fixtures/config-files/ignore-terraform-data-dir/")
11361131
terragruntOptions, err := options.NewTerragruntOptionsForTest(workingDir)
11371132
require.NoError(t, err)
11381133
terragruntOptions.Env["TF_DATA_DIR"] = filepath.Join(workingDir, ".tf_data")
11391134

11401135
actual, err := config.FindConfigFilesInPath(workingDir, terragruntOptions)
1141-
11421136
require.NoError(t, err, "Unexpected error: %v", err)
1143-
assert.ElementsMatch(t, expected, actual)
1137+
1138+
// Create expected paths using filepath.Join for cross-platform compatibility
1139+
expected := []string{
1140+
filepath.Join(cwd, "../test/fixtures/config-files/ignore-terraform-data-dir/subdir/terragrunt.hcl"),
1141+
filepath.Join(cwd, "../test/fixtures/config-files/ignore-terraform-data-dir/subdir/.terraform/modules/mod/terragrunt.hcl"),
1142+
filepath.Join(cwd, "../test/fixtures/config-files/ignore-terraform-data-dir/subdir/.tf_data/modules/mod/terragrunt.hcl"),
1143+
}
1144+
1145+
// Sort both slices to ensure consistent order for comparison
1146+
sort.Strings(actual)
1147+
sort.Strings(expected)
1148+
1149+
// Compare the paths using filepath.Clean to normalize them
1150+
normalizedActual := make([]string, len(actual))
1151+
normalizedExpected := make([]string, len(expected))
1152+
1153+
for i, path := range actual {
1154+
normalizedActual[i] = filepath.Clean(path)
1155+
}
1156+
1157+
for i, path := range expected {
1158+
normalizedExpected[i] = filepath.Clean(path)
1159+
}
1160+
1161+
assert.Equal(t, normalizedExpected, normalizedActual)
11441162
}
11451163

11461164
func TestFindConfigFilesIgnoresDownloadDir(t *testing.T) {

0 commit comments

Comments
 (0)