Skip to content

Commit 076d69e

Browse files
authored
Merge pull request moby#5350 from billywr/wcow-integration-test-part-4
tests: frontend/dockerfile: update integration tests for windows/wcow (part 4)
2 parents 3c06cec + 8e5c34f commit 076d69e

File tree

1 file changed

+97
-46
lines changed

1 file changed

+97
-46
lines changed

frontend/dockerfile/dockerfile_test.go

Lines changed: 97 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,17 +1029,28 @@ RUN e="300:400"; p="/file" ; a=` + "`" + `stat -c "%u:%g
10291029
}
10301030

10311031
func testCopyWildcardCache(t *testing.T, sb integration.Sandbox) {
1032-
integration.SkipOnPlatform(t, "windows")
10331032
f := getFrontend(t, sb)
10341033

1035-
dockerfile := []byte(`
1034+
dockerfile := []byte(integration.UnixOrWindows(
1035+
`
10361036
FROM busybox AS base
10371037
COPY foo* files/
10381038
RUN cat /dev/urandom | head -c 100 | sha256sum > unique
10391039
COPY bar files/
10401040
FROM scratch
10411041
COPY --from=base unique /
1042-
`)
1042+
`,
1043+
`
1044+
FROM nanoserver AS base
1045+
USER ContainerAdministrator
1046+
WORKDIR /files
1047+
COPY foo* /files/
1048+
RUN echo test> /unique
1049+
COPY bar /files/
1050+
FROM nanoserver
1051+
COPY --from=base /unique /
1052+
`,
1053+
))
10431054

10441055
dir := integration.Tmpdir(
10451056
t,
@@ -1115,8 +1126,9 @@ COPY --from=base unique /
11151126
require.NoError(t, err)
11161127

11171128
dt2, err = os.ReadFile(filepath.Join(destDir, "unique"))
1129+
expectedStr := string(dt)
11181130
require.NoError(t, err)
1119-
require.NotEqual(t, string(dt), string(dt2))
1131+
require.NotEqual(t, integration.UnixOrWindows(expectedStr, expectedStr+"\r\n"), string(dt2))
11201132
}
11211133

11221134
func testEmptyWildcard(t *testing.T, sb integration.Sandbox) {
@@ -2801,7 +2813,6 @@ ADD %s /dest/
28012813
}
28022814

28032815
func testDockerfileAddArchive(t *testing.T, sb integration.Sandbox) {
2804-
integration.SkipOnPlatform(t, "windows")
28052816
f := getFrontend(t, sb)
28062817
f.RequiresBuildctl(t)
28072818

@@ -2820,10 +2831,12 @@ func testDockerfileAddArchive(t *testing.T, sb integration.Sandbox) {
28202831
err = tw.Close()
28212832
require.NoError(t, err)
28222833

2823-
dockerfile := []byte(`
2824-
FROM scratch
2834+
baseImage := integration.UnixOrWindows("scratch", "nanoserver")
2835+
2836+
dockerfile := []byte(fmt.Sprintf(`
2837+
FROM %s
28252838
ADD t.tar /
2826-
`)
2839+
`, baseImage))
28272840

28282841
dir := integration.Tmpdir(
28292842
t,
@@ -2851,10 +2864,10 @@ ADD t.tar /
28512864
err = gz.Close()
28522865
require.NoError(t, err)
28532866

2854-
dockerfile = []byte(`
2855-
FROM scratch
2867+
dockerfile = []byte(fmt.Sprintf(`
2868+
FROM %s
28562869
ADD t.tar.gz /
2857-
`)
2870+
`, baseImage))
28582871

28592872
dir = integration.Tmpdir(
28602873
t,
@@ -2875,10 +2888,10 @@ ADD t.tar.gz /
28752888
require.Equal(t, expectedContent, dt)
28762889

28772890
// COPY doesn't extract
2878-
dockerfile = []byte(`
2879-
FROM scratch
2891+
dockerfile = []byte(fmt.Sprintf(`
2892+
FROM %s
28802893
COPY t.tar.gz /
2881-
`)
2894+
`, baseImage))
28822895

28832896
dir = integration.Tmpdir(
28842897
t,
@@ -2910,9 +2923,9 @@ COPY t.tar.gz /
29102923
defer server.Close()
29112924

29122925
dockerfile = []byte(fmt.Sprintf(`
2913-
FROM scratch
2926+
FROM %s
29142927
ADD %s /
2915-
`, server.URL+"/t.tar.gz"))
2928+
`, baseImage, server.URL+"/t.tar.gz"))
29162929

29172930
dir = integration.Tmpdir(
29182931
t,
@@ -2933,9 +2946,9 @@ ADD %s /
29332946

29342947
// https://github.com/moby/buildkit/issues/386
29352948
dockerfile = []byte(fmt.Sprintf(`
2936-
FROM scratch
2949+
FROM %s
29372950
ADD %s /newname.tar.gz
2938-
`, server.URL+"/t.tar.gz"))
2951+
`, baseImage, server.URL+"/t.tar.gz"))
29392952

