pkg/bindings/images: fix TestConvertAdditionalBuildContexts on non-Windows hosts

TestConvertAdditionalBuildContexts asserted that the additional build
context "C:\test" is rewritten to "/mnt/c/test". That rewrite is done by
specgen.ConvertWinMountPath, which is a no-op unless shouldResolveWinPaths()
is true: always on Windows, but on Linux only when the client runs inside a
WSL or Hyper-V guest. On an ordinary Linux host the value is passed through
unchanged and the test fails.

Keep the platform independent expectations (URLs, images and unix paths are
never rewritten) in the shared test and move the drive letter case to a
Windows only file, following the existing split in pkg/specgen.

Signed-off-by: Daksha1611 <mehtadaksha1611@gmail.com>
This commit is contained in:
Daksha1611 2026-09-18 20:36:13 +05:30
parent 17b9000cf7
commit 20a077b16c
2 changed files with 26 additions and 7 deletions

View file

@ -17,14 +17,11 @@ func TestBuildNotMatchStatusMessage(t *testing.T) {
assert.False(t, iidRegex.MatchString("Copying config a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4"))
}
// Windows host paths are only rewritten when the client runs on Windows or
// inside a WSL/Hyper-V guest, so the drive letter case is covered separately in
// build_windows_test.go. The values below are left alone on every platform.
func TestConvertAdditionalBuildContexts(t *testing.T) {
additionalBuildContexts := map[string]*define.AdditionalBuildContext{
"context1": {
IsURL: false,
IsImage: false,
Value: "C:\\test",
DownloadedCache: "",
},
"context2": {
IsURL: false,
IsImage: false,
@ -48,7 +45,6 @@ func TestConvertAdditionalBuildContexts(t *testing.T) {
convertAdditionalBuildContexts(additionalBuildContexts)
expectedGuestValues := map[string]string{
"context1": "/mnt/c/test",
"context2": "/test",
"context3": "https://a.com/b.tar",
"context4": "quay.io/a/b:c",

View file

@ -0,0 +1,23 @@
package images
import (
"testing"
"github.com/stretchr/testify/assert"
"go.podman.io/buildah/define"
)
func TestConvertAdditionalBuildContextsWindowsPath(t *testing.T) {
additionalBuildContexts := map[string]*define.AdditionalBuildContext{
"context1": {
IsURL: false,
IsImage: false,
Value: "C:\\test",
DownloadedCache: "",
},
}
convertAdditionalBuildContexts(additionalBuildContexts)
assert.Equal(t, "/mnt/c/test", additionalBuildContexts["context1"].Value)
}