Skip to content

test: add comprehensive test coverage for cmd/oras/internal/display/metadata/text/copy.go#1868

Merged
shizhMSFT merged 5 commits into
mainfrom
copilot/fix-1862
Sep 29, 2025
Merged

test: add comprehensive test coverage for cmd/oras/internal/display/metadata/text/copy.go#1868
shizhMSFT merged 5 commits into
mainfrom
copilot/fix-1862

Conversation

Copilot AI commented Sep 14, 2025

Copy link
Copy Markdown
Contributor

This PR adds complete test coverage for the CopyHandler implementation in cmd/oras/internal/display/metadata/text/copy.go. The file previously had no test coverage, which this PR addresses by creating copy_test.go with comprehensive test cases.

What's Added

The new test file includes:

  • TestNewCopyHandler - Tests the constructor function and validates proper interface implementation
  • TestCopyHandler_OnTagged - Tests tag handling with various tag formats (simple, version, complex, empty) plus error scenarios
  • TestCopyHandler_Render - Tests digest rendering with valid descriptors, empty digests, and error conditions
  • TestCopyHandler_OnCopied - Tests copy operations across different target types:
    • Registry to registry
    • Registry to OCI layout
    • OCI layout to registry
    • OCI layout to OCI layout
  • TestCopyHandler_Integration - Demonstrates the typical workflow of OnCopied followed by Render

Test Coverage

The tests achieve 100% function coverage for all public methods in copy.go:

  • NewCopyHandler() - 100%
  • OnTagged() - 100%
  • Render() - 100%
  • OnCopied() - 100%

Implementation Details

The tests follow established patterns from other test files in the package (backup_test.go, push_test.go, restore_test.go):

  • Uses table-driven test approach for comprehensive coverage
  • Includes both success and error path testing
  • Leverages the existing errorWriter helper for testing error conditions
  • Validates output formatting matches expected patterns
  • Uses proper Go testing conventions and descriptive test names

Recent Changes

  • ✅ Fixed lint issue: Removed redundant type assertion handler.(metadata.CopyHandler) in TestNewCopyHandler since the variable is already of that type
  • ✅ Removed unused import "oras.land/oras/cmd/oras/internal/display/metadata"
  • ✅ All tests still pass with the changes

All tests pass successfully and maintain consistency with the existing codebase style and testing patterns.

Fixes #1862.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 14, 2025 12:42
Co-authored-by: TerryHowe <104113+TerryHowe@users.noreply.github.com>
Co-authored-by: TerryHowe <104113+TerryHowe@users.noreply.github.com>
Copilot AI changed the title [WIP] Add test coverage for cmd/oras/internal/display/metadata/text/copy.go Add comprehensive test coverage for cmd/oras/internal/display/metadata/text/copy.go Sep 14, 2025
Copilot AI requested a review from TerryHowe September 14, 2025 12:45
@codecov

codecov Bot commented Sep 14, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.35%. Comparing base (d19ca44) to head (49b1e3e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1868      +/-   ##
==========================================
+ Coverage   85.32%   85.35%   +0.02%     
==========================================
  Files         143      143              
  Lines        6739     6739              
==========================================
+ Hits         5750     5752       +2     
+ Misses        703      701       -2     
  Partials      286      286              

☔ View full report in Codecov by Sentry.
📢 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.

Comment thread cmd/oras/internal/display/metadata/text/copy_test.go Outdated
Co-authored-by: TerryHowe <104113+TerryHowe@users.noreply.github.com>
Copilot AI requested a review from TerryHowe September 14, 2025 12:58
@TerryHowe TerryHowe marked this pull request as ready for review September 14, 2025 13:17

@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

@shizhMSFT shizhMSFT changed the title Add comprehensive test coverage for cmd/oras/internal/display/metadata/text/copy.go test: add comprehensive test coverage for cmd/oras/internal/display/metadata/text/copy.go Sep 23, 2025
@shizhMSFT shizhMSFT requested a review from Copilot September 23, 2025 06:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive test coverage for the CopyHandler implementation in cmd/oras/internal/display/metadata/text/copy.go, which previously had no test coverage.

  • Implements 100% function coverage for all public methods (NewCopyHandler, OnTagged, Render, OnCopied)
  • Adds thorough test cases covering success paths, error conditions, and edge cases
  • Includes integration testing demonstrating typical workflow patterns

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread cmd/oras/internal/display/metadata/text/copy_test.go
Comment thread cmd/oras/internal/display/metadata/text/copy_test.go
Comment thread cmd/oras/internal/display/metadata/text/copy_test.go
@shizhMSFT

Copy link
Copy Markdown
Contributor

LoL. @TerryHowe Do you know how to let copilot to address the comments from copilot?

@TerryHowe

Copy link
Copy Markdown
Member

Copilot vs Copilot comments resolved. These type conversions are needed.

@shizhMSFT shizhMSFT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@shizhMSFT shizhMSFT merged commit da85412 into main Sep 29, 2025
8 checks passed
@shizhMSFT shizhMSFT deleted the copilot/fix-1862 branch September 29, 2025 09:30
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.

Add test coverage for cmd/oras/internal/display/metadata/text/copy.go

4 participants