mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #6780 from unclejack/tweak_cli_integration_tests
Tweak cli integration tests
This commit is contained in:
commit
f357b18ee3
3 changed files with 29 additions and 16 deletions
|
@ -43,7 +43,7 @@ func TestRemoveContainerWithVolume(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoveContainerRunning(t *testing.T) {
|
func TestRemoveContainerRunning(t *testing.T) {
|
||||||
cmd := exec.Command(dockerBinary, "run", "-d", "--name", "foo", "busybox", "sleep", "300")
|
cmd := exec.Command(dockerBinary, "run", "-dt", "--name", "foo", "busybox", "top")
|
||||||
if _, err := runCommand(cmd); err != nil {
|
if _, err := runCommand(cmd); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,12 @@ import (
|
||||||
|
|
||||||
// tagging a named image in a new unprefixed repo should work
|
// tagging a named image in a new unprefixed repo should work
|
||||||
func TestTagUnprefixedRepoByName(t *testing.T) {
|
func TestTagUnprefixedRepoByName(t *testing.T) {
|
||||||
pullCmd := exec.Command(dockerBinary, "pull", "busybox")
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
||||||
out, exitCode, err := runCommandWithOutput(pullCmd)
|
t.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
||||||
errorOut(err, t, fmt.Sprintf("%s %s", out, err))
|
|
||||||
|
|
||||||
if err != nil || exitCode != 0 {
|
|
||||||
t.Fatal("pulling the busybox image from the registry has failed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tagCmd := exec.Command(dockerBinary, "tag", "busybox", "testfoobarbaz")
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "testfoobarbaz")
|
||||||
out, _, err = runCommandWithOutput(tagCmd)
|
out, _, err := runCommandWithOutput(tagCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("%v %v", out, err))
|
errorOut(err, t, fmt.Sprintf("%v %v", out, err))
|
||||||
|
|
||||||
deleteImages("testfoobarbaz")
|
deleteImages("testfoobarbaz")
|
||||||
|
@ -62,18 +58,14 @@ func TestTagInvalidUnprefixedRepo(t *testing.T) {
|
||||||
|
|
||||||
// ensure we allow the use of valid tags
|
// ensure we allow the use of valid tags
|
||||||
func TestTagValidPrefixedRepo(t *testing.T) {
|
func TestTagValidPrefixedRepo(t *testing.T) {
|
||||||
pullCmd := exec.Command(dockerBinary, "pull", "busybox")
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
||||||
out, exitCode, err := runCommandWithOutput(pullCmd)
|
t.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
||||||
errorOut(err, t, fmt.Sprintf("%s %s", out, err))
|
|
||||||
|
|
||||||
if err != nil || exitCode != 0 {
|
|
||||||
t.Fatal("pulling the busybox image from the registry has failed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validRepos := []string{"fooo/bar", "fooaa/test"}
|
validRepos := []string{"fooo/bar", "fooaa/test"}
|
||||||
|
|
||||||
for _, repo := range validRepos {
|
for _, repo := range validRepos {
|
||||||
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repo)
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", repo)
|
||||||
_, _, err := runCommandWithOutput(tagCmd)
|
_, _, err := runCommandWithOutput(tagCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("tag busybox %v should have worked: %s", repo, err)
|
t.Errorf("tag busybox %v should have worked: %s", repo, err)
|
||||||
|
|
|
@ -66,6 +66,27 @@ func deleteImages(images string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func imageExists(image string) error {
|
||||||
|
inspectCmd := exec.Command(dockerBinary, "inspect", image)
|
||||||
|
exitCode, err := runCommand(inspectCmd)
|
||||||
|
if exitCode != 0 && err == nil {
|
||||||
|
err = fmt.Errorf("couldn't find image '%s'", image)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func pullImageIfNotExist(image string) (err error) {
|
||||||
|
if err := imageExists(image); err != nil {
|
||||||
|
pullCmd := exec.Command(dockerBinary, "pull", image)
|
||||||
|
_, exitCode, err := runCommandWithOutput(pullCmd)
|
||||||
|
|
||||||
|
if err != nil || exitCode != 0 {
|
||||||
|
err = fmt.Errorf("image '%s' wasn't found locally and it couldn't be pulled: %s", image, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func cmd(t *testing.T, args ...string) (string, int, error) {
|
func cmd(t *testing.T, args ...string) (string, int, error) {
|
||||||
out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...))
|
out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...))
|
||||||
errorOut(err, t, fmt.Sprintf("'%s' failed with errors: %v (%v)", strings.Join(args, " "), err, out))
|
errorOut(err, t, fmt.Sprintf("'%s' failed with errors: %v (%v)", strings.Join(args, " "), err, out))
|
||||||
|
|
Loading…
Reference in a new issue