Skip to content

Commit

Permalink
tests: frontend/dockerfile: update integration tests for windows/wcow
Browse files Browse the repository at this point in the history
- [x] `testCopyThroughSymlinkContext`
- [x] `testIgnoreEntrypoint`
- [x] `testQuotedMetaArgs`
- [x] `testDockerfileCheckHostname`
- [x] `testEmptyStages`
- [x] `testNamedImageContextScratch`
- [x] `testNamedImageContextPlatform`

Signed-off-by: Daniel Githinji <[email protected]>
  • Loading branch information
danielGithinji committed Oct 15, 2024
1 parent a7656ae commit ccdd43b
Showing 1 changed file with 76 additions and 24 deletions.
100 changes: 76 additions & 24 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,13 +1356,18 @@ RUN [ "$(stat -c "%U %G" /dest01)" == "user01 user" ]
}

func testCopyThroughSymlinkContext(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)

dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(
`
FROM scratch
COPY link/foo .
`)
`,
`
FROM nanoserver AS build
COPY link/foo .
`,
))

dir := integration.Tmpdir(
t,
Expand Down Expand Up @@ -1481,14 +1486,20 @@ COPY . /
}

func testIgnoreEntrypoint(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)

dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(
`
FROM busybox
ENTRYPOINT ["/nosuchcmd"]
RUN ["ls"]
`)
`,
`
FROM nanoserver AS build
ENTRYPOINT ["nosuchcmd.exe"]
RUN dir
`,
))

dir := integration.Tmpdir(
t,
Expand All @@ -1509,10 +1520,10 @@ RUN ["ls"]
}

func testQuotedMetaArgs(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)

dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(
`
ARG a1="box"
ARG a2="$a1-foo"
FROM busy$a1 AS build
Expand All @@ -1521,7 +1532,18 @@ ARG a3="bar-$a2"
RUN echo -n $a3 > /out
FROM scratch
COPY --from=build /out .
`)
`,
`
ARG a1="server"
ARG a2="$a1-foo"
FROM nano$a1 AS build
ARG a2
ARG a3="bar-$a2"
RUN echo %a3% > /out
FROM nanoserver
COPY --from=build /out .
`,
))

dir := integration.Tmpdir(
t,
Expand Down Expand Up @@ -1550,7 +1572,12 @@ COPY --from=build /out .

dt, err := os.ReadFile(filepath.Join(destDir, "out"))
require.NoError(t, err)
require.Equal(t, "bar-box-foo", string(dt))

// create a variable that holds a string depending on the OS platform.
// The string will be used to test against the string returned from the created out file
testString := string([]byte(integration.UnixOrWindows("bar-box-foo", "bar-server-foo \r\n")))

require.Equal(t, testString, string(dt))
}

func testGlobalArgErrors(t *testing.T, sb integration.Sandbox) {
Expand Down Expand Up @@ -6312,14 +6339,19 @@ COPY Dockerfile Dockerfile

// moby/buildkit#1301
func testDockerfileCheckHostname(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)
dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(
`
FROM busybox
RUN cat /etc/hosts | grep foo
RUN echo $HOSTNAME | grep foo
RUN echo $(hostname) | grep foo
`)
`,
`
FROM nanoserver
RUN reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname| findstr "foo"
`,
))

dir := integration.Tmpdir(
t,
Expand Down Expand Up @@ -6370,11 +6402,15 @@ RUN echo $(hostname) | grep foo
}

func testEmptyStages(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)
dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(
`
ARG foo=bar
`)
`,
`
ARG foo=bar
`,
))

dir := integration.Tmpdir(
t,
Expand Down Expand Up @@ -6693,7 +6729,6 @@ COPY --from=base /env_foobar /
}

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

Expand All @@ -6708,7 +6743,14 @@ func testNamedImageContextPlatform(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

// Build a base image and force buildkit to generate a manifest list.
dockerfile := []byte(`FROM --platform=$BUILDPLATFORM alpine:latest`)
dockerfile := []byte(integration.UnixOrWindows(
`
FROM --platform=$BUILDPLATFORM alpine:latest
`,
`
FROM --platform=$BUILDPLATFORM nanoserver:latest
`,
))
target := registry + "/buildkit/testnamedimagecontextplatform:latest"

dir := integration.Tmpdir(
Expand Down Expand Up @@ -6738,10 +6780,12 @@ func testNamedImageContextPlatform(t *testing.T, sb integration.Sandbox) {
}, nil)
require.NoError(t, err)

dockerfile = []byte(`
dockerfile = []byte(integration.UnixOrWindows(`
FROM --platform=$BUILDPLATFORM busybox AS target
RUN echo hello
`)
RUN echo hello`,
`
FROM --platform=$BUILDPLATFORM nanoserver AS target
RUN echo hello`))

dir = integration.Tmpdir(
t,
Expand Down Expand Up @@ -6852,19 +6896,27 @@ RUN echo foo >> /test
}

func testNamedImageContextScratch(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 busybox
COPY <<EOF /out
hello world!
EOF
`)
`,
`
FROM nanoserver AS build
FROM busybox
COPY <<EOF /out
hello world!
EOF
`,
))

dir := integration.Tmpdir(
t,
Expand Down

0 comments on commit ccdd43b

Please sign in to comment.