From f63c38d6a11be3d25eda48c9b8d31bc31957b5a5 Mon Sep 17 00:00:00 2001 From: "Alan D. Salewski" Date: Thu, 27 Aug 2020 10:02:22 -0400 Subject: [PATCH] internal/initwd: allow tests to pass when $PWD contains symlinks (#26015) Fixes #26014 --- internal/initwd/from_module_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/initwd/from_module_test.go b/internal/initwd/from_module_test.go index 96b7fee34d..4688267dce 100644 --- a/internal/initwd/from_module_test.go +++ b/internal/initwd/from_module_test.go @@ -122,6 +122,17 @@ func TestDirFromModule_submodules(t *testing.T) { t.Fatal(err) } + // DirFromModule will expand ("canonicalize") the pathnames, so we must do + // the same for our "wantCalls" comparison values. Otherwise this test + // will fail when building in a source tree with symlinks in $PWD. + // + // See also: https://github.com/hashicorp/terraform/issues/26014 + // + fromModuleDirRealpath, err := filepath.EvalSymlinks(fromModuleDir) + if err != nil { + t.Error(err) + } + tmpDir, done := tempChdir(t, fixtureDir) defer done() @@ -138,12 +149,12 @@ func TestDirFromModule_submodules(t *testing.T) { { Name: "Install", ModuleAddr: "child_a", - LocalPath: filepath.Join(fromModuleDir, "child_a"), + LocalPath: filepath.Join(fromModuleDirRealpath, "child_a"), }, { Name: "Install", ModuleAddr: "child_a.child_b", - LocalPath: filepath.Join(fromModuleDir, "child_a/child_b"), + LocalPath: filepath.Join(fromModuleDirRealpath, "child_a/child_b"), }, }