mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <tibor@docker.com>
This commit is contained in:
parent
59e55dcdd0
commit
f2c9e391fc
5 changed files with 76 additions and 11 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue