Skip to content

Commit

Permalink
Updated tests in frontend/dockerfile/dockerfile_provenance_test.go to…
Browse files Browse the repository at this point in the history
… run on Windows.

Partially addressing #4485

Signed-off-by: Billy Owire <billyowire@microsoft.com>
  • Loading branch information
Billy Owire committed Aug 14, 2024
1 parent 5e729c3 commit 0fa776e
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions frontend/dockerfile/dockerfile_provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
)

func testProvenanceAttestation(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush, workers.FeatureProvenance)
ctx := sb.Context()

Expand All @@ -59,10 +58,12 @@ func testProvenanceAttestation(t *testing.T, sb integration.Sandbox) {

f := getFrontend(t, sb)

dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(`
FROM busybox:latest
RUN echo "ok" > /foo
`)
`, `FROM nanoserver
RUN echo ok> /foo`))

dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
Expand Down Expand Up @@ -115,7 +116,9 @@ RUN echo "ok" > /foo

img := imgs.Find(platforms.Format(platforms.Normalize(platforms.DefaultSpec())))
require.NotNil(t, img)
require.Equal(t, []byte("ok\n"), img.Layers[1]["foo"].Data)
outFile := integration.UnixOrWindows("foo", "Files/foo") //image layer files are prefixed with Files\ in windows
expectedFileData := integration.UnixOrWindows([]byte("ok\n"), []byte("ok\r\n")) //echo adds \r\n in windows
require.Equal(t, expectedFileData, img.Layers[1][outFile].Data)

att := imgs.Find("unknown/unknown")
require.NotNil(t, att)
Expand Down Expand Up @@ -179,7 +182,9 @@ RUN echo "ok" > /foo
require.Equal(t, "https://xxxxx:xxxxx@example.invalid/foo.html", args["context:foo"])
}

expectedBase := "pkg:docker/busybox@latest?platform=" + url.PathEscape(platforms.Format(platforms.Normalize(platforms.DefaultSpec())))
expectedBaseImage := integration.UnixOrWindows("busybox", "nanoserver")
escapedPlatform := url.PathEscape(platforms.Format(platforms.Normalize(platforms.DefaultSpec())))
expectedBase := fmt.Sprintf("pkg:docker/%s@latest?platform=%s", expectedBaseImage, escapedPlatform)
if isGateway {
require.Equal(t, 2, len(pred.Materials), "%+v", pred.Materials)
require.Contains(t, pred.Materials[0].URI, "docker/buildkit_test")
Expand Down Expand Up @@ -1020,7 +1025,6 @@ EOF
}

func testNilProvenance(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
workers.CheckFeatureCompat(t, sb, workers.FeatureProvenance)
ctx := sb.Context()

Expand All @@ -1030,10 +1034,12 @@ func testNilProvenance(t *testing.T, sb integration.Sandbox) {

f := getFrontend(t, sb)

dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(`
FROM scratch
ENV FOO=bar
`)
`, `
FROM scratch
ENV FOO=bar`))
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
Expand All @@ -1058,7 +1064,6 @@ ENV FOO=bar

// https://github.com/moby/buildkit/issues/3562
func testDuplicatePlatformProvenance(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
workers.CheckFeatureCompat(t, sb, workers.FeatureProvenance)
ctx := sb.Context()

Expand All @@ -1068,16 +1073,16 @@ func testDuplicatePlatformProvenance(t *testing.T, sb integration.Sandbox) {

f := getFrontend(t, sb)

dockerfile := []byte(`FROM alpine`)
dockerfile := []byte(integration.UnixOrWindows(`FROM alpine`, `FROM nanoserver`))
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)

platform := integration.UnixOrWindows("linux/amd64,linux/amd64", "windows/amd64")
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
FrontendAttrs: map[string]string{
"attest:provenance": "mode=max",
"platform": "linux/amd64,linux/amd64",
"platform": platform,
},
LocalMounts: map[string]fsutil.FS{
dockerui.DefaultLocalNameDockerfile: dir,
Expand All @@ -1089,13 +1094,12 @@ func testDuplicatePlatformProvenance(t *testing.T, sb integration.Sandbox) {

// https://github.com/moby/buildkit/issues/3928
func testDockerIgnoreMissingProvenance(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
workers.CheckFeatureCompat(t, sb, workers.FeatureProvenance)
c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

dockerfile := []byte(`FROM alpine`)
dockerfile := []byte(integration.UnixOrWindows(`FROM alpine`, `FROM nanoserver`))
dirDockerfile := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
Expand Down Expand Up @@ -1132,20 +1136,24 @@ func testDockerIgnoreMissingProvenance(t *testing.T, sb integration.Sandbox) {
}

func testCommandSourceMapping(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush, workers.FeatureProvenance)
ctx := sb.Context()

c, err := client.New(ctx, sb.Address())
require.NoError(t, err)
defer c.Close()

dockerfile := []byte(`FROM alpine
dockerfile := []byte(integration.UnixOrWindows(`FROM alpine
RUN echo "hello" > foo
WORKDIR /tmp
COPY foo foo2
COPY --link foo foo3
ADD bar bar`)
ADD bar bar`, `FROM nanoserver
RUN echo "hello" > foo
WORKDIR C:\tmp
COPY foo foo2
COPY foo foo3
ADD bar bar`))

dir := integration.Tmpdir(
t,
Expand Down Expand Up @@ -1250,20 +1258,25 @@ ADD bar bar`)
}

func testFrontendDeduplicateSources(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
ctx := sb.Context()

c, err := client.New(ctx, sb.Address())
require.NoError(t, err)
defer c.Close()

dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(`
FROM scratch as base
COPY foo foo2
FROM linked
COPY bar bar2
`)
`, `FROM nanoserver as base
RUN mkdir foo2
COPY foo foo2
FROM nanoserver
RUN mkdir bar2
COPY bar bar2`))

dir := integration.Tmpdir(
t,
Expand Down

0 comments on commit 0fa776e

Please sign in to comment.