29402953
dir = integration.Tmpdir(
29412954
t,
@@ -4422,13 +4435,21 @@ COPY foo bar
44224435
}
44234436

44244437
func testMultiStageImplicitFrom(t *testing.T, sb integration.Sandbox) {
4425-
integration.SkipOnPlatform(t, "windows")
44264438
f := getFrontend(t, sb)
44274439

4428-
dockerfile := []byte(`
4440+
dockerfile := []byte(integration.UnixOrWindows(
4441+
`
44294442
FROM scratch
44304443
COPY --from=busybox /etc/passwd test
4431-
`)
4444+
`, `
4445+
FROM nanoserver AS build
4446+
USER ContainerAdministrator
4447+
RUN echo test> test
4448+
4449+
FROM nanoserver
4450+
COPY --from=build /test /test
4451+
`,
4452+
))
44324453

44334454
dir := integration.Tmpdir(
44344455
t,
@@ -4457,17 +4478,26 @@ COPY --from=busybox /etc/passwd test
44574478

44584479
dt, err := os.ReadFile(filepath.Join(destDir, "test"))
44594480
require.NoError(t, err)
4460-
require.Contains(t, string(dt), "root")
4481+
require.Contains(t, string(dt), integration.UnixOrWindows("root", "test"))
44614482

44624483
// testing masked image will load actual stage
44634484

4464-
dockerfile = []byte(`
4485+
dockerfile = []byte(integration.UnixOrWindows(
4486+
`
44654487
FROM busybox AS golang
44664488
RUN mkdir -p /usr/bin && echo -n foo > /usr/bin/go
44674489
44684490
FROM scratch
44694491
COPY --from=golang /usr/bin/go go
4470-
`)
4492+
`, `
4493+
FROM nanoserver AS golang
4494+
USER ContainerAdministrator
4495+
RUN echo foo> go
4496+
4497+
FROM nanoserver
4498+
COPY --from=golang /go /go
4499+
`,
4500+
))
44714501

44724502
dir = integration.Tmpdir(
44734503
t,
@@ -4495,17 +4525,18 @@ COPY --from=golang /usr/bin/go go
44954525
}
44964526

