Repository navigation
test(errors): cover the CLI error type and its constructors - #2196
Merged
TerryHowe merged 2 commits intoSep 28, 2026
Merged
Conversation
Signed-off-by: Akshita <[email protected]>
akshita317
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
September 28, 2026 10:59
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2196 +/- ##
==========================================
- Coverage 87.85% 87.81% -0.04%
==========================================
Files 139 139
Lines 5714 5714
==========================================
- Hits 5020 5018 -2
- Misses 414 416 +2
Partials 280 280 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: Akshita <[email protected]>
Member
|
Thanks! |
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
cmd/oras/internal/errorsis at 32.9% of statements. Everything that builds the text a user reads when a command fails has no test:Error.ErrorandUnwrap,CheckArgs,Command,TrimErrBasicCredentialNotFoundandNewErrEmptyTagOrDigestare all at 0%.What the tests pin
Error: the exact message with and withoutUsageandRecommendation, with usage before the recommendation, and thatUnwrapexposesErrtoerrors.Is.CheckArgs:nilwhen the checker passes; otherwise the exactErr,UsageandRecommendation. The command isoras blob push, so the usage has to come from the parent's command path plusUse.Command: a failingRunEgoes through the modifier and returns what the modifier returns; a successful run never calls the modifier.TrimErrBasicCredentialNotFound: uses the shape oras-go actually produces (GET "<url>": basic credential not found, fromauth.Client.Do). The request line is trimmed, an outer context such asError from source registry for "<ref>"is kept, and the result still satisfieserrors.Is(err, auth.ErrBasicCredentialNotFound).reWrap: returns the inner error when the mid message is not in the outer one.NewErrEmptyTagOrDigest: both forms of the message and recommendation (needsTagtrue and false), the usage, andOperationTypeParseArtifactReference.I checked that none of these assertions is vacuous by breaking the source one change at a time. Each mutation fails a test:
errors.goreWrapalways returnsinner(outer context dropped)TestTrimErrBasicCredentialNotFoundCommanddiscards the modifier's errorTestCommandCheckArgsusage built fromcmd.UsealoneTestCheckArgsneedsTagignoredTestNewErrEmptyTagOrDigestRecommendationnot appendedTestError_ErrorUnwrapreturnsnilTestError_ErrorResult
The remaining lines are the
Unwrap() []errorbranch ofTrimErrBasicCredentialNotFound. I left it unpinned on purpose: for a joined error it currently returns only the credential error and drops the sibling's message, and I didn't want to lock that in with a test without knowing whether it's intended. Happy to add a case either way.No production code is changed.
go test ./...,gofmtandgo vetare clean.Note: this adds the
cobraandoras-go/v2/registry/remote/authimports toerrors_test.go, whose import block #2002 also rewrites for oras-go v3. Whichever lands second needs a one-line import update.