Add a build unit test for symlinked context

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2018-03-07 13:04:33 -05:00
parent 0e3677ead5
commit 00b803b2d8
1 changed files with 38 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package image
import (
"archive/tar"
"bytes"
"io"
"io/ioutil"
@ -194,3 +195,40 @@ func TestRunBuildFromLocalGitHubDir(t *testing.T) {
err = cmd.Execute()
assert.NilError(t, err)
}
func TestRunBuildWithSymlinkedContext(t *testing.T) {
dockerfile := `
FROM alpine:3.6
RUN echo hello world
`
tmpDir := fs.NewDir(t, t.Name(),
fs.WithDir("context",
fs.WithFile("Dockerfile", dockerfile)),
fs.WithSymlink("context-link", "context"))
defer tmpDir.Remove()
files := []string{}
fakeImageBuild := func(_ context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
tarReader := tar.NewReader(context)
for {
hdr, err := tarReader.Next()
switch err {
case io.EOF:
body := new(bytes.Buffer)
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
case nil:
files = append(files, hdr.Name)
default:
return types.ImageBuildResponse{}, err
}
}
}
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeImageBuild})
options := newBuildOptions()
options.context = tmpDir.Join("context-link")
assert.NilError(t, runBuild(cli, options))
assert.DeepEqual(t, files, []string{"Dockerfile"})
}