Repository navigation
test(display): cover the pulled-file model - #2189
Merged
TerryHowe merged 2 commits intoSep 27, 2026
Merged
Conversation
The model package sits at 62.3% of statements, and all three of the
uncovered functions are in pull.go: newFile, Pulled.Add and
Pulled.Files. They decide the path recorded for every file that
oras pull reports, so a change in them is visible to users through
--format json and go-template.
Cover them, asserting behaviour rather than only that no error is
returned:
- a relative name is resolved against the output directory and an
absolute one is kept as given, so the recorded path is always
absolute, and a name needing cleaning is cleaned
- a descriptor annotated for unpacking names a directory, so its
path gains a trailing separator; an unpack annotation of "false"
and an unrelated annotation both leave the path alone
- the descriptor half of a File comes from the descriptor path, not
from the name the file was written under
- Add preserves insertion order, and Files is empty beforehand
- Files returns a copy: writing to the returned slice does not change
what a later call reports
The last one is the reason for the slices.Clone in Files, and nothing
pinned it. Verified by mutation: replacing that call with a bare
return of the stored slice fails the new test.
Coverage goes from 62.3% to 96.2% of statements. The remaining
uncovered lines are the filepath.Abs error branches in newFile and the
error return it feeds in Add, which the source itself notes are "not
likely to go wrong since the file has already be written to file
store" and cannot be reached without faking the filesystem.
No production code is changed.
Signed-off-by: Akshita <[email protected]>
akshita317
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
September 24, 2026 16:20
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2189 +/- ##
==========================================
+ Coverage 87.78% 87.81% +0.03%
==========================================
Files 139 139
Lines 5714 5714
==========================================
+ Hits 5016 5018 +2
+ Misses 417 416 -1
+ Partials 281 280 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
TerryHowe
reviewed
Sep 24, 2026
TerryHowe
reviewed
Sep 24, 2026
filepath.Join cleans its own result, so the "absolute name is cleaned" input reached newFile already clean and a no-op in place of filepath.Clean kept it green. Build the path by concatenation instead. Add TestPulled_concurrent so -race has concurrent Add and Files calls to inspect, mirroring TestTagged_Tags_concurrent. Signed-off-by: Akshita <[email protected]>
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/display/metadata/modelis at 62.3% of statements, and all three uncovered functions are inpull.go:newFile,Pulled.AddandPulled.Files. They decide the path recorded for every fileoras pullreports, so a change in them reaches users through--format jsonand--format go-template.What the tests pin
"false"and an unrelated annotation both leave the path alone.Filecomes from the descriptor path, not from the name the file was written under.Addpreserves insertion order, andFilesis empty before anything is added.Filesreturns a copy — writing to the returned slice does not change what a later call reports.That last one is the reason for the
slices.CloneinFiles, and nothing pinned it. I checked it is not a vacuous assertion by mutation — replacing the clone with a barereturn p.files:The tests build expected paths with
filepathrather than literals, so they behave the same on Linux and Windows.Result
The remaining uncovered lines are the
filepath.Abserror branch innewFileand the error return it feeds inAdd— which the source itself notes are "not likely to go wrong since the file has already be written to file store" and cannot be reached without faking the filesystem. Happy to add a seam for them if you would rather have 100%.No production code is changed.
go test ./...,gofmtandgo vetare clean.