44974527
func testMultiStageCaseInsensitive(t *testing.T, sb integration.Sandbox) {
4498-
integration.SkipOnPlatform(t, "windows")
44994528
f := getFrontend(t, sb)
45004529

4501-
dockerfile := []byte(`
4502-
FROM scratch AS STAge0
4530+
dockerfileStr := `
4531+
FROM %s AS STAge0
45034532
COPY foo bar
4504-
FROM scratch AS staGE1
4533+
FROM %s AS staGE1
45054534
COPY --from=staGE0 bar baz
4506-
FROM scratch
4535+
FROM %s
45074536
COPY --from=stage1 baz bax
4508-
`)
4537+
`
4538+
baseImage := integration.UnixOrWindows("scratch", "nanoserver")
4539+
dockerfile := []byte(fmt.Sprintf(dockerfileStr, baseImage, baseImage, baseImage))
45094540
dir := integration.Tmpdir(
45104541
t,
45114542
fstest.CreateFile("Dockerfile", dockerfile, 0600),
@@ -4665,7 +4696,6 @@ RUN dir file1
46654696
}
46664697

46674698
func testOnBuildCleared(t *testing.T, sb integration.Sandbox) {
4668-
integration.SkipOnPlatform(t, "windows")
46694699
workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush)
46704700
f := getFrontend(t, sb)
46714701

@@ -4675,10 +4705,16 @@ func testOnBuildCleared(t *testing.T, sb integration.Sandbox) {
46754705
}
46764706
require.NoError(t, err)
46774707

4678-
dockerfile := []byte(`
4708+
dockerfile := []byte(integration.UnixOrWindows(
4709+
`
46794710
FROM busybox
46804711
ONBUILD RUN mkdir -p /out && echo -n 11 >> /out/foo
4681-
`)
4712+
`, `
4713+
FROM nanoserver
4714+
USER ContainerAdministrator
4715+
ONBUILD RUN mkdir \out && echo 11>> \out\foo
4716+
`,
4717+
))
46824718

46834719
dir := integration.Tmpdir(
46844720
t,
@@ -4738,9 +4774,9 @@ ONBUILD RUN mkdir -p /out && echo -n 11 >> /out/foo
47384774

47394775
dockerfile = []byte(fmt.Sprintf(`
47404776
FROM %s AS base
4741-
FROM scratch
4777+
FROM %s
47424778
COPY --from=base /out /
4743-
`, target2))
4779+
`, target2, integration.UnixOrWindows("scratch", "nanoserver")))
47444780

47454781
dir = integration.Tmpdir(
47464782
t,
@@ -4764,7 +4800,7 @@ ONBUILD RUN mkdir -p /out && echo -n 11 >> /out/foo
47644800

47654801
dt, err := os.ReadFile(filepath.Join(destDir, "foo"))
47664802
require.NoError(t, err)
4767-
require.Equal(t, "11", string(dt))
4803+
require.Equal(t, integration.UnixOrWindows("11", "11\r\n"), string(dt))
47684804
}
47694805

47704806
func testOnBuildNamedContext(t *testing.T, sb integration.Sandbox) {
@@ -5833,10 +5869,10 @@ COPY --from=build out .
58335869
}
58345870

58355871
func testBuiltinArgs(t *testing.T, sb integration.Sandbox) {
5836-
integration.SkipOnPlatform(t, "windows")
58375872
f := getFrontend(t, sb)
58385873

5839-
dockerfile := []byte(`
5874+
dockerfile := []byte(integration.UnixOrWindows(
5875+
`
58405876
FROM busybox AS build
58415877
ARG FOO
58425878
ARG BAR
@@ -5845,7 +5881,18 @@ RUN echo -n $HTTP_PROXY::$NO_PROXY::$FOO::$BAR::$BAZ > /out
58455881
FROM scratch
58465882
COPY --from=build /out /
58475883
5848-
`)
5884+
`, `
5885+
FROM nanoserver AS build
5886+
USER ContainerAdministrator
5887+
ARG FOO
5888+
ARG BAR
5889+
ARG BAZ=bazcontent
5890+
RUN echo %HTTP_PROXY%::%NO_PROXY%::%FOO%::%BAR%::%BAZ%> out
5891+
FROM nanoserver
5892+
COPY --from=build out /
5893+
`,
5894+
))
5895+
58495896
dir := integration.Tmpdir(
58505897
t,
58515898
fstest.CreateFile("Dockerfile", dockerfile, 0600),
@@ -5880,7 +5927,9 @@ COPY --from=build /out /
58805927

58815928
dt, err := os.ReadFile(filepath.Join(destDir, "out"))
58825929
require.NoError(t, err)
5883-
require.Equal(t, "hpvalue::npvalue::foocontents::::bazcontent", string(dt))
5930+
// Windows can't interpret empty env variables, %BAR% handles empty values.
5931+
expectedStr := integration.UnixOrWindows(`hpvalue::npvalue::foocontents::::bazcontent`, "hpvalue::npvalue::foocontents::%BAR%::bazcontent\r\n")
5932+
require.Equal(t, expectedStr, string(dt))
58845933

58855934
// repeat with changed default args should match the old cache
58865935
destDir = t.TempDir()
@@ -5907,7 +5956,8 @@ COPY --from=build /out /
59075956

59085957
dt, err = os.ReadFile(filepath.Join(destDir, "out"))
59095958
require.NoError(t, err)
5910-
require.Equal(t, "hpvalue::npvalue::foocontents::::bazcontent", string(dt))
5959+
expectedStr = integration.UnixOrWindows("hpvalue::npvalue::foocontents::::bazcontent", "hpvalue::npvalue::foocontents::%BAR%::bazcontent\r\n")
5960+
require.Equal(t, expectedStr, string(dt))
59115961

59125962
// changing actual value invalidates cache
59135963
destDir = t.TempDir()
@@ -5934,7 +5984,8 @@ COPY --from=build /out /
59345984

59355985
dt, err = os.ReadFile(filepath.Join(destDir, "out"))
59365986
require.NoError(t, err)
5937-
require.Equal(t, "hpvalue2::::foocontents2::::bazcontent", string(dt))
5987+
expectedStr = integration.UnixOrWindows("hpvalue2::::foocontents2::::bazcontent", "hpvalue2::%NO_PROXY%::foocontents2::%BAR%::bazcontent\r\n")
5988+
require.Equal(t, expectedStr, string(dt))
59385989
}
59395990

59405991
func testTarContext(t *testing.T, sb integration.Sandbox) {
@@ -6050,15 +6101,15 @@ COPY foo bar
60506101
}
60516102

60526103
func testFrontendUseForwardedSolveResults(t *testing.T, sb integration.Sandbox) {
6053-
integration.SkipOnPlatform(t, "windows")
60546104
c, err := client.New(sb.Context(), sb.Address())
60556105
require.NoError(t, err)
60566106
defer c.Close()
60576107

6058-
dockerfile := []byte(`
6059-
FROM scratch
6108+
dockerfileStr := `
6109+
FROM %s
60606110
COPY foo foo2
6061-
`)
6111+
`
6112+
dockerfile := []byte(fmt.Sprintf(dockerfileStr, integration.UnixOrWindows("scratch", "nanoserver")))
60626113
dir := integration.Tmpdir(
60636114
t,
60646115
fstest.CreateFile("Dockerfile", dockerfile, 0600),

0 commit comments

Comments
 (0)