buildkit/frontend/dockerfile/dockerfile2llb/convert_test.go

65 lines
1.5 KiB
Go
Raw Normal View History

package dockerfile2llb
import (
"testing"
"github.com/moby/buildkit/util/appcontext"
"github.com/stretchr/testify/assert"
)
func TestDockerfileParsing(t *testing.T) {
t.Parallel()
df := `FROM busybox
ENV FOO bar
COPY f1 f2 /sub/
RUN ls -l
`
_, _, err := Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.NoError(t, err)
df = `FROM busybox AS foo
ENV FOO bar
FROM foo
COPY --from=foo f1 /
COPY --from=0 f2 /
`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.NoError(t, err)
df = `FROM busybox AS foo
ENV FOO bar
FROM foo
COPY --from=foo f1 /
COPY --from=0 f2 /
`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{
Target: "Foo",
})
assert.NoError(t, err)
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{
Target: "nosuch",
})
assert.Error(t, err)
df = `FROM busybox
ADD http://github.com/moby/buildkit/blob/master/README.md /
`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.NoError(t, err)
df = `FROM busybox
COPY http://github.com/moby/buildkit/blob/master/README.md /
`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.EqualError(t, err, "source can't be a URL for COPY")
df = `FROM "" AS foo`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.Error(t, err)
df = `FROM ${BLANK} AS foo`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.Error(t, err)
}