Skip to content

Commit 19562db

Browse files
committed
fileutils_test: check symlink directory location before test
In macOS and maybe some other systems, /tmp is a symlink to /private/tmp or some other similar directory, so ReadSymlinkedDirectory ends up pointing at a different directory than was created. Get the evaluated path of the directory being created, and compare that to the result of ReadSymlinkedDirectory. Signed-off-by: Caleb Xu <caxu@redhat.com>
1 parent 11843ce commit 19562db

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

storage/pkg/fileutils/fileutils_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ func TestReadSymlinkedDirectoryExistingDirectory(t *testing.T) {
120120
t.Errorf("failed to create directory: %s", err)
121121
}
122122

123+
var realpath string
124+
if realpath, err = filepath.EvalSymlinks("/tmp/testReadSymlinkToExistingDirectory"); err != nil {
125+
t.Errorf("failed to evaluate symlinks in path: %s", err)
126+
}
127+
123128
if err = os.Symlink("/tmp/testReadSymlinkToExistingDirectory", "/tmp/dirLinkTest"); err != nil {
124129
t.Errorf("failed to create symlink: %s", err)
125130
}
@@ -129,7 +134,7 @@ func TestReadSymlinkedDirectoryExistingDirectory(t *testing.T) {
129134
t.Fatalf("failed to read symlink to directory: %s", err)
130135
}
131136

132-
if path != "/tmp/testReadSymlinkToExistingDirectory" {
137+
if path != realpath {
133138
t.Fatalf("symlink returned unexpected directory: %s", path)
134139
}
135140

0 commit comments

Comments
 (0)