gcsfs tests exit successfully when tests fail
At current master eb6a92826ea568e3f40ab91fcbda8d2b38b61d3e, the CI run is marked successful even though all 12 test jobs log failures in TestGcsReaddir, TestGcsReaddirnames, and TestGcsGlob.
For example, the successful Ubuntu / Go 1.26 job reports open : file does not exist for the two directory tests and nil results for the bucket-root glob cases. Its Test gcsfs step still succeeds.
The cause is defer os.Exit(exitCode) in TestMain. The deferred call captures the initial zero value before m.Run() updates exitCode. It also masks the nonzero exit code assigned by the panic recovery path.
Reproduction using the checked-in fake credentials and mocked client:
cd gcsfs
GOOGLE_APPLICATION_CREDENTIALS="$PWD/gcs-fake-service-account.json" \
GOMAXPROCS=2 go test -race -count=1 -p=2 -v \
-run '^TestGcs(Readdir|Readdirnames|Glob)$' ./...
printf 'exit status: %s\n' "$?"
Expected: failed tests produce a nonzero exit status and a failed CI job.
Actual: the failures appear in the output, but the command and CI step succeed. No real GCS account or bucket is needed for these mocked tests.
Verified locally on macOS ARM64 with Go 1.26.5: the unchanged mocked suite records the three failures but exits 0. With the closure below, the same tests fail and the command exits 1. A passing-test binary control retains exit 0; a setup-panic binary control changes from exit 0 to exit 2.
A deferred closure that reads the final value, defer func() { os.Exit(exitCode) }(), preserves the intended cleanup ordering and report failures correctly. That change exposes the existing three failures and makes CI red until their cause is addressed.
Related work: #679 changes how MemMapFs handles empty paths. It may affect the mocked bucket-root failures; that interaction has not been validated here. It does not change the test-harness exit handling.
Would maintainers prefer a small test-harness PR followed by a separate directory/mock fix, or one PR covering both?