Skip to content

test(display): cover the raw content handlers - #2182

Merged
TerryHowe merged 1 commit into
oras-project:mainfrom
akshita317:test/content-manifest-fetch-coverage
Sep 21, 2026
Merged

TerryHowe merged 1 commit into
oras-project:mainfrom
akshita317:test/content-manifest-fetch-coverage

Conversation

@akshita317

Copy link
Copy Markdown
Contributor

Problem

cmd/oras/internal/display/content is at 37.9% of statements. manifest_fetch.go has no test file at all — neither of its functions is exercised — and manifest_index.go is covered only on the path where creating the output file fails.

These handlers produce what oras manifest fetch and oras manifest index create write to stdout or to --output, so a regression is immediately visible to users but was caught by almost nothing.

Changes

manifest_fetch_test.go (new, pairing 1:1 with its source) and additional cases in manifest_index_test.go. The existing index test is unchanged. Assertions are on the bytes that come out, not merely that no error is returned:

  • --pretty is dropped for a file and kept for stdout and for -. Both constructors do this deliberately (// ignore --pretty when output to a file) but nothing pinned it, so the behaviour could have been lost silently.
  • The compact form is byte-for-byte the fetched content, so it stays pipeable; only the pretty form is indented.
  • --output writes to the file and leaves stdout untouched.
  • Error paths: a path that cannot be created reports failed to open, a failing writer surfaces its error, and content that is not JSON fails while prettifying rather than being written out half-formed.

Result

before: coverage: 37.9% of statements
after:  coverage: 100.0% of statements

Every function in the package is now at 100%:

discard.go            OnContentFetched               100.0%
discard.go            OnContentCreated               100.0%
discard.go            NewDiscardHandler              100.0%
manifest_fetch.go     OnContentFetched               100.0%
manifest_fetch.go     NewManifestFetchHandler        100.0%
manifest_index.go     NewManifestIndexCreateHandler  100.0%
manifest_index.go     OnContentCreated               100.0%

No production code is changed. go test ./..., gofmt and go vet are clean.

The content package sits at 37.9% of statements. manifest_fetch.go had no
test file at all, so neither of its functions was exercised, and
manifest_index.go was covered only on the path where creating the output
file fails.

These handlers write what `oras manifest fetch` and `oras manifest index
create` put on stdout or into --output, so a change in them is immediately
visible to users but was caught by almost nothing.

Add manifest_fetch_test.go and extend manifest_index_test.go, asserting the
bytes that come out rather than only that no error is returned:

  - --pretty is dropped when the output is a file and kept for stdout and
    for "-", which is the documented intent of both constructors but was
    pinned by nothing
  - the compact form is byte-for-byte the fetched content, so it stays
    pipeable, while only the pretty form is indented
  - writing to --output puts the content in the file and leaves stdout
    untouched
  - a path that cannot be created reports "failed to open", a failing
    writer surfaces its error, and content that is not JSON fails while
    prettifying rather than being written out half-formed

Coverage goes from 37.9% to 100.0% of statements, with every function in
the package at 100%. No production code is changed.

Signed-off-by: Akshita <[email protected]>
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.89%. Comparing base (0d1f61e) to head (0241516).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2182      +/-   ##
==========================================
+ Coverage   87.81%   87.89%   +0.07%     
==========================================
  Files         139      139              
  Lines        5689     5691       +2     
==========================================
+ Hits         4996     5002       +6     
+ Misses        413      411       -2     
+ Partials      280      278       -2     

☔ 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.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@TerryHowe
TerryHowe merged commit a9965b3 into oras-project:main Sep 21, 2026
9 checks passed
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

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