Skip to content

fix: make TestExistsErrorIncludesFilePath pass in every environment - #350

Merged
jwilder merged 1 commit into
masterfrom
testexistserrorincludesfilepath-fails-wh
Oct 17, 2026
Merged

jwilder merged 1 commit into
masterfrom
testexistserrorincludesfilepath-fails-wh

Conversation

@jwilder

@jwilder jwilder commented Oct 17, 2026

Copy link
Copy Markdown
Owner

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 <t.TempDir>/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).

## 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 `<t.TempDir>/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).
@jwilder
jwilder merged commit 78aec84 into master Oct 17, 2026
12 checks passed
@jwilder
jwilder deleted the testexistserrorincludesfilepath-fails-wh branch October 17, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant