2017-08-25 20:08:18 +00:00
|
|
|
package dockerfile2llb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/util/appcontext"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDockerfileParsing(t *testing.T) {
|
2017-12-09 02:19:08 +00:00
|
|
|
t.Parallel()
|
2017-08-25 20:08:18 +00:00
|
|
|
df := `FROM busybox
|
|
|
|
ENV FOO bar
|
|
|
|
COPY f1 f2 /sub/
|
|
|
|
RUN ls -l
|
|
|
|
`
|
2017-09-11 05:35:07 +00:00
|
|
|
_, _, err := Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
|
2017-08-25 20:08:18 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
df = `FROM busybox AS foo
|
|
|
|
ENV FOO bar
|
|
|
|
FROM foo
|
|
|
|
COPY --from=foo f1 /
|
|
|
|
COPY --from=0 f2 /
|
|
|
|
`
|
2017-09-11 05:35:07 +00:00
|
|
|
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
|
2017-08-25 20:08:18 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
df = `FROM busybox AS foo
|
|
|
|
ENV FOO bar
|
|
|
|
FROM foo
|
|
|
|
COPY --from=foo f1 /
|
|
|
|
COPY --from=0 f2 /
|
|
|
|
`
|
2017-09-11 05:35:07 +00:00
|
|
|
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{
|
2017-08-25 20:08:18 +00:00
|
|
|
Target: "Foo",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2017-09-11 05:35:07 +00:00
|
|
|
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{
|
2017-08-25 20:08:18 +00:00
|
|
|
Target: "nosuch",
|
|
|
|
})
|
|
|
|
assert.Error(t, err)
|
2018-06-27 23:46:29 +00:00
|
|
|
|
2018-07-03 11:28:08 +00:00
|
|
|
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")
|
|
|
|
|
2018-06-27 23:46:29 +00:00
|
|
|
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)
|
2017-08-25 20:08:18 +00:00
|
|
|
}
|