Repository navigation
test(credential): fix TestNewStoreError failing on Windows - #2159
Merged
TerryHowe merged 1 commit intoSep 8, 2026
Merged
Conversation
TestNewStoreError makes a config file unreadable with os.Chmod(f, 000) and
expects NewStore to fail. On Windows os.Chmod can only toggle the read-only
attribute and cannot clear the read permission, so the file stays readable,
NewStore succeeds, and both assertions fire:
store_test.go:41: Expected NewStore to return nil but actually returned &{...}
store_test.go:47: Expected err to be not nil
CI runs ubuntu-latest only, so this is invisible there, but `go test ./...`
fails for anyone developing on Windows.
Skip the permission case on Windows, and on Unix when running as root, where
permission bits do not restrict access either. To keep the error path covered
on every platform, add TestNewStoreMalformedConfig, which reaches the same
failure through JSON decoding and so is OS-independent.
Also fix two existing problems in the test:
- reflect.DeepEqual(ok, true) discarded its result, so the expected
"failed to open config file" text was never actually asserted; the test
would have passed on any error at all. It is now checked with
strings.Contains. Both expected strings are verified against the
producing code in oras-go's credentials/internal/config/config.go.
- path.Join builds slash-separated paths and is not intended for
filesystem paths; use filepath.Join.
Setup failures now use t.Fatalf rather than t.Errorf, which previously let
the test continue against a file it had failed to create or chmod.
Signed-off-by: Akshita <[email protected]>
akshita317
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
September 7, 2026 17:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
go test ./...fails on Windows on a clean checkout ofmain:The test makes a config file unreadable with
os.Chmod(filename, 000)and expectsNewStoreto fail opening it. On Windowsos.Chmodcan only toggle the read-only attribute — it cannot clear the read permission. The file stays readable,NewStoresucceeds, and both assertions fire.build.ymlrunsubuntu-latestonly (the matrix is over Go versions, not OS), so CI never sees this. It only bites people developing on Windows.Changes
Skip the permission case where permissions don't apply — on Windows, and on Unix when running as root (a root container hits the same failure for the same underlying reason: the file remains readable).
Add
TestNewStoreMalformedConfigso the error path stays covered everywhere. It reaches the sameNewStorefailure through JSON decoding, which behaves identically on every platform, so skipping the permission case does not leave the error path untested on Windows.Assert the error message, which the test never actually did:
reflect.DeepEqualreturns aboolthat was thrown away, so the test passed on any error. Now checked withstrings.Contains. Both expected strings are verified against the code that produces them,credentials/internal/config/config.go:path.Join→filepath.Join—pathis for slash-separated paths, not filesystem paths.t.Errorf→t.Fatalffor setup failures, which previously let the test continue against a file it had failed to create or chmod.Verification
Windows, before →
FAIL. After:On Linux both tests run; the permission case keeps its original behaviour, now with the assertion actually enforced.
gofmtandgo vetare clean.