test(patch): add single-image helper coverage and fix EnsurePath error handling#1576
test(patch): add single-image helper coverage and fix EnsurePath error handling#1576omercnet wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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.gowith table-driven unit tests for multiple helper/error paths insingle.go. - Cover working folder setup/cleanup behavior, reference parsing/resolution, loader selection, and pkg-type parsing/validation.
12eb224 to
98ec4e4
Compare
98ec4e4 to
ab167d1
Compare
|
@sozercan thanks for the One housekeeping issue: commit Expected trailer format: 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>
9aa2e6d to
c896958
Compare
|
I rewrote the branch cleanly on current main with one signed commit ( |
Summary
Adds focused unit coverage for single-image patch helper paths and fixes a real
utils.EnsurePathbug exposed by those tests.pkg/patch/single_test.gowith focused coverage for pre-BuildKit single-image patch helpers.pkg/patch/patch_validation_test.gowith the uniqueparsePkgTypescases from the first draft, avoiding duplicate validation-test ownership.pkg/utils.EnsurePathto return non-ENOENTos.Staterrors directly instead of dereferencing a nilFileInfo.Why
pkg/patch/single.gois 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 inutils.EnsurePathsurfaced: ifos.Stat(path)returned an error that was notos.ErrNotExist, the old implementation entered theelsebranch and calledst.IsDir()even thoughstwas nil. The fix now returns non-ENOENT stat errors directly.Covered areas
patchSingleArchImagevalidatePlatformEmulationhost-platform happy pathsetupWorkingFoldertemp, existing, explicit-dir, and error pathscreatePatchResultWithStatesinvalid patched-ref pathEnsurePathnon-ENOENT stat error behaviorTest 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.