test: add table-based tests for resolveAgainstBase#808
Open
naman79820 wants to merge 1 commit into
Open
Conversation
The resolveAgainstBase helper had no unit tests. Add table-driven cases covering an absolute path, a relative path with an absolute base and a relative path with a relative base, asserting the exact resolved path. Also add a separate test for the error branch by removing the working directory so a relative base cannot be resolved. Fixes: urunc-dev#96 Signed-off-by: naman79820 <naman79820@gmail.com>
✅ Deploy Preview for urunc canceled.
|
Author
|
@cmainas :)) |
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
Adds unit tests for the
resolveAgainstBasefunction inpkg/unikontainers/utils.go, which previously had no test coverage. The tests are added to the existingpkg/unikontainers/utils_test.go(rather than a new file) and are written as table-based tests, following the style already used invaccel_test.go.resolveAgainstBase(base, path)resolvespathrelative tobaseand returns an absolute path. The tests cover three success cases and one failure case:/var/lib/urunc+rootfs/image→/var/lib/urunc/rootfs/image).os.Getwd()fails). The test forces this by changing into a temporary directory and removing it, then asserts an error. This case is intentionally not run witht.Parallel()since it mutates the process working directory, and it restores the original working directory afterwards.This implements the review feedback left on #592 for this function: update the existing test file instead of creating a new one, use table-based tests, add a failure case, assert the exact path instead of using
Contains, and drop the hardcoded personal path.This builds on the work started in #592. Since that PR went stale, I've implemented the maintainer's review feedback in a fresh PR, with credit to her for the original test cases.
Related issues
How was this tested?
Tested locally on WSL with Go 1.26:
go test ./pkg/unikontainers/ -run TestResolveAgainstBase -v— all cases pass, including the failure case.go test ./pkg/unikontainers/ -count=2— the whole package passes twice, confirming the failure test restores the working directory and doesn't disturb other tests.gofmt -lclean,go vet ./pkg/unikontainers/clean,go build ./...succeeds.LLM usage
Claude Opus 4.8 assisted with writing the tests and understanding the code. Every line was reviewed, understood, and tested before submission.
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).