Repository navigation
test(display): cover the metadata model types - #2176
Merged
Merged
Conversation
The model package sits at 13.7% of statements: push.go was the only type
with a test file, so the types behind oras attach, discover, manifest
fetch, repo ls and repo tags were exercised by nothing, even though they
define the JSON and go-template output users depend on.
Add one test file per source file, following the 1:1 pairing used
elsewhere under display/metadata, asserting the marshalled shape rather
than only that a constructor returns non-nil:
- descriptor: NewDigestReference and FromDescriptor, including that the
reference and the OCI fields are inlined as templates address them,
and that URLs, Data and Platform are deliberately dropped
- discover: NewNode starting Referrers as an empty slice, a referrer of
a previously discovered referrer attaching to that node rather than
the root, and an unknown subject being rejected
- attach and fetched: the rendered fields, and that nil content marshals
as null rather than failing, which is what lets the fetch handlers
tolerate content that is not JSON
- repo_list and repo_tags: that both lists are initialised so an empty
listing marshals as [] rather than null
- tag: that Tags sorts, which push relies on for referenceAsTags
Coverage goes from 13.7% to 58.8% of statements, with every function at
100% except the four in pull.go. Those are left alone on purpose: oras-project#2175
covers NewPull, and oras-project#2002 also touches that file.
Signed-off-by: Akshita <[email protected]>
akshita317
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
September 19, 2026 12:18
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2176 +/- ##
=======================================
Coverage 87.81% 87.81%
=======================================
Files 139 139
Lines 5689 5689
=======================================
Hits 4996 4996
Misses 413 413
Partials 280 280 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 13.7% of statements.push.gowas the only type with a test file, so the types behindoras attach,discover,manifest fetch,repo lsandrepo tagshad no tests at all — despite defining the JSON and go-template output users consume.Changes
One test file per source file, following the 1:1 pairing used elsewhere under
display/metadata(and asked for on #2164). The assertions are on the marshalled shape, not merely that a constructor returns non-nil:descriptor_test.goNewDigestReference;FromDescriptorcopying the core fields, inliningreference/mediaType/digest/sizeas templates address them, and deliberately droppingURLs,DataandPlatformdiscover_test.goNewNodestartingReferrersas an empty slice; a referrer of a previously discovered referrer attaching to that node, not the root; an unknown subject rejected withunexpected subject descriptorattach_test.gofetched_test.gonullrather than failing — what lets the fetch handlers tolerate non-JSON contentrepo_list_test.go/repo_tags_test.go[], notnulltag_test.goTagssorting, whichpushrelies on forreferenceAsTagsThe
[]-not-nullassertions are deliberate: that is the regression class fixed in #2170 and #2175, and nothing was pinning it for the lists that already behaved correctly.Result
Every function is now at 100% except the four in
pull.go(newFile,NewPull,Files,Add). Those are left alone on purpose to avoid conflicts: #2175 coversNewPull, and #2002 also touches that file. Happy to fold them in here instead if you would rather.No production code is changed.
go test ./...,gofmtandgo vetare clean.