test: add unit coverage for image registry service responses#5542
Open
jyun-KIM wants to merge 4 commits into
Open
test: add unit coverage for image registry service responses#5542jyun-KIM wants to merge 4 commits into
jyun-KIM wants to merge 4 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
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) | ||
| } |
Contributor
|
Hey @jyun-KIM |
Signed-off-by: jyun27 <kimjyun27@gmail.com>
Author
@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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
This PR adds unit tests for the image registry service responses. The service in
chaoscenter/graphql/server/pkg/image_registry/service.goexposes five methods (CreateImageRegistry, UpdateImageRegistry, DeleteImageRegistry, GetImageRegistry, ListImageRegistries) that all returnmodel.ImageRegistryResponse, but had no unit test coverage.The new
pkg/image_registry/service_test.gowires the realOperatoron top of the existing mockedMongoOperator(following the pattern inpkg/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;
gofmtis clean.Fixes #5540
Types of changes
What types of changes does your code introduce to Litmus? Put an
xin the boxes that applyChecklist
Dependency
Special notes for your reviewer:
cd chaoscenter/graphql/server && go test -cover ./pkg/image_registry/...