Skip to content

Test Coverage PR-1: Tests added in ./licensecheck and ./repodata subdir#231

Open
mohanmanikanta2299 wants to merge 3 commits into
mainfrom
mohan/test_coverage
Open

Test Coverage PR-1: Tests added in ./licensecheck and ./repodata subdir#231
mohanmanikanta2299 wants to merge 3 commits into
mainfrom
mohan/test_coverage

Conversation

@mohanmanikanta2299
Copy link
Copy Markdown
Collaborator

@mohanmanikanta2299 mohanmanikanta2299 commented Jun 3, 2026

🛠️ Description

Summary

This PR is the 1st part of the test coverage PRs intended to increase the test coverage of the entire repo from 55% to 80+%, fulfilling our coverage requirements.

Changes Made

  • Implemented comprehensive table-driven tests for the ./licensecheck and ./repodata packages.
  • Added validation for CLI command flags, ensuring default values and flag bindings are properly configured.
  • Added strict assertions (assert.Equal, assert.Contains) and explicit error checking to validate function outputs and edge cases.
  • Used require for critical initializations (like loggers and flag lookups) to prevent nil-pointer panics during test execution.

Testing

  • Ran go test -v ./... (All tests passing)
  • Ran go test -race ./... (No race conditions detected)
  • Verified coverage metrics locally.

🔗 External Links

https://hashicorp.atlassian.net/browse/CCEN-512

👍 Definition of Done

  • Tests added : ✅

🤔 Can be merged upon approval?

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@mohanmanikanta2299 mohanmanikanta2299 requested a review from a team as a code owner June 3, 2026 09:40
// Header should come before original content
headerIdx := lo.IndexOf([]byte(string(content)), []byte(header)[0])
contentIdx := lo.IndexOf([]byte(string(content)), []byte(originalContent)[0])
assert.Less(t, headerIdx, contentIdx)
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.

Image

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.

Hey @mohanmanikanta2299, I changed header to just "C" in the "add header to file with existing content" sub-test and the test still passed. Please take a look and review the PR properly before sending it for review.

aatish@aatish-CLPJCQ9LWW copywrite % go test ./licensecheck/ -run "TestAddHeader/add_header_to_file_with_existing_content" -v -count=1
=== RUN   TestAddHeader
=== RUN   TestAddHeader/add_header_to_file_with_existing_content
--- PASS: TestAddHeader (0.00s)
    --- PASS: TestAddHeader/add_header_to_file_with_existing_content (0.00s)
PASS
ok      github.com/hashicorp/copywrite/licensecheck     0.971s

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.

@mohanmanikanta2299 , please enable co-pilot review as well, it will help saving some time in review from other Devs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed the concern.
Thanks

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread licensecheck/update_test.go Outdated
Comment thread licensecheck/update_test.go Outdated
Comment thread licensecheck/update_test.go Outdated
Comment thread licensecheck/licensecheck_test.go Outdated
Comment thread repodata/repodata_test.go Outdated
@mohanmanikanta2299 mohanmanikanta2299 marked this pull request as ready for review June 4, 2026 06:17
@mohanmanikanta2299 mohanmanikanta2299 marked this pull request as draft June 4, 2026 06:21
@mohanmanikanta2299 mohanmanikanta2299 changed the title Test Coverage Improvement - 1 Test Coverage PR-1: Tests added in ./licensecheck and ./repodata subdir Jun 5, 2026
@mohanmanikanta2299 mohanmanikanta2299 marked this pull request as ready for review June 5, 2026 15:49
@mohanmanikanta2299 mohanmanikanta2299 requested review from a team and CreatorHead June 5, 2026 15:49
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.

3 participants