test(hypervisors): add unit tests for utils.go helpers#584
Open
parthdagia05 wants to merge 1 commit intourunc-dev:mainfrom
Open
test(hypervisors): add unit tests for utils.go helpers#584parthdagia05 wants to merge 1 commit intourunc-dev:mainfrom
parthdagia05 wants to merge 1 commit intourunc-dev:mainfrom
Conversation
Adds table-driven unit tests covering the pure helpers in pkg/unikontainers/hypervisors/utils.go: cpuArch, appendNonEmpty, bytesToMiB, bytesToMB and BytesToStringMB. Also includes a guard test that exercises the MB vs MiB distinction, so a refactor that swaps the two unit constants would fail loudly. killProcess is intentionally not covered here, since it requires spawning a real subprocess; it can be addressed in a follow-up contribution. Tests follow the existing style in vmm_test.go (testify/assert, t.Parallel, package-internal access). Refs: urunc-dev#96 Signed-off-by: Parth Dagia <parth.24bcs10414@sst.scaler.com>
✅ Deploy Preview for urunc canceled.
|
Contributor
|
Hello @parthdagia05 , thank you for this PR> Please do not overwrite the PR template. |
Author
Sure, made the changes according to the PR template could you take a look again |
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
I have added unit tests for
pkg/unikontainers/hypervisors/utils.go, which currently has no test coverage.The tests use
testify/assertand a table-driven,t.Parallel-friendly style consistent with the existingvmm_test.goin the same package.Functions covered:
cpuArch- verified againstruntime.GOARCHso the same test works on both amd64 and aarch64 builds.appendNonEmpty- six cases covering empty/non-empty body, prefix and value combinations.bytesToMiB- exact MiB boundary, sub-MiB truncation, large values.bytesToMB- same coverage shape with the decimal MB constant.BytesToStringMB- the three logical branches: zero argument falls back toDefaultMemory, sub-MB value falls back toDefaultMemory, and a normal value passes through.I also added one extra test (
TestBytesToMiBVsMBDistinction) that asserts the binary vs decimal megabyte constants are not interchangeable. Its goal is to catch a refactor that accidentally swaps the two unit helpers - they have the same signature so the compiler won't notice.killProcessis intentionally not covered in this PR. It requires spawning a real subprocess, and several of its branches cannot be reproduced deterministically without privileged operations or refactoring the function to inject the signaller. Happy to address it in a follow-up if useful.Related issues
Refs #96
How was this tested?
go test -v ./pkg/unikontainers/hypervisors/...- 6 tests, 23 subtests, all pass.go test -count=1 ./...(excludingtests/e2ewhich needs Docker/QEMU/crictl) - every previously-passing package still passes.gofmt -l pkg/unikontainers/hypervisors/utils_test.go- clean.go vet ./pkg/unikontainers/hypervisors/...- clean.golangci-lint run ./pkg/unikontainers/hypervisors/...(using the project's.golangci.ymlv2 config) - 0 issues.make lint- passes locally.LLM usage
Anthropic Claude Opus 4.6 was used to assist with planning the test scope, identifying edge cases for each helper. All code was reviewed and tested by me before submission.
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).