From 272b2693c8c41e5fdd264c36fed9c845c1215d2a Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Fri, 16 Oct 2026 21:46:59 -0600 Subject: [PATCH] fix: make `TestExistsErrorIncludesFilePath` pass in every environment ## Summary Make `TestExistsErrorIncludesFilePath` pass in every environment, including containers where /proc/1/fd can be read. ## What changes - Root cause: the test assumed `stat /proc/1/fd/does-not-exist/child` fails with EACCES. In this nspawn sandbox it returns ENOENT, even as uid 1000, and `exists` maps ENOENT to (false, nil). `exists` itself (template.go:19) is correct. - Fix: stat `/file/child`, where `file` is a regular file. The stat fails with ENOTDIR for any user, including root, so the test needs no root skip. Chosen over a mode-0 directory because root ignores mode bits. ## Testing `go test -count=1 -run TestExistsErrorIncludesFilePath.`: fails on master in this sandbox and passes on the branch, both as the user and with sudo. `go test -count=1./...` passes. `make lint` needs golangci-lint on PATH (installed under GOPATH/bin). --- template_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/template_test.go b/template_test.go index bf4477a..34b435c 100644 --- a/template_test.go +++ b/template_test.go @@ -140,7 +140,13 @@ func TestGenerateFileDefaultDoesNotPanicOnNonStringValue(t *testing.T) { } func TestExistsErrorIncludesFilePath(t *testing.T) { - missingPath := filepath.Join("/proc", "1", "fd", "does-not-exist", "child") + // A path through a regular file fails with ENOTDIR rather than ENOENT, + // regardless of the user running the test. + file := filepath.Join(t.TempDir(), "file") + if err := os.WriteFile(file, nil, 0o600); err != nil { + t.Fatal(err) + } + missingPath := filepath.Join(file, "child") _, err := exists(missingPath) if err == nil {