Skip to content

test: add table-based tests for resolveAgainstBase#808

Open
naman79820 wants to merge 1 commit into
urunc-dev:mainfrom
naman79820:test/resolve-against-base-tests
Open

test: add table-based tests for resolveAgainstBase#808
naman79820 wants to merge 1 commit into
urunc-dev:mainfrom
naman79820:test/resolve-against-base-tests

Conversation

@naman79820

@naman79820 naman79820 commented Jul 6, 2026

Copy link
Copy Markdown

Description

Adds unit tests for the resolveAgainstBase function in pkg/unikontainers/utils.go, which previously had no test coverage. The tests are added to the existing pkg/unikontainers/utils_test.go (rather than a new file) and are written as table-based tests, following the style already used in vaccel_test.go.

resolveAgainstBase(base, path) resolves path relative to base and returns an absolute path. The tests cover three success cases and one failure case:

  • Absolute path — returned unchanged.
  • Relative path with absolute base — joined onto the base (e.g. /var/lib/urunc + rootfs/image/var/lib/urunc/rootfs/image).
  • Relative path with relative base — the base is first resolved against the working directory, then joined. The test asserts the exact resolved absolute path rather than a substring.
  • Failure case — the function only errors when it cannot resolve a relative base to an absolute path (i.e. when 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 with t.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 -l clean, 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

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

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>
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit 3defea7
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a4b69df3784f1000822dd43

@naman79820

Copy link
Copy Markdown
Author

@cmainas :))

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.

Add more unit tests

1 participant