Skip to content

Commit 0a9b1f1

Browse files
committed
chore: failing tests fixes
1 parent 84adc4b commit 0a9b1f1

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

internal/component/component.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,37 @@
88
package component
99

1010
import (
11+
"path/filepath"
1112
"slices"
1213
"sort"
1314
"sync"
1415

1516
"github.com/gruntwork-io/terragrunt/internal/errors"
1617
)
1718

19+
// resolvedPathMemo caches results of filepath.EvalSymlinks to reduce repeated system calls.
20+
var resolvedPathMemo sync.Map // map[string]string
21+
22+
// resolvePath resolves symlinks in a path for consistent comparison across platforms.
23+
// On macOS, /var is a symlink to /private/var, so paths must be resolved.
24+
func resolvePath(path string) string {
25+
if v, ok := resolvedPathMemo.Load(path); ok {
26+
if s, ok := v.(string); ok {
27+
return s
28+
}
29+
}
30+
31+
resolved, err := filepath.EvalSymlinks(path)
32+
if err != nil {
33+
resolvedPathMemo.Store(path, path)
34+
return path
35+
}
36+
37+
resolvedPathMemo.Store(path, resolved)
38+
39+
return resolved
40+
}
41+
1842
// Kind is the type of Terragrunt component.
1943
type Kind string
2044

@@ -236,12 +260,15 @@ func (tsc *ThreadSafeComponents) addComponent(c Component) (Component, bool) {
236260
}
237261

238262
// FindByPath searches for a component by its path and returns it if found, otherwise returns nil.
263+
// Paths are resolved to handle symlinks consistently across platforms (e.g., macOS /var -> /private/var).
239264
func (tsc *ThreadSafeComponents) FindByPath(path string) Component {
240265
tsc.mu.RLock()
241266
defer tsc.mu.RUnlock()
242267

268+
resolvedSearchPath := resolvePath(path)
269+
243270
for _, c := range tsc.components {
244-
if c.Path() == path {
271+
if resolvePath(c.Path()) == resolvedSearchPath {
245272
return c
246273
}
247274
}

internal/discovery/dependentdiscovery.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ func (dd *DependentDiscovery) DiscoverDependents(
339339

340340
candidate.AddDependency(c)
341341

342-
if dep == target.Path() {
342+
// Use resolved paths for comparison to handle symlinks (e.g., macOS /var -> /private/var)
343+
if resolvePath(dep) == resolvePath(target.Path()) {
343344
dependsOnTarget = true
344345
}
345346
}

internal/discovery/discovery.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,9 @@ func extractDependencyPaths(cfg *config.TerragruntConfig, component component.Co
15721572
depPath = filepath.Clean(filepath.Join(component.Path(), depPath))
15731573
}
15741574

1575+
// Resolve symlinks for consistent path comparison (e.g., macOS /var -> /private/var)
1576+
depPath = resolvePath(depPath)
1577+
15751578
deduped[depPath] = struct{}{}
15761579
}
15771580

@@ -1581,6 +1584,9 @@ func extractDependencyPaths(cfg *config.TerragruntConfig, component component.Co
15811584
dependency = filepath.Clean(filepath.Join(component.Path(), dependency))
15821585
}
15831586

1587+
// Resolve symlinks for consistent path comparison (e.g., macOS /var -> /private/var)
1588+
dependency = resolvePath(dependency)
1589+
15841590
deduped[dependency] = struct{}{}
15851591
}
15861592
}

test/fixtures/auth-provider-parallel/auth-provider.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ mkdir -p "$LOCK_DIR"
1313
# This works on Linux, macOS, and BSD without requiring nanosecond precision
1414
INVOCATION_ID="auth-$$-$(date +%s)-$RANDOM"
1515

16-
# Log to stderr so it shows up in terragrunt output
17-
echo "Auth start ${INVOCATION_ID}" >&2
18-
1916
# Create a lock file to indicate we've started
17+
# This acts as a synchronization point - by the time the file is created,
18+
# the parent process should be ready to capture our stderr output.
2019
touch "${LOCK_DIR}/start-${INVOCATION_ID}"
2120

21+
# Log to stderr so it shows up in terragrunt output
22+
# Note: Output after lock file creation to avoid macOS stderr buffering race condition
23+
echo "Auth start ${INVOCATION_ID}" >&2
24+
2225
# Wait for other auth commands to also start (up to 500ms)
2326
# This ensures we test the parallel execution scenario
2427
WAIT_COUNT=0

test/integration_destroy_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ func TestTerragruntDestroyOrder(t *testing.T) {
3333
helpers.CleanupTerraformFolder(t, testFixtureDestroyOrder)
3434
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureDestroyOrder)
3535
rootPath := util.JoinPath(tmpEnvPath, testFixtureDestroyOrder, "app")
36+
// Resolve symlinks to avoid path mismatches on macOS where /var -> /private/var
37+
rootPath, err := filepath.EvalSymlinks(rootPath)
38+
require.NoError(t, err)
3639

3740
helpers.RunTerragrunt(t, "terragrunt run --all apply --non-interactive --working-dir "+rootPath)
3841

@@ -47,6 +50,9 @@ func TestTerragruntApplyDestroyOrder(t *testing.T) {
4750
helpers.CleanupTerraformFolder(t, testFixtureDestroyOrder)
4851
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureDestroyOrder)
4952
rootPath := util.JoinPath(tmpEnvPath, testFixtureDestroyOrder, "app")
53+
// Resolve symlinks to avoid path mismatches on macOS where /var -> /private/var
54+
rootPath, err := filepath.EvalSymlinks(rootPath)
55+
require.NoError(t, err)
5056

5157
helpers.RunTerragrunt(t, "terragrunt run --all apply --non-interactive --working-dir "+rootPath)
5258

@@ -72,6 +78,9 @@ func TestTerragruntDestroyOrderWithQueueIgnoreErrors(t *testing.T) {
7278
helpers.CleanupTerraformFolder(t, testFixtureDestroyOrder)
7379
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureDestroyOrder)
7480
rootPath := util.JoinPath(tmpEnvPath, testFixtureDestroyOrder, "app")
81+
// Resolve symlinks to avoid path mismatches on macOS where /var -> /private/var
82+
rootPath, err := filepath.EvalSymlinks(rootPath)
83+
require.NoError(t, err)
7584

7685
helpers.RunTerragrunt(t, "terragrunt run --all apply --non-interactive --working-dir "+rootPath)
7786

test/integration_runner_pool_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ func TestAuthProviderParallelExecution(t *testing.T) {
205205
helpers.CleanupTerraformFolder(t, testFixtureAuthProviderParallel)
206206
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureAuthProviderParallel)
207207
testPath := util.JoinPath(tmpEnvPath, testFixtureAuthProviderParallel)
208+
// Resolve symlinks to avoid path mismatches on macOS where /var -> /private/var
209+
testPath, err := filepath.EvalSymlinks(testPath)
210+
require.NoError(t, err)
208211

209212
authProviderScript := filepath.Join(testPath, "auth-provider.sh")
210213

0 commit comments

Comments
 (0)