Skip to content

test: strengthen display handler test assertions - #2055

Merged
TerryHowe merged 1 commit into
oras-project:mainfrom
TerryHowe:test/display-handler-assertions
Jul 21, 2026
Merged

TerryHowe merged 1 commit into
oras-project:mainfrom
TerryHowe:test/display-handler-assertions

Conversation

@TerryHowe

Copy link
Copy Markdown
Member

Summary

Follow-up to #1950 that addresses the Copilot review feedback left on that PR. The previously added tests only asserted that handler methods returned no error; this PR adds assertions on the state mutations and rendered JSON output that those methods are actually supposed to produce.

Note

This branch is stacked on #1950. It currently shows that PR's commits plus this one in the diff. Please merge #1950 first — once that lands, GitHub will recompute this PR's diff to show only the changes here.

Changes

cmd/oras/internal/display/metadata/json/push_test.go

  • TestPushHandler_OnTagged now asserts the tag is stored in handler.tagged.Tags().
  • TestPushHandler_OnCopied now asserts handler.path, handler.root.Digest, and that the non-digest reference was added as a tag.
  • TestPushHandler_OnCopied_WithDigest now asserts that no tag is added when the reference is a digest — the whole purpose of that code path.
  • TestPushHandler_Render now decodes the JSON into a typed struct and asserts reference, mediaType, digest, size, and referenceAsTags rather than only checking that the output parses.

cmd/oras/internal/display/metadata/json/pull_test.go

  • TestPullHandler_OnFilePulled now asserts the file was recorded in handler.pulled.Files() with the expected digest and media type.
  • TestPullHandler_Render now calls OnFilePulled before rendering and decodes the output into a typed struct, asserting reference and the files array contents.

cmd/oras/internal/display/content/discard_test.go

  • One-line drive-by: rename the unused t parameter in TestDiscardHandler_ImplementsInterfaces to _ so the branch passes revive's unused-parameter check.

Test plan

  • go test ./cmd/oras/internal/display/metadata/json/... ./cmd/oras/internal/display/content/... passes
  • golangci-lint run ./cmd/oras/internal/display/metadata/json/... ./cmd/oras/internal/display/content/... reports 0 issues

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

@codecov

codecov Bot commented May 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.25%. Comparing base (a9b45e3) to head (7111654).
⚠️ Report is 47 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2055   +/-   ##
=======================================
  Coverage   87.25%   87.25%           
=======================================
  Files         138      138           
  Lines        5462     5462           
=======================================
  Hits         4766     4766           
  Misses        415      415           
  Partials      281      281           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Follow-up to oras-project#1950 addressing Copilot review feedback:
- assert that OnTagged/OnCopied actually store the tag, path, and root
- assert that OnCopied with a digest reference does NOT add a tag
- assert that OnFilePulled records the file in the pulled list
- assert rendered JSON contains the expected reference, digest,
  mediaType, size, files, and referenceAsTags rather than only
  validating that the output parses.

Signed-off-by: Terry Howe <[email protected]>
@TerryHowe
TerryHowe force-pushed the test/display-handler-assertions branch from fbb9ac6 to 7111654 Compare May 24, 2026 16:54
@TerryHowe
TerryHowe merged commit 2234363 into oras-project:main Jul 21, 2026
9 checks passed
@TerryHowe
TerryHowe deleted the test/display-handler-assertions branch July 21, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants