Skip to content

Add unit tests for internal/service module #3781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

salignatmoandal
Copy link

What

This PR adds a comprehensive test suite for the internal/services module.

Why

  • Improves code reliability and maintainability
  • Makes future refactoring safer
  • Provides documentation for expected behavior

Details

  • Adds unit tests for:
    • Run()
    • CheckVersions()
    • listRemoteImages()
    • suggestUpdateCmd()
  • Uses afero.NewMemMapFs() for in-memory filesystem testing
  • Uses gock for HTTP request mocking
  • Uses testify for assertions

Result

  • Test coverage for the module is now above 90%
  • All tests pass locally

Let me know if you need any changes or improvements!

@salignatmoandal salignatmoandal requested a review from a team as a code owner June 28, 2025 18:57
fsys := afero.NewMemMapFs()

// Execute: Call the Run function
err := Run(context.Background(), fsys)
Copy link
Contributor

Choose a reason for hiding this comment

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

To make these tests pass, you need to mock all api requests using gock.

Copy link
Author

Choose a reason for hiding this comment

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

Got it — I’ll use gock to mock the API calls and make the tests pass. Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

  • Use a fake but valid access token for tests, with #nosec G101 to avoid gosec false positives
  • Fix race condition in listRemoteImages by protecting map writes with sync.Mutex
  • All tests now pass with -race and are CI-friendly

@coveralls
Copy link

Pull Request Test Coverage Report for Build 16030849241

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.6%) to 56.237%

Files with Coverage Reduction New Missed Lines %
internal/storage/rm/rm.go 2 89.53%
internal/gen/keys/keys.go 5 12.9%
Totals Coverage Status
Change from base Build 16026012543: 0.6%
Covered Lines: 6158
Relevant Lines: 10950

💛 - Coveralls

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