Skip to content

test(patch): add single-image helper coverage and fix EnsurePath error handling#1576

Open
omercnet wants to merge 4 commits into
project-copacetic:mainfrom
omercnet:coverage/pr4-test-single
Open

test(patch): add single-image helper coverage and fix EnsurePath error handling#1576
omercnet wants to merge 4 commits into
project-copacetic:mainfrom
omercnet:coverage/pr4-test-single

Conversation

@omercnet
Copy link
Copy Markdown
Contributor

@omercnet omercnet commented Apr 30, 2026

Part of the coverage-improvement series tracked in #1580.

Summary

Adds focused unit coverage for single-image patch helper paths and fixes a real utils.EnsurePath bug exposed by those tests.

  • Adds pkg/patch/single_test.go with focused coverage for pre-BuildKit single-image patch helpers.
  • Extends pkg/patch/patch_validation_test.go with the unique parsePkgTypes cases from the first draft, avoiding duplicate validation-test ownership.
  • Fixes pkg/utils.EnsurePath to return non-ENOENT os.Stat errors directly instead of dereferencing a nil FileInfo.

Why

pkg/patch/single.go is one of the largest low-coverage files in the package. Most of the full patching path requires live BuildKit/image infrastructure, but many guardrail/helper branches are unit-testable and should not require the integration suite.

While adding error-path tests for setupWorkingFolder, a bug in utils.EnsurePath surfaced: if os.Stat(path) returned an error that was not os.ErrNotExist, the old implementation entered the else branch and called st.IsDir() even though st was nil. The fix now returns non-ENOENT stat errors directly.

Covered areas

  • Invalid image-reference guardrail in patchSingleArchImage
  • validatePlatformEmulation host-platform happy path
  • setupWorkingFolder temp, existing, explicit-dir, and error paths
  • image reference resolution
  • loader auto-detection and loader-creation error cleanup
  • createPatchResultWithStates invalid patched-ref path
  • package-type inclusion helpers
  • report-parse and no-updates-after-filtering pre-BuildKit paths
  • EnsurePath non-ENOENT stat error behavior

Test plan

go test ./pkg/patch/... ./pkg/utils/... -count=1
go vet ./pkg/patch/... ./pkg/utils/...
golangci-lint run --timeout=2m ./pkg/patch/... ./pkg/utils/...

All pass locally.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds focused unit-test coverage for single-arch patching helpers in pkg/patch/single.go, complementing existing integration coverage and improving Codecov-reported unit coverage without changing production behavior.

Changes:

  • Add pkg/patch/single_test.go with table-driven unit tests for multiple helper/error paths in single.go.
  • Cover working folder setup/cleanup behavior, reference parsing/resolution, loader selection, and pkg-type parsing/validation.

Comment thread pkg/patch/single_test.go
Comment thread pkg/patch/single_test.go
Comment thread pkg/patch/single_test.go Outdated
sozercan
sozercan previously approved these changes May 10, 2026
@omercnet
Copy link
Copy Markdown
Contributor Author

@sozercan thanks for the EnsurePath fix on this branch — it looks like a real bug my tests exposed and I'm glad you patched it here.

One housekeeping issue: commit c67907a3 is missing a DCO trailer, so the PR now fails the DCO check. Could you please amend/sign off that commit and force-push?

Expected trailer format:

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>

I intentionally didn't rewrite your commit from my side so authorship/signoff stays with you.

Adds focused unit coverage for single-image patch helper paths that were
previously only exercised indirectly by integration tests.

Covered areas:
- invalid image-reference guardrail in patchSingleArchImage
- platform-emulation host happy path
- setupWorkingFolder temp, existing, explicit-dir, and error paths
- image reference resolution
- loader auto-detection and loader-creation error cleanup
- createPatchResultWithStates invalid patched-ref path
- package-type inclusion helpers
- report-parse and no-updates-after-filtering pre-BuildKit paths

The tests exposed a real bug in utils.EnsurePath: if os.Stat returned an
error other than ENOENT, the previous implementation dereferenced a nil
FileInfo while checking st.IsDir(). Return non-ENOENT stat errors
directly instead.

Also extends patch_validation_test.go with the unique parsePkgTypes cases
from the first draft, avoiding duplicate validation-test ownership in
single_test.go.

Verified:
- go test ./pkg/patch/... ./pkg/utils/... -count=1
- go vet ./pkg/patch/... ./pkg/utils/...
- golangci-lint run --timeout=2m ./pkg/patch/... ./pkg/utils/...

Signed-off-by: Omer <omer@descope.com>
@omercnet omercnet force-pushed the coverage/pr4-test-single branch from 9aa2e6d to c896958 Compare May 17, 2026 16:47
@omercnet omercnet changed the title test(patch): add unit tests for pkg/patch/single.go test(patch): add single-image helper coverage and fix EnsurePath error handling May 17, 2026
@omercnet
Copy link
Copy Markdown
Contributor Author

omercnet commented May 17, 2026

I rewrote the branch cleanly on current main with one signed commit (c8969586) containing both the single-image helper tests and the EnsurePath fix. That removes the unsigned c67907a3 commit while preserving its behavior, so DCO should clear on the new run. Thanks again for catching/fixing the EnsurePath path — the new test coverage keeps it guarded.

@omercnet omercnet requested a review from sozercan May 21, 2026 09:09
@omercnet omercnet enabled auto-merge (squash) May 21, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

3 participants