feat: Add comprehensive unit tests and refactor for testability in UI and endpoint logic#95
Open
GitNinja36 wants to merge 1 commit intokubeslice:masterfrom
Open
feat: Add comprehensive unit tests and refactor for testability in UI and endpoint logic#95GitNinja36 wants to merge 1 commit intokubeslice:masterfrom
GitNinja36 wants to merge 1 commit intokubeslice:masterfrom
Conversation
- Add unit tests for pkg/ui.go with 100% coverage - Add unit tests for pkg/internal/enterprise.go GetUIEndpoint with 94.4% coverage - Refactor code to use dependency injection for better testability - Test multiple scenarios like : NodePort, LoadBalancer, error handling - Made all tests self-contained and independent These changes boost test reliability and improve overall code quality.
|
@gourishkb @bharath-avesha please review |
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.
Description
This PR adds comprehensive unit tests for the
GetUIEndpointfunction inpkg/ui.goand the endpoint logic inpkg/internal/enterprise.go, which handle UI endpoint retrieval and service endpoint construction for the KubeSlice CLI. Both functions have been refactored to use dependency injection for improved testability.I've refactored the functions to accept dependencies, which allowed me to mock command execution and node IP retrieval. This effort boosts test coverage to 100% for pkg/ui.go and 94.4% for GetUIEndpoint in pkg/internal/enterprise.go.
This test suite covers 5 scenarios including NodePort and LoadBalancer service types, invalid JSON handling, and command failure cases. All tests pass and existing functionality remains unchanged.
Testing Approach
UI Wrapper Function (
pkg/ui.go)Endpoint Logic (
pkg/internal/enterprise.go-GetUIEndpoint)Coverage Results
pkg/ui.gopkg/internal/enterprise.go(GetUIEndpoint)How Has This Been Tested?
go buildandgo testpkg/internal/enterprise.go :- @kubeslice-cli % go tool cover -func=coverage.out | grep ui.gopkg/ui.go file :- kubeslice-cli % go tool cover -func=enterprise_coverage.out | grep enterprise.goDoes this PR introduce a breaking change?
No breaking changes. Functions maintain the same interface and behavior while being made more testable through dependency injection.
PTAL @priyupadhyay @narmidm @Rahul-D78 @gourishkb
Signed-off-by: GitNinja36