From f007d623a8317bfeffff609de3027bf585d3f040 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 27 Jul 2017 11:30:18 +0200 Subject: [PATCH] Add test for github.com special handling Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build_test.go | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cli/command/image/build_test.go b/cli/command/image/build_test.go index b3fb3c6834..c874e90965 100644 --- a/cli/command/image/build_test.go +++ b/cli/command/image/build_test.go @@ -68,3 +68,37 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) { sort.Strings(actual) assert.Equal(t, []string{dockerfileName, ".dockerignore", "foo"}, actual) } + +// TestRunBuildFromLocalGitHubDirNonExistingRepo tests that build contexts +// starting with `github.com/` are special-cased, and the build command attempts +// to clone the remote repo. +func TestRunBuildFromGitHubSpecialCase(t *testing.T) { + cmd := NewBuildCommand(&command.DockerCli{}) + cmd.SetArgs([]string{"github.com/docker/no-such-repository"}) + cmd.SetOutput(ioutil.Discard) + err := cmd.Execute() + assert.Error(t, err) + assert.Contains(t, err.Error(), "unable to prepare context: unable to 'git clone'") +} + +// TestRunBuildFromLocalGitHubDirNonExistingRepo tests that a local directory +// starting with `github.com` takes precedence over the `github.com` special +// case. +func TestRunBuildFromLocalGitHubDir(t *testing.T) { + tmpDir, err := ioutil.TempDir("", "docker-build-from-local-dir-") + require.NoError(t, err) + defer os.RemoveAll(tmpDir) + + buildDir := filepath.Join(tmpDir, "github.com", "docker", "no-such-repository") + err = os.MkdirAll(buildDir, 0777) + require.NoError(t, err) + err = ioutil.WriteFile(filepath.Join(buildDir, "Dockerfile"), []byte("FROM busybox\n"), 0644) + require.NoError(t, err) + + client := test.NewFakeCli(&fakeClient{}) + cmd := NewBuildCommand(client) + cmd.SetArgs([]string{buildDir}) + cmd.SetOutput(ioutil.Discard) + err = cmd.Execute() + require.NoError(t, err) +}