Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 931edfe5e95ec2428274fb87e35602537dbabf53)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -30,6 +30,10 @@ type testingT interface {
|
| 30 | 30 |
Fatalf(string, ...interface{})
|
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 |
+type TestingT interface {
|
|
| 34 |
+ testingT |
|
| 35 |
+} |
|
| 36 |
+ |
|
| 33 | 37 |
// DockerCmd executes the specified docker command and expect a success |
| 34 | 38 |
func DockerCmd(t testingT, args ...string) *icmd.Result {
|
| 35 | 39 |
return Docker(Args(args...)).Assert(t, icmd.Success) |
| ... | ... |
@@ -108,7 +108,8 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
|
| 108 | 108 |
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") |
| 109 | 109 |
|
| 110 | 110 |
out, _ := dockerCmd(c, "inspect", "--type=image", "busybox") |
| 111 |
- c.Assert(out, checker.Not(checker.Contains), "State") // not an image JSON |
|
| 111 |
+ // not an image JSON |
|
| 112 |
+ c.Assert(out, checker.Not(checker.Contains), "State") |
|
| 112 | 113 |
} |
| 113 | 114 |
|
| 114 | 115 |
func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
|
| ... | ... |
@@ -118,7 +119,7 @@ func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
|
| 118 | 118 |
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") |
| 119 | 119 |
|
| 120 | 120 |
out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
|
| 121 |
- c.Assert(err, checker.NotNil, check.Commentf("%s", exitCode))
|
|
| 121 |
+ c.Assert(err, checker.NotNil, check.Commentf("%d", exitCode))
|
|
| 122 | 122 |
c.Assert(exitCode, checker.Equals, 1, check.Commentf("%s", err))
|
| 123 | 123 |
c.Assert(out, checker.Contains, "not a valid value for --type") |
| 124 | 124 |
} |
| ... | ... |
@@ -1175,12 +1175,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectWithPortMapping(c *check.C) |
| 1175 | 1175 |
} |
| 1176 | 1176 |
|
| 1177 | 1177 |
func verifyPortMap(c *check.C, container, port, originalMapping string, mustBeEqual bool) {
|
| 1178 |
- chk := checker.Equals |
|
| 1179 |
- if !mustBeEqual {
|
|
| 1180 |
- chk = checker.Not(checker.Equals) |
|
| 1181 |
- } |
|
| 1182 | 1178 |
currentMapping, _ := dockerCmd(c, "port", container, port) |
| 1183 |
- c.Assert(currentMapping, chk, originalMapping) |
|
| 1179 |
+ if mustBeEqual {
|
|
| 1180 |
+ c.Assert(currentMapping, checker.Equals, originalMapping) |
|
| 1181 |
+ } else {
|
|
| 1182 |
+ c.Assert(currentMapping, checker.Not(checker.Equals), originalMapping) |
|
| 1183 |
+ } |
|
| 1184 | 1184 |
} |
| 1185 | 1185 |
|
| 1186 | 1186 |
func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectWithPortMapping(c *check.C) {
|
| ... | ... |
@@ -443,11 +443,11 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
| 443 | 443 |
secondZero, _ := dockerCmd(c, "run", "-d", "busybox", "true") |
| 444 | 444 |
|
| 445 | 445 |
out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false")
|
| 446 |
- c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
|
|
| 446 |
+ c.Assert(err, checker.NotNil, check.Commentf("Should fail. out: %s", out))
|
|
| 447 | 447 |
firstNonZero := getIDByName(c, "nonzero1") |
| 448 | 448 |
|
| 449 | 449 |
out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false")
|
| 450 |
- c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
|
|
| 450 |
+ c.Assert(err, checker.NotNil, check.Commentf("Should fail. out: %s", out))
|
|
| 451 | 451 |
secondNonZero := getIDByName(c, "nonzero2") |
| 452 | 452 |
|
| 453 | 453 |
// filter containers by exited=0 |
| ... | ... |
@@ -38,7 +38,7 @@ func dockerCmdWithError(args ...string) (string, int, error) {
|
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
// Deprecated: use cli.Docker or cli.DockerCmd |
| 41 |
-func dockerCmd(c *check.C, args ...string) (string, int) {
|
|
| 41 |
+func dockerCmd(c cli.TestingT, args ...string) (string, int) {
|
|
| 42 | 42 |
result := cli.DockerCmd(c, args...) |
| 43 | 43 |
return result.Combined(), result.ExitCode |
| 44 | 44 |
} |
| ... | ... |
@@ -412,27 +412,28 @@ func getErrorMessage(c *check.C, body []byte) string {
|
| 412 | 412 |
return strings.TrimSpace(resp.Message) |
| 413 | 413 |
} |
| 414 | 414 |
|
| 415 |
-func waitAndAssert(c *check.C, timeout time.Duration, f checkF, checker check.Checker, args ...interface{}) {
|
|
| 415 |
+func waitAndAssert(t assert.TestingT, timeout time.Duration, f checkF, comparison assert.BoolOrComparison, args ...interface{}) {
|
|
| 416 | 416 |
t1 := time.Now() |
| 417 | 417 |
defer func() {
|
| 418 | 418 |
t2 := time.Now() |
| 419 |
- c.Logf("waited for %v (out of %v)", t2.Sub(t1), timeout)
|
|
| 419 |
+ t.(testingT).Logf("waited for %v (out of %v)", t2.Sub(t1), timeout)
|
|
| 420 | 420 |
}() |
| 421 | 421 |
|
| 422 | 422 |
after := time.After(timeout) |
| 423 | 423 |
for {
|
| 424 |
- v, comment := f(c) |
|
| 425 |
- assert, _ := checker.Check(append([]interface{}{v}, args...), checker.Info().Params)
|
|
| 424 |
+ v, comment := f(t.(*check.C)) |
|
| 425 |
+ args = append([]interface{}{v}, args...)
|
|
| 426 |
+ shouldAssert := assert.Check(t, comparison, args...) |
|
| 426 | 427 |
select {
|
| 427 | 428 |
case <-after: |
| 428 |
- assert = true |
|
| 429 |
+ shouldAssert = true |
|
| 429 | 430 |
default: |
| 430 | 431 |
} |
| 431 |
- if assert {
|
|
| 432 |
+ if shouldAssert {
|
|
| 432 | 433 |
if comment != nil {
|
| 433 |
- args = append(args, comment) |
|
| 434 |
+ args = append(args, comment.CheckCommentString()) |
|
| 434 | 435 |
} |
| 435 |
- c.Assert(v, checker, args...) |
|
| 436 |
+ assert.Assert(t, comparison, args...) |
|
| 436 | 437 |
return |
| 437 | 438 |
} |
| 438 | 439 |
time.Sleep(100 * time.Millisecond) |
| ... | ... |
@@ -190,6 +190,6 @@ func TODOBuildkit() bool {
|
| 190 | 190 |
|
| 191 | 191 |
// testRequires checks if the environment satisfies the requirements |
| 192 | 192 |
// for the test to run or skips the tests. |
| 193 |
-func testRequires(c requirement.SkipT, requirements ...requirement.Test) {
|
|
| 194 |
- requirement.Is(c, requirements...) |
|
| 193 |
+func testRequires(c interface{}, requirements ...requirement.Test) {
|
|
| 194 |
+ requirement.Is(c.(requirement.SkipT), requirements...) |
|
| 195 | 195 |
} |
| ... | ... |
@@ -28,7 +28,7 @@ type logT interface {
|
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
type skipT interface {
|
| 31 |
- Skip(reason string) |
|
| 31 |
+ Skip(...interface{})
|
|
| 32 | 32 |
} |
| 33 | 33 |
|
| 34 | 34 |
type gitServer interface {
|
| ... | ... |
@@ -63,7 +63,8 @@ func (g *FakeGit) Close() {
|
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 | 65 |
// New create a fake git server that can be used for git related tests |
| 66 |
-func New(c testingT, name string, files map[string]string, enforceLocalServer bool) *FakeGit {
|
|
| 66 |
+func New(cc interface{}, name string, files map[string]string, enforceLocalServer bool) *FakeGit {
|
|
| 67 |
+ c := cc.(testingT) |
|
| 67 | 68 |
if ht, ok := c.(test.HelperT); ok {
|
| 68 | 69 |
ht.Helper() |
| 69 | 70 |
} |
| ... | ... |
@@ -38,7 +38,7 @@ type logT interface {
|
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
type skipT interface {
|
| 41 |
- Skip(reason string) |
|
| 41 |
+ Skip(...interface{})
|
|
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 | 44 |
// Fake is a static file server. It might be running locally or remotely |
| ... | ... |
@@ -56,7 +56,8 @@ func SetTestEnvironment(env *environment.Execution) {
|
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 | 58 |
// New returns a static file server that will be use as build context. |
| 59 |
-func New(t testingT, dir string, modifiers ...func(*fakecontext.Fake) error) Fake {
|
|
| 59 |
+func New(tt interface{}, dir string, modifiers ...func(*fakecontext.Fake) error) Fake {
|
|
| 60 |
+ t := tt.(testingT) |
|
| 60 | 61 |
if ht, ok := t.(test.HelperT); ok {
|
| 61 | 62 |
ht.Helper() |
| 62 | 63 |
} |
| ... | ... |
@@ -85,23 +85,20 @@ func (s *DiscoverySuite) TestEntriesEquality(c *check.C) {
|
| 85 | 85 |
c.Assert(entries.Equals(Entries{
|
| 86 | 86 |
&Entry{Host: "127.0.0.1", Port: "2375"},
|
| 87 | 87 |
&Entry{Host: "127.0.0.2", Port: "2375"},
|
| 88 |
- }), check. |
|
| 89 |
- Equals, true) |
|
| 88 |
+ }), check.Equals, true) |
|
| 90 | 89 |
|
| 91 | 90 |
// Different size |
| 92 | 91 |
c.Assert(entries.Equals(Entries{
|
| 93 | 92 |
&Entry{Host: "127.0.0.1", Port: "2375"},
|
| 94 | 93 |
&Entry{Host: "127.0.0.2", Port: "2375"},
|
| 95 | 94 |
&Entry{Host: "127.0.0.3", Port: "2375"},
|
| 96 |
- }), check. |
|
| 97 |
- Equals, false) |
|
| 95 |
+ }), check.Equals, false) |
|
| 98 | 96 |
|
| 99 | 97 |
// Different content |
| 100 | 98 |
c.Assert(entries.Equals(Entries{
|
| 101 | 99 |
&Entry{Host: "127.0.0.1", Port: "2375"},
|
| 102 | 100 |
&Entry{Host: "127.0.0.42", Port: "2375"},
|
| 103 |
- }), check. |
|
| 104 |
- Equals, false) |
|
| 101 |
+ }), check.Equals, false) |
|
| 105 | 102 |
|
| 106 | 103 |
} |
| 107 | 104 |
|