test(): Add comprehensive unit tests for internal/secrets.go file#98
Open
GitNinja36 wants to merge 3 commits intokubeslice:masterfrom
Open
test(): Add comprehensive unit tests for internal/secrets.go file#98GitNinja36 wants to merge 3 commits intokubeslice:masterfrom
GitNinja36 wants to merge 3 commits 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.
- Adds a dedicated test suite in pkg/internal/secret_test.go to cover the GetSecretName function. - Ensures robust, cross-platform test coverage using a fake kubectl binary and environment variable overrides. - Covers successful secret retrieval, command pipeline validation, and edge cases such as missing or malformed output. - No changes to production code; all improvements are limited to the test suite. Signed-off-by: Rohit27 <137439791+GitNinja36@users.noreply.github.com>
Signed-off-by: Rohit27 <137439791+GitNinja36@users.noreply.github.com>
0eee295 to
9fa6f3c
Compare
|
your previous commit doesn't have DOC. Please fix that |
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 a complete and production-grade unit test suite for the
GetSecretsandGetSecretNamefunctions inpkg/internal/secrets.goof the KubeSlice CLI. These functions are responsible for fetching Kubernetes secrets and rely on shell command pipelines that involve tools likekubectl,grep, andawk.Testing Approach
Files Covered
pkg/internal/secrets.goFunctions Tested
GetSecretName(workerName, namespace, controllerCluster)GetSecrets(workerName, namespace, controllerCluster, outputFormat)Techniques Used
kubectlbehavior using temporary fake binaries with controlled outputs.kubectl | grep | awkexecution to ensure proper parsing and behavior.GetSecretsexecutes without being skipped or altered.Coverage Results
pkg/internal/secrets.goSample Coverage Output
How Has This Been Tested?
Test Cases
kubectlfailure returns empty resultGetSecretsfunction runs without panicGetSecretsenforces required 200ms delaySafe Execution
kubectlDoes this PR introduce a breaking change?
NA
Fixes
Fixes: #46
Reviewers
PTAL
@priyupadhyay @narmidm @Rahul-D78 @gourishkb
Signed-off-by: Rohit Kumar