From f2c9e391fc889ace2b5c2536cb1483922356c98c Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Mon, 9 Sep 2019 21:07:08 +0000 Subject: [PATCH] rm-gocheck: Matches -> cmp.Regexp sed -E -i '0,/^import "github\.com/ s/^(import "github\.com.*)/\1\nimport "gotest.tools\/assert\/cmp")/' \ -- "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_links_test.go" \ && \ sed -E -i '0,/^\t+"github\.com/ s/(^\t+"github\.com.*)/\1\n"gotest.tools\/assert\/cmp"/' \ -- "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_links_test.go" \ && \ sed -E -i 's#\bassert\.Assert\(c, (.*), checker\.Matches, (.*)\)$#assert.Assert(c, eg_matches(is.Regexp, \1, \2))#g' \ -- "integration-cli/docker_cli_images_test.go" "integration-cli/docker_api_containers_test.go" \ && \ sed -E -i 's#\bassert\.Assert\(c, (.*), checker\.Matches, (.*)\)$#assert.Assert(c, eg_matches(cmp.Regexp, \1, \2))#g' \ -- "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_links_test.go" \ && \ go get -d golang.org/x/tools/cmd/eg && dir=$(go env GOPATH)/src/golang.org/x/tools && git -C "$dir" fetch https://github.com/tiborvass/tools handle-variadic && git -C "$dir" checkout 61a94b82347c29b3289e83190aa3dda74d47abbb && go install golang.org/x/tools/cmd/eg \ && \ /bin/echo -e 'package main\nvar eg_matches func(func(cmp.RegexOrPattern, string) cmp.Comparison, interface{}, string, ...interface{}) bool' > ./integration-cli/eg_helper.go \ && \ goimports -w ./integration-cli \ && \ eg -w -t template.matches.go -- ./integration-cli \ && \ rm -f ./integration-cli/eg_helper.go \ && \ go run rm-gocheck.go redress '\bassert\.Assert\b.*(\(|,)\s*$' \ "integration-cli/docker_api_containers_test.go" "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_images_test.go" "integration-cli/docker_cli_links_test.go" Signed-off-by: Tibor Vass --- integration-cli/docker_api_containers_test.go | 16 +++++++- integration-cli/docker_cli_build_test.go | 38 ++++++++++++++++--- integration-cli/docker_cli_history_test.go | 8 +++- integration-cli/docker_cli_images_test.go | 16 +++++++- integration-cli/docker_cli_links_test.go | 9 ++++- 5 files changed, 76 insertions(+), 11 deletions(-) diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index ec5312d2b7..984f4d86c2 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -1066,7 +1066,13 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *testing.T) } b, err := request.ReadBody(body) assert.NilError(c, err) - assert.Assert(c, string(b), checker.Matches, "Path cannot be empty\n") + assert.Assert(c, is.Regexp("^"+ + + "Path cannot be empty\n"+ + "$", + + string(b))) + } func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing.T) { @@ -1087,7 +1093,13 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *testing. } b, err := request.ReadBody(body) assert.NilError(c, err) - assert.Assert(c, string(b), checker.Matches, "Could not find the file /notexist in container "+name+"\n") + assert.Assert(c, is.Regexp("^"+ + + ("Could not find the file /notexist in container "+name+"\n")+ + "$", + + string(b))) + } func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *testing.T) { diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 86dd0ee563..403268648e 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -30,6 +30,7 @@ import ( "github.com/moby/buildkit/frontend/dockerfile/command" "github.com/opencontainers/go-digest" "gotest.tools/assert" + "gotest.tools/assert/cmp" "gotest.tools/icmd" ) @@ -4803,7 +4804,12 @@ func (s *DockerSuite) TestBuildFollowSymlinkToFile(c *testing.T) { cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) out := cli.DockerCmd(c, "run", "--rm", name, "cat", "target").Combined() - assert.Assert(c, out, checker.Matches, "bar") + assert.Assert(c, cmp.Regexp("^"+ + + "bar"+ + "$", + + out)) // change target file should invalidate cache err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) @@ -4813,7 +4819,13 @@ func (s *DockerSuite) TestBuildFollowSymlinkToFile(c *testing.T) { assert.Assert(c, result.Combined(), checker.Not(checker.Contains), "Using cache") out = cli.DockerCmd(c, "run", "--rm", name, "cat", "target").Combined() - assert.Assert(c, out, checker.Matches, "baz") + assert.Assert(c, cmp.Regexp("^"+ + + "baz"+ + "$", + + out)) + } func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *testing.T) { @@ -4834,7 +4846,12 @@ func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *testing.T) { cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) out := cli.DockerCmd(c, "run", "--rm", name, "cat", "abc", "def").Combined() - assert.Assert(c, out, checker.Matches, "barbaz") + assert.Assert(c, cmp.Regexp("^"+ + + "barbaz"+ + "$", + + out)) // change target file should invalidate cache err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo/def"), []byte("bax"), 0644) @@ -4844,7 +4861,12 @@ func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *testing.T) { assert.Assert(c, result.Combined(), checker.Not(checker.Contains), "Using cache") out = cli.DockerCmd(c, "run", "--rm", name, "cat", "abc", "def").Combined() - assert.Assert(c, out, checker.Matches, "barbax") + assert.Assert(c, cmp.Regexp("^"+ + + "barbax"+ + "$", + + out)) } @@ -4867,7 +4889,13 @@ func (s *DockerSuite) TestBuildSymlinkBasename(c *testing.T) { cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) out := cli.DockerCmd(c, "run", "--rm", name, "cat", "asymlink").Combined() - assert.Assert(c, out, checker.Matches, "bar") + assert.Assert(c, cmp.Regexp("^"+ + + "bar"+ + "$", + + out)) + } // #17827 diff --git a/integration-cli/docker_cli_history_test.go b/integration-cli/docker_cli_history_test.go index dd5a9cf612..3059462d99 100644 --- a/integration-cli/docker_cli_history_test.go +++ b/integration-cli/docker_cli_history_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/integration-cli/cli/build" "github.com/go-check/check" "gotest.tools/assert" + "gotest.tools/assert/cmp" ) // This is a heisen-test. Because the created timestamp of images and the behavior of @@ -116,6 +117,11 @@ func (s *DockerSuite) TestHistoryHumanOptionTrue(c *testing.T) { endIndex = len(lines[i]) } sizeString := lines[i][startIndex:endIndex] - assert.Assert(c, strings.TrimSpace(sizeString), checker.Matches, humanSizeRegexRaw, check.Commentf("The size '%s' was not in human format", sizeString)) + assert.Assert(c, cmp.Regexp("^"+ + + humanSizeRegexRaw+ + "$", + + strings.TrimSpace(sizeString)), check.Commentf("The size '%s' was not in human format", sizeString)) } } diff --git a/integration-cli/docker_cli_images_test.go b/integration-cli/docker_cli_images_test.go index c2c97c914b..008dfba9f5 100644 --- a/integration-cli/docker_cli_images_test.go +++ b/integration-cli/docker_cli_images_test.go @@ -93,8 +93,20 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *testing.T) { out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match") out = strings.TrimSpace(out) - assert.Assert(c, out, checker.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image1ID)) - assert.Assert(c, out, checker.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image2ID)) + assert.Assert(c, is.Regexp("^"+ + + fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image1ID)+ + "$", + + out)) + + assert.Assert(c, is.Regexp("^"+ + + fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image2ID)+ + "$", + + out)) + assert.Assert(c, !is.Regexp("^"+fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image3ID)+"$", out)().Success()) out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too") diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index e29b677d69..54e457c0c2 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/runconfig" "github.com/go-check/check" "gotest.tools/assert" + "gotest.tools/assert/cmp" ) func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *testing.T) { @@ -230,7 +231,13 @@ func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *testing.T) { testRequires(c, DaemonIsLinux, NotUserNamespace) out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts") // /etc/hosts should be a regular file - assert.Assert(c, out, checker.Matches, "^-.+\n") + assert.Assert(c, cmp.Regexp("^"+ + + "^-.+\n"+ + "$", + + out)) + } func (s *DockerSuite) TestLinksMultipleWithSameName(c *testing.T) {