Skip to content

test: add unit coverage for image registry service responses#5542

Open
jyun-KIM wants to merge 4 commits into
litmuschaos:masterfrom
jyun-KIM:test/image-registry-service-unit-tests
Open

test: add unit coverage for image registry service responses#5542
jyun-KIM wants to merge 4 commits into
litmuschaos:masterfrom
jyun-KIM:test/image-registry-service-unit-tests

Conversation

@jyun-KIM

@jyun-KIM jyun-KIM commented Jun 2, 2026

Copy link
Copy Markdown

Proposed changes

This PR adds unit tests for the image registry service responses. The service in chaoscenter/graphql/server/pkg/image_registry/service.go exposes five methods (CreateImageRegistry, UpdateImageRegistry, DeleteImageRegistry, GetImageRegistry, ListImageRegistries) that all return model.ImageRegistryResponse, but had no unit test coverage.

The new pkg/image_registry/service_test.go wires the real Operator on top of the existing mocked MongoOperator (following the pattern in pkg/chaos_experiment/ops/service_test.go) and uses table-driven tests to assert both the mapped response fields and error propagation for every method. List is additionally covered for multi-result, empty-result, and error cases.

Local result: all subtests pass with 100% statement coverage of the package; gofmt is clean.

Fixes #5540

Types of changes

What types of changes does your code introduce to Litmus? Put an x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)
  • Test (adds unit test coverage, no production code change)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Dependency

  • None.

Special notes for your reviewer:

  • No production code is modified; only a new test file is added.
  • Tests can be run with: cd chaoscenter/graphql/server && go test -cover ./pkg/image_registry/...

Add table-driven unit tests for the image_registry service covering the
success and error paths of CreateImageRegistry, UpdateImageRegistry,
DeleteImageRegistry, GetImageRegistry and ListImageRegistries. The tests
wire the real Operator on top of the mocked MongoOperator and assert the
mapped ImageRegistryResponse fields and error propagation.

Signed-off-by: jyun27 <kimjyun27@gmail.com>

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

Adds unit-test coverage for the image registry service layer (pkg/image_registry) to validate GraphQL response mapping and error propagation across all five service methods, addressing the lack of coverage noted in #5540.

Changes:

  • Introduces table-driven unit tests for Create/Update/Delete/Get/List image registry service methods.
  • Verifies key mapped response fields (including timestamp string conversion) and error propagation.
  • Covers list behavior for multi-result, empty-result, and error cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +26
// newTestService wires the real image registry Operator on top of a mocked
// MongoOperator and returns both so each test can program the mock and assert
// against the service responses in isolation.
func newTestService() (*dbMocks.MongoOperator, Service) {
mockOperator := new(dbMocks.MongoOperator)
operator := dbImageRegistry.NewImageRegistryOperator(mockOperator)
return mockOperator, NewImageRegistryService(operator)
}
@PriteshKiri

Copy link
Copy Markdown
Contributor

Hey @jyun-KIM
Could you please check the Co-Pilot review comments?

Signed-off-by: jyun27 <kimjyun27@gmail.com>
@jyun-KIM

jyun-KIM commented Jun 9, 2026

Copy link
Copy Markdown
Author

Hey @jyun-KIM Could you please check the Co-Pilot review comments?

@PriteshKiri I checked the Copilot comment and addressed it in the latest commit. The tests now assert mock expectations and verify the operator calls properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit coverage for image registry service responses

4 participants