test: add unit tests for _verifyBinary and verificationResult functions - #117
Open
saiashok0981 wants to merge 1 commit into
Open
test: add unit tests for _verifyBinary and verificationResult functions#117saiashok0981 wants to merge 1 commit into
saiashok0981 wants to merge 1 commit into
Conversation
The pkg/internal/verify-executables.go file contains two key internal helpers — _verifyBinary and verificationResult — that drive the entire executable verification phase run at the start of every kubeslice-cli install/uninstall operation. Neither function had any unit test coverage, making regressions hard to catch without a full integration run. This commit adds a new test file, verify-executables_test.go, covering: - verificationResult(0, ...): confirms a success message is printed - _verifyBinary with a non-existent binary name: expects return code 1 - _verifyBinary with a bad env-var override pointing to /nonexistent/path: expects return code 1 - _verifyBinary with a real executable (temp script): expects return code 0 - _verifyBinary with /bin/false (always exits 1): expects return code 2 Tests are table-driven where applicable, run in parallel, and clean up all temporary filesystem artefacts via t.TempDir and t.Cleanup. Signed-off-by: saiashok103@gmail.com
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 new test file pkg/internal/verify-executables_test.go with unit tests for the _verifyBinary and verificationResult functions, which had no test coverage at all before this change.
Motivation
_verifyBinary is one of the most critical functions in the CLI. It checks whether required tools like kubectl, helm, kind, and docker are installed and working before the install process begins. If this function has a bug — for example, returning success when a binary is actually missing — the entire install workflow could proceed and fail in a confusing way deep into the process.
Without unit tests, this function can only be checked through a full integration run against a live environment. Adding tests lets us catch regressions in CI without any external setup.
Changes
A new file pkg/internal/verify-executables_test.go was created with five test functions.
The first test checks that when verificationResult is called with status 0 it prints a success message.
The second test checks that _verifyBinary returns 1 when given a binary name that does not exist on the system.
The third test checks that _verifyBinary returns 1 when the environment variable override points to a path that does not exist.
The fourth test checks that _verifyBinary returns 0 when given a real executable that runs successfully, using a small temporary script.
The fifth test checks that _verifyBinary returns 2 when the binary is found but its verification command exits with a non-zero code, using /bin/false.
Testing
All tests pass with go test ./pkg/internal/...
Tests are run in parallel using t.Parallel()
All temporary files are cleaned up automatically via t.TempDir()
Tests that depend on platform-specific binaries like /bin/false are skipped gracefully on unsupported platforms using t.Skip
Checklist
Follows the same style as existing test files in the project
No production code was changed
Commit message uses Conventional Commits format
DCO Signed-off-by included
Signed-off-by:
saiashok103@gmail.com