1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Convert a legacy integration test to a clean v2 CLI integration test.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-04-04 00:57:41 +00:00
parent 902f88ea15
commit 30f22ee9e3
4 changed files with 49 additions and 59 deletions

View file

@ -18,3 +18,41 @@ func TestImagesEnsureImageIsListed(t *testing.T) {
logDone("images - busybox should be listed")
}
func TestCLIImageTagRemove(t *testing.T) {
imagesBefore, _, _ := cmd(t, "images", "-a")
cmd(t, "tag", "busybox", "utest:tag1")
cmd(t, "tag", "busybox", "utest/docker:tag2")
cmd(t, "tag", "busybox", "utest:5000/docker:tag3")
{
imagesAfter, _, _ := cmd(t, "images", "-a")
if nLines(imagesAfter) != nLines(imagesBefore)+3 {
t.Fatalf("before: %#s\n\nafter: %#s\n", imagesBefore, imagesAfter)
}
}
cmd(t, "rmi", "utest/docker:tag2")
{
imagesAfter, _, _ := cmd(t, "images", "-a")
if nLines(imagesAfter) != nLines(imagesBefore)+2 {
t.Fatalf("before: %#s\n\nafter: %#s\n", imagesBefore, imagesAfter)
}
}
cmd(t, "rmi", "utest:5000/docker:tag3")
{
imagesAfter, _, _ := cmd(t, "images", "-a")
if nLines(imagesAfter) != nLines(imagesBefore)+1 {
t.Fatalf("before: %#s\n\nafter: %#s\n", imagesBefore, imagesAfter)
}
}
cmd(t, "rmi", "utest:tag1")
{
imagesAfter, _, _ := cmd(t, "images", "-a")
if nLines(imagesAfter) != nLines(imagesBefore)+0 {
t.Fatalf("before: %#s\n\nafter: %#s\n", imagesBefore, imagesAfter)
}
}
logDone("tag,rmi- tagging the same images multiple times then removing tags")
}

View file

@ -4,6 +4,7 @@ import (
"fmt"
"os/exec"
"strings"
"testing"
)
func deleteContainer(container string) error {
@ -54,3 +55,9 @@ func deleteImages(images string) error {
return err
}
func cmd(t *testing.T, args ...string) (string, int, error) {
out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...))
errorOut(err, t, fmt.Sprintf("'%s' failed with errors: %v (%v)", strings.Join(args, " "), err, out))
return out, status, err
}

View file

@ -107,3 +107,7 @@ func errorOutOnNonNilError(err error, t *testing.T, message string) {
t.Fatalf(message)
}
}
func nLines(s string) int {
return strings.Count(s, "\n")
}

View file

@ -9,65 +9,6 @@ import (
"time"
)
func TestImageTagImageDelete(t *testing.T) {
eng := NewTestEngine(t)
defer mkRuntimeFromEngine(eng, t).Nuke()
srv := mkServerFromEngine(eng, t)
initialImages := getAllImages(eng, t)
if err := eng.Job("tag", unitTestImageName, "utest", "tag1").Run(); err != nil {
t.Fatal(err)
}
if err := eng.Job("tag", unitTestImageName, "utest/docker", "tag2").Run(); err != nil {
t.Fatal(err)
}
if err := eng.Job("tag", unitTestImageName, "utest:5000/docker", "tag3").Run(); err != nil {
t.Fatal(err)
}
images := getAllImages(eng, t)
nExpected := len(initialImages.Data[0].GetList("RepoTags")) + 3
nActual := len(images.Data[0].GetList("RepoTags"))
if nExpected != nActual {
t.Errorf("Expected %d images, %d found", nExpected, nActual)
}
if err := srv.DeleteImage("utest/docker:tag2", engine.NewTable("", 0), true, false, false); err != nil {
t.Fatal(err)
}
images = getAllImages(eng, t)
nExpected = len(initialImages.Data[0].GetList("RepoTags")) + 2
nActual = len(images.Data[0].GetList("RepoTags"))
if nExpected != nActual {
t.Errorf("Expected %d images, %d found", nExpected, nActual)
}
if err := srv.DeleteImage("utest:5000/docker:tag3", engine.NewTable("", 0), true, false, false); err != nil {
t.Fatal(err)
}
images = getAllImages(eng, t)
nExpected = len(initialImages.Data[0].GetList("RepoTags")) + 1
nActual = len(images.Data[0].GetList("RepoTags"))
if err := srv.DeleteImage("utest:tag1", engine.NewTable("", 0), true, false, false); err != nil {
t.Fatal(err)
}
images = getAllImages(eng, t)
if images.Len() != initialImages.Len() {
t.Errorf("Expected %d image, %d found", initialImages.Len(), images.Len())
}
}
func TestCreateRm(t *testing.T) {
eng := NewTestEngine(t)
defer mkRuntimeFromEngine(eng, t).Nuke()