Repository navigation
Conversation
Both packages had no test file at all:
cmd/oras/internal/display/metadata/template 0.0% of statements
cmd/oras/internal/display/metadata/descriptor 0.0% of statements
They render user-facing output for --format go-template and for
`oras manifest fetch --descriptor`, so a regression in either is visible
to users but was caught by nothing.
Tests are added for every handler in both packages, asserting the rendered
bytes rather than just that no error is returned:
- descriptor: compact and pretty output round-trip back to the same
descriptor, only the pretty form is indented and newline-terminated,
a failing writer surfaces its error, and the reference and raw manifest
bytes passed to OnFetched stay out of the output.
- template: attach, discover, manifest fetch, push, repo ls and repo tags
handlers, each over its Render path plus an unparsable template. Also
covered are discover rejecting a referrer whose subject was never seen,
manifest fetch tolerating non-JSON content by rendering a null manifest
instead of failing, and push not recording a digest reference as a tag.
cmd/oras/internal/display/metadata/template 85.3% of statements
cmd/oras/internal/display/metadata/descriptor 80.0% of statements
No production code is changed.
Signed-off-by: Akshita <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2164 +/- ##
==========================================
+ Coverage 87.64% 87.78% +0.14%
==========================================
Files 139 139
Lines 5689 5689
==========================================
+ Hits 4986 4994 +8
+ Misses 420 415 -5
+ Partials 283 280 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
TerryHowe
left a comment
There was a problem hiding this comment.
LGTM. I fetched the branch and ran it locally: tests pass, -race is clean, go vet and gofmt are clean, and the coverage numbers reproduce exactly as claimed (template 85.3%, descriptor 80.0%).
What I like here is that the assertions are on the exact rendered output rather than just a nil error, so a format regression actually fails. The branch selection is thoughtful too — unknown-subject rejection in discover, referrer-of-a-referrer acceptance, non-JSON content rendering a null manifest, and digest-reference-is-not-a-tag are exactly the branches that would otherwise rot silently. OnFetched_ignoresNameAndContent pins a real contract, and the descriptor round-trip test checking that only the pretty form is indented and newline-terminated is what protects the pipe-ability of the compact form.
Two follow-ups, neither blocking:
template/pull.gois the one handler in the package still at 0%, and it is the entire remaining gap. Filed as #2165.repo_test.gocovers bothrepo_list.goandrepo_tags.go; every other test file underdisplay/metadata/pairs 1:1 with its source. Worth splitting intorepo_list_test.goandrepo_tags_test.gowhenever this area is next touched.
And your model.NewPush observation is correct — var refAsTags []string marshals to null, so {{len .referenceAsTags}} fails after an untagged push where the same template works for repo ls and repo tags. Agreed it belongs in a separate PR; please do open an issue for it.
Problem
Two metadata packages had no test file at all:
Both render user-facing output —
--format go-templatefor every command that supports it, andoras manifest fetch --descriptor— so a regression in either is immediately visible to users but was caught by nothing.Changes
Tests for every handler in both packages. They assert the rendered bytes, not merely that no error came back, so a change in output format fails the test.
descriptorOnFetcheddo not leak into the outputtemplate— attach, discover, manifest fetch, push, repo ls, repo tags: each over itsRenderpath and an unparsable template, plus the branches worth pinning down:discoverrejects a referrer whose subject was never seen, and accepts a referrer of a previously discovered referrermanifest fetchtolerates non-JSON content by rendering a null manifest rather than failingpushdoes not record a digest reference as a tag, and records nothing when no reference is givenNo production code is changed.
go test ./...,gofmtandgo vetare clean.One thing noticed while writing these
model.NewPushbuildsReferenceAsTagswithvar refAsTags []stringand only ever appends, so when nothing is tagged the field marshals asnullrather than[].model.Repositoriesandmodel.Tagsboth initialise their slices to[]string{}instead.The visible effect is that a template calling
{{len .referenceAsTags}}errors withlen of nil pointerafter an untagged push, while the same template shape works forrepo lsandrepo tags. I left it alone here to keep this PR test-only — happy to open an issue or a follow-up PR if you'd like it made consistent.