Explorar o código

prepare for rm-gocheck script

Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 931edfe5e95ec2428274fb87e35602537dbabf53)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Tibor Vass %!s(int64=6) %!d(string=hai) anos
pai
achega
02545bf320

+ 4 - 0
integration-cli/cli/cli.go

@@ -30,6 +30,10 @@ type testingT interface {
 	Fatalf(string, ...interface{})
 }
 
+type TestingT interface {
+	testingT
+}
+
 // DockerCmd executes the specified docker command and expect a success
 func DockerCmd(t testingT, args ...string) *icmd.Result {
 	return Docker(Args(args...)).Assert(t, icmd.Success)

+ 3 - 2
integration-cli/docker_cli_inspect_test.go

@@ -108,7 +108,8 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
 	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
 
 	out, _ := dockerCmd(c, "inspect", "--type=image", "busybox")
-	c.Assert(out, checker.Not(checker.Contains), "State") // not an image JSON
+	// not an image JSON
+	c.Assert(out, checker.Not(checker.Contains), "State")
 }
 
 func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
@@ -118,7 +119,7 @@ func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
 	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
 
 	out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
-	c.Assert(err, checker.NotNil, check.Commentf("%s", exitCode))
+	c.Assert(err, checker.NotNil, check.Commentf("%d", exitCode))
 	c.Assert(exitCode, checker.Equals, 1, check.Commentf("%s", err))
 	c.Assert(out, checker.Contains, "not a valid value for --type")
 }

+ 5 - 5
integration-cli/docker_cli_network_unix_test.go

@@ -1175,12 +1175,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectWithPortMapping(c *check.C)
 }
 
 func verifyPortMap(c *check.C, container, port, originalMapping string, mustBeEqual bool) {
-	chk := checker.Equals
-	if !mustBeEqual {
-		chk = checker.Not(checker.Equals)
-	}
 	currentMapping, _ := dockerCmd(c, "port", container, port)
-	c.Assert(currentMapping, chk, originalMapping)
+	if mustBeEqual {
+		c.Assert(currentMapping, checker.Equals, originalMapping)
+	} else {
+		c.Assert(currentMapping, checker.Not(checker.Equals), originalMapping)
+	}
 }
 
 func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectWithPortMapping(c *check.C) {

+ 2 - 2
integration-cli/docker_cli_ps_test.go

@@ -443,11 +443,11 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
 	secondZero, _ := dockerCmd(c, "run", "-d", "busybox", "true")
 
 	out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false")
-	c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
+	c.Assert(err, checker.NotNil, check.Commentf("Should fail. out: %s", out))
 	firstNonZero := getIDByName(c, "nonzero1")
 
 	out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false")
-	c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
+	c.Assert(err, checker.NotNil, check.Commentf("Should fail. out: %s", out))
 	secondNonZero := getIDByName(c, "nonzero2")
 
 	// filter containers by exited=0

+ 10 - 9
integration-cli/docker_utils_test.go

@@ -38,7 +38,7 @@ func dockerCmdWithError(args ...string) (string, int, error) {
 }
 
 // Deprecated: use cli.Docker or cli.DockerCmd
-func dockerCmd(c *check.C, args ...string) (string, int) {
+func dockerCmd(c cli.TestingT, args ...string) (string, int) {
 	result := cli.DockerCmd(c, args...)
 	return result.Combined(), result.ExitCode
 }
@@ -412,27 +412,28 @@ func getErrorMessage(c *check.C, body []byte) string {
 	return strings.TrimSpace(resp.Message)
 }
 
-func waitAndAssert(c *check.C, timeout time.Duration, f checkF, checker check.Checker, args ...interface{}) {
+func waitAndAssert(t assert.TestingT, timeout time.Duration, f checkF, comparison assert.BoolOrComparison, args ...interface{}) {
 	t1 := time.Now()
 	defer func() {
 		t2 := time.Now()
-		c.Logf("waited for %v (out of %v)", t2.Sub(t1), timeout)
+		t.(testingT).Logf("waited for %v (out of %v)", t2.Sub(t1), timeout)
 	}()
 
 	after := time.After(timeout)
 	for {
-		v, comment := f(c)
-		assert, _ := checker.Check(append([]interface{}{v}, args...), checker.Info().Params)
+		v, comment := f(t.(*check.C))
+		args = append([]interface{}{v}, args...)
+		shouldAssert := assert.Check(t, comparison, args...)
 		select {
 		case <-after:
-			assert = true
+			shouldAssert = true
 		default:
 		}
-		if assert {
+		if shouldAssert {
 			if comment != nil {
-				args = append(args, comment)
+				args = append(args, comment.CheckCommentString())
 			}
-			c.Assert(v, checker, args...)
+			assert.Assert(t, comparison, args...)
 			return
 		}
 		time.Sleep(100 * time.Millisecond)

+ 1 - 1
integration-cli/requirement/requirement.go

@@ -10,7 +10,7 @@ import (
 
 // SkipT is the interface required to skip tests
 type SkipT interface {
-	Skip(reason string)
+	Skip(...interface{})
 }
 
 // Test represent a function that can be used as a requirement validation.

+ 2 - 2
integration-cli/requirements_test.go

@@ -190,6 +190,6 @@ func TODOBuildkit() bool {
 
 // testRequires checks if the environment satisfies the requirements
 // for the test to run or skips the tests.
-func testRequires(c requirement.SkipT, requirements ...requirement.Test) {
-	requirement.Is(c, requirements...)
+func testRequires(c interface{}, requirements ...requirement.Test) {
+	requirement.Is(c.(requirement.SkipT), requirements...)
 }

+ 3 - 2
internal/test/fakegit/fakegit.go

@@ -28,7 +28,7 @@ type logT interface {
 }
 
 type skipT interface {
-	Skip(reason string)
+	Skip(...interface{})
 }
 
 type gitServer interface {
@@ -63,7 +63,8 @@ func (g *FakeGit) Close() {
 }
 
 // New create a fake git server that can be used for git related tests
-func New(c testingT, name string, files map[string]string, enforceLocalServer bool) *FakeGit {
+func New(cc interface{}, name string, files map[string]string, enforceLocalServer bool) *FakeGit {
+	c := cc.(testingT)
 	if ht, ok := c.(test.HelperT); ok {
 		ht.Helper()
 	}

+ 3 - 2
internal/test/fakestorage/storage.go

@@ -38,7 +38,7 @@ type logT interface {
 }
 
 type skipT interface {
-	Skip(reason string)
+	Skip(...interface{})
 }
 
 // Fake is a static file server. It might be running locally or remotely
@@ -56,7 +56,8 @@ func SetTestEnvironment(env *environment.Execution) {
 }
 
 // New returns a static file server that will be use as build context.
-func New(t testingT, dir string, modifiers ...func(*fakecontext.Fake) error) Fake {
+func New(tt interface{}, dir string, modifiers ...func(*fakecontext.Fake) error) Fake {
+	t := tt.(testingT)
 	if ht, ok := t.(test.HelperT); ok {
 		ht.Helper()
 	}

+ 3 - 6
pkg/discovery/discovery_test.go

@@ -85,23 +85,20 @@ func (s *DiscoverySuite) TestEntriesEquality(c *check.C) {
 	c.Assert(entries.Equals(Entries{
 		&Entry{Host: "127.0.0.1", Port: "2375"},
 		&Entry{Host: "127.0.0.2", Port: "2375"},
-	}), check.
-		Equals, true)
+	}), check.Equals, true)
 
 	// Different size
 	c.Assert(entries.Equals(Entries{
 		&Entry{Host: "127.0.0.1", Port: "2375"},
 		&Entry{Host: "127.0.0.2", Port: "2375"},
 		&Entry{Host: "127.0.0.3", Port: "2375"},
-	}), check.
-		Equals, false)
+	}), check.Equals, false)
 
 	// Different content
 	c.Assert(entries.Equals(Entries{
 		&Entry{Host: "127.0.0.1", Port: "2375"},
 		&Entry{Host: "127.0.0.42", Port: "2375"},
-	}), check.
-		Equals, false)
+	}), check.Equals, false)
 
 }