Skip to content

test: add unit tests for _verifyBinary and verificationResult functions - #117

Open
saiashok0981 wants to merge 1 commit into
kubeslice:masterfrom
saiashok0981:dev/3
Open

test: add unit tests for _verifyBinary and verificationResult functions#117
saiashok0981 wants to merge 1 commit into
kubeslice:masterfrom
saiashok0981:dev/3

Conversation

@saiashok0981

Copy link
Copy Markdown

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant