diff --git a/integration-cli/cli/cli.go b/integration-cli/cli/cli.go index bc3f3c194e..6d38c8ba80 100644 --- a/integration-cli/cli/cli.go +++ b/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) diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index 620272f65f..22bf5ffd48 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/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") } diff --git a/integration-cli/docker_cli_network_unix_test.go b/integration-cli/docker_cli_network_unix_test.go index 1857cf603d..ba525dd50c 100644 --- a/integration-cli/docker_cli_network_unix_test.go +++ b/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) { diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index cab75f4696..29eb2ea912 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/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 diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index a95246f141..8c53b38a05 100644 --- a/integration-cli/docker_utils_test.go +++ b/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) diff --git a/integration-cli/requirement/requirement.go b/integration-cli/requirement/requirement.go index 45a1bcabfd..e05dffb4bf 100644 --- a/integration-cli/requirement/requirement.go +++ b/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. diff --git a/integration-cli/requirements_test.go b/integration-cli/requirements_test.go index fd3f4efaad..658b5581c6 100644 --- a/integration-cli/requirements_test.go +++ b/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...) } diff --git a/internal/test/fakegit/fakegit.go b/internal/test/fakegit/fakegit.go index 605d1baaa8..6062e0988b 100644 --- a/internal/test/fakegit/fakegit.go +++ b/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() } diff --git a/internal/test/fakestorage/storage.go b/internal/test/fakestorage/storage.go index 77d6e2fcb9..03bd09cdf0 100644 --- a/internal/test/fakestorage/storage.go +++ b/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() } diff --git a/pkg/discovery/discovery_test.go b/pkg/discovery/discovery_test.go index ffe8cb9122..3558bbda44 100644 --- a/pkg/discovery/discovery_test.go +++ b/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) }