Просмотр исходного кода

Merge pull request #16846 from HuKeping/master

Use checkers on Integration test when possible
Vincent Demeester 9 лет назад
Родитель
Сommit
d46fff7d8f
2 измененных файлов с 25 добавлено и 44 удалено
  1. 17 21
      integration-cli/docker_cli_tag_test.go
  2. 8 23
      integration-cli/docker_cli_top_test.go

+ 17 - 21
integration-cli/docker_cli_tag_test.go

@@ -3,6 +3,7 @@ package main
 import (
 import (
 	"strings"
 	"strings"
 
 
+	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/docker/docker/pkg/stringutils"
 	"github.com/docker/docker/pkg/stringutils"
 	"github.com/go-check/check"
 	"github.com/go-check/check"
 )
 )
@@ -27,14 +28,11 @@ func (s *DockerSuite) TestTagUnprefixedRepoByID(c *check.C) {
 
 
 // ensure we don't allow the use of invalid repository names; these tag operations should fail
 // ensure we don't allow the use of invalid repository names; these tag operations should fail
 func (s *DockerSuite) TestTagInvalidUnprefixedRepo(c *check.C) {
 func (s *DockerSuite) TestTagInvalidUnprefixedRepo(c *check.C) {
-
 	invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd"}
 	invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd"}
 
 
 	for _, repo := range invalidRepos {
 	for _, repo := range invalidRepos {
-		_, _, err := dockerCmdWithError("tag", "busybox", repo)
-		if err == nil {
-			c.Fatalf("tag busybox %v should have failed", repo)
-		}
+		out, _, err := dockerCmdWithError("tag", "busybox", repo)
+		c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repo, out))
 	}
 	}
 }
 }
 
 
@@ -45,10 +43,8 @@ func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) {
 	invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}
 	invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}
 
 
 	for _, repotag := range invalidTags {
 	for _, repotag := range invalidTags {
-		_, _, err := dockerCmdWithError("tag", "busybox", repotag)
-		if err == nil {
-			c.Fatalf("tag busybox %v should have failed", repotag)
-		}
+		out, _, err := dockerCmdWithError("tag", "busybox", repotag)
+		c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repotag, out))
 	}
 	}
 }
 }
 
 
@@ -80,9 +76,9 @@ func (s *DockerSuite) TestTagExistedNameWithoutForce(c *check.C) {
 
 
 	dockerCmd(c, "tag", "busybox:latest", "busybox:test")
 	dockerCmd(c, "tag", "busybox:latest", "busybox:test")
 	out, _, err := dockerCmdWithError("tag", "busybox:latest", "busybox:test")
 	out, _, err := dockerCmdWithError("tag", "busybox:latest", "busybox:test")
-	if err == nil || !strings.Contains(out, "Conflict: Tag busybox:test is already set to image") {
-		c.Fatal("tag busybox busybox:test should have failed,because busybox:test is existed")
-	}
+
+	c.Assert(err, checker.NotNil, check.Commentf(out))
+	c.Assert(out, checker.Contains, "Conflict: Tag busybox:test is already set to image", check.Commentf("tag busybox busybox:test should have failed,because busybox:test is existed"))
 }
 }
 
 
 // tag an image with an existed tag name with -f option should work
 // tag an image with an existed tag name with -f option should work
@@ -101,21 +97,21 @@ func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) {
 	if err := pullImageIfNotExist("busybox:latest"); err != nil {
 	if err := pullImageIfNotExist("busybox:latest"); err != nil {
 		c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
 		c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
 	}
 	}
+
 	// test repository name begin with '-'
 	// test repository name begin with '-'
 	out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test")
 	out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test")
-	if err == nil || !strings.Contains(out, "repository name component must match") {
-		c.Fatal("tag a name begin with '-' should failed")
-	}
+	c.Assert(err, checker.NotNil, check.Commentf(out))
+	c.Assert(out, checker.Contains, "repository name component must match", check.Commentf("tag a name begin with '-' should failed"))
+
 	// test namespace name begin with '-'
 	// test namespace name begin with '-'
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test")
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test")
-	if err == nil || !strings.Contains(out, "repository name component must match") {
-		c.Fatal("tag a name begin with '-' should failed")
-	}
+	c.Assert(err, checker.NotNil, check.Commentf(out))
+	c.Assert(out, checker.Contains, "repository name component must match", check.Commentf("tag a name begin with '-' should failed"))
+
 	// test index name begin with '-'
 	// test index name begin with '-'
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test")
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test")
-	if err == nil || !strings.Contains(out, "Invalid index name (-index:5000). Cannot begin or end with a hyphen") {
-		c.Fatal("tag a name begin with '-' should failed")
-	}
+	c.Assert(err, checker.NotNil, check.Commentf(out))
+	c.Assert(out, checker.Contains, "Invalid index name (-index:5000). Cannot begin or end with a hyphen", check.Commentf("tag a name begin with '-' should failed"))
 }
 }
 
 
 // ensure tagging using official names works
 // ensure tagging using official names works

+ 8 - 23
integration-cli/docker_cli_top_test.go

@@ -3,20 +3,17 @@ package main
 import (
 import (
 	"strings"
 	"strings"
 
 
+	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/go-check/check"
 	"github.com/go-check/check"
 )
 )
 
 
 func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
 func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
 	out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
 	out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
-
 	cleanedContainerID := strings.TrimSpace(out)
 	cleanedContainerID := strings.TrimSpace(out)
 
 
 	out, _ = dockerCmd(c, "top", cleanedContainerID, "-o", "pid")
 	out, _ = dockerCmd(c, "top", cleanedContainerID, "-o", "pid")
-	if !strings.Contains(out, "PID") {
-		c.Fatalf("did not see PID after top -o pid: %s", out)
-	}
-
+	c.Assert(out, checker.Contains, "PID", check.Commentf("did not see PID after top -o pid: %s", out))
 }
 }
 
 
 func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
 func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
@@ -26,16 +23,10 @@ func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
 
 
 	out1, _ := dockerCmd(c, "top", cleanedContainerID)
 	out1, _ := dockerCmd(c, "top", cleanedContainerID)
 	out2, _ := dockerCmd(c, "top", cleanedContainerID)
 	out2, _ := dockerCmd(c, "top", cleanedContainerID)
-	out, _ = dockerCmd(c, "kill", cleanedContainerID)
-
-	if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
-		c.Fatal("top should've listed `top` in the process list, but failed twice")
-	} else if !strings.Contains(out1, "top") {
-		c.Fatal("top should've listed `top` in the process list, but failed the first time")
-	} else if !strings.Contains(out2, "top") {
-		c.Fatal("top should've listed `top` in the process list, but failed the second itime")
-	}
+	dockerCmd(c, "kill", cleanedContainerID)
 
 
+	c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time"))
+	c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time"))
 }
 }
 
 
 func (s *DockerSuite) TestTopPrivileged(c *check.C) {
 func (s *DockerSuite) TestTopPrivileged(c *check.C) {
@@ -45,14 +36,8 @@ func (s *DockerSuite) TestTopPrivileged(c *check.C) {
 
 
 	out1, _ := dockerCmd(c, "top", cleanedContainerID)
 	out1, _ := dockerCmd(c, "top", cleanedContainerID)
 	out2, _ := dockerCmd(c, "top", cleanedContainerID)
 	out2, _ := dockerCmd(c, "top", cleanedContainerID)
-	out, _ = dockerCmd(c, "kill", cleanedContainerID)
-
-	if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
-		c.Fatal("top should've listed `top` in the process list, but failed twice")
-	} else if !strings.Contains(out1, "top") {
-		c.Fatal("top should've listed `top` in the process list, but failed the first time")
-	} else if !strings.Contains(out2, "top") {
-		c.Fatal("top should've listed `top` in the process list, but failed the second itime")
-	}
+	dockerCmd(c, "kill", cleanedContainerID)
 
 
+	c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time"))
+	c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time"))
 }
 }