mirror of https://github.com/docker/cli.git
Merge pull request #390 from thaJeztah/add-test-for-github-special-case
Add test for github.com special handling
This commit is contained in:
commit
aaf6939679
|
@ -68,3 +68,37 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
||||||
sort.Strings(actual)
|
sort.Strings(actual)
|
||||||
assert.Equal(t, []string{dockerfileName, ".dockerignore", "foo"}, 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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue