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

prepare for rm-gocheck script

Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 931edfe5e9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Tibor Vass 2019-08-09 06:57:11 +00:00 committed by Sebastiaan van Stijn
parent e71e7d8246
commit 02545bf320
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
10 changed files with 36 additions and 31 deletions

View file

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

View file

@ -108,7 +108,8 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
out, _ := dockerCmd(c, "inspect", "--type=image", "busybox") 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) { 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") dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox") 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(exitCode, checker.Equals, 1, check.Commentf("%s", err))
c.Assert(out, checker.Contains, "not a valid value for --type") c.Assert(out, checker.Contains, "not a valid value for --type")
} }

View file

@ -1175,12 +1175,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectWithPortMapping(c *check.C)
} }
func verifyPortMap(c *check.C, container, port, originalMapping string, mustBeEqual bool) { 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) 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) { func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectWithPortMapping(c *check.C) {

View file

@ -443,11 +443,11 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
secondZero, _ := dockerCmd(c, "run", "-d", "busybox", "true") secondZero, _ := dockerCmd(c, "run", "-d", "busybox", "true")
out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false") 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") firstNonZero := getIDByName(c, "nonzero1")
out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false") 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") secondNonZero := getIDByName(c, "nonzero2")
// filter containers by exited=0 // filter containers by exited=0

View file

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

View file

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

View file

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

View file

@ -28,7 +28,7 @@ type logT interface {
} }
type skipT interface { type skipT interface {
Skip(reason string) Skip(...interface{})
} }
type gitServer 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 // 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 { if ht, ok := c.(test.HelperT); ok {
ht.Helper() ht.Helper()
} }

View file

@ -38,7 +38,7 @@ type logT interface {
} }
type skipT interface { type skipT interface {
Skip(reason string) Skip(...interface{})
} }
// Fake is a static file server. It might be running locally or remotely // 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. // 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 { if ht, ok := t.(test.HelperT); ok {
ht.Helper() ht.Helper()
} }

View file

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