Skip to content

fileutils_test: check symlink directory location before test#603

Merged
mtrmac merged 1 commit intocontainers:mainfrom
caxu-rh:fileutils-symlink-test
Feb 26, 2026
Merged

fileutils_test: check symlink directory location before test#603
mtrmac merged 1 commit intocontainers:mainfrom
caxu-rh:fileutils-symlink-test

Conversation

@caxu-rh
Copy link
Copy Markdown
Contributor

@caxu-rh caxu-rh commented Jan 22, 2026

On some systems, /tmp and /var are symlinks to /private/tmp and /private/var, respectively. This may cause the test to fail, because the created directory is not actually at the path where it was created.

Get the canonical path of the created directory and compare that to the output of ReadSymlinkedDirectory.

While we're here, avoid hardcoding specific test paths and prefer using t.TempDir() instead. This also simplifies the cleanup logic.

@github-actions github-actions Bot added the storage Related to "storage" package label Jan 22, 2026
Copy link
Copy Markdown
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

I expect that works, but really tests should not be hard-coding specific paths in /tmp (and exposing the invoking user to attacks by other users on the machine) in the first place. Can you convert the test to be based on t.TempDir(), please? That might work around the macOS /tmp situation as a side effect.

Comment thread storage/pkg/fileutils/fileutils_test.go Outdated
On some systems, /tmp and /var are symlinks to /private/tmp and
/private/var, respectively. This may cause the test to fail,
because the created directory is not actually at the path where it
was created.

Get the canonical path of the created directory and compare that to
the output of ReadSymlinkedDirectory.

While we're here, avoid hardcoding specific test paths and prefer
using t.TempDir() instead. This also simplifies the cleanup logic.

Signed-off-by: Caleb Xu <caxu@redhat.com>
@caxu-rh caxu-rh force-pushed the fileutils-symlink-test branch from 19562db to 5d306e0 Compare January 23, 2026 19:22
@caxu-rh
Copy link
Copy Markdown
Contributor Author

caxu-rh commented Jan 23, 2026

Thanks for the feedback, I made adjustments to avoid using hardcoded paths for the test. The path returned by t.TempDir() is still not a canonical one, so the filepath.EvalSymlinks call is still necessary.

I wonder if this should work now on Windows too, but I don't have the means to test it right now, so I've left the TODO in place.

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

If @mtrmac is hip with this, so am I. Provisionally:
LGTM

Copy link
Copy Markdown
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

if err = os.Remove("/tmp/dirLinkTest"); err != nil {
t.Errorf("failed to remove symlink: %s", err)
}
require.Equal(t, path, realpath, "symlink returned unexpected directory: %s", path)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For the record, the argument order is Equal(t, expected, actual). Not worth worrying that much about I guess.)

@mtrmac mtrmac merged commit c0bbab5 into containers:main Feb 26, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage Related to "storage" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants