mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Replace some checkers and assertions with gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -13,7 +13,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakegit"
|
||||
"github.com/docker/docker/internal/test/fakestorage"
|
||||
@ -41,17 +40,17 @@ RUN find /tmp/`
|
||||
defer server.Close()
|
||||
|
||||
res, body, err := request.Post("/build?dockerfile=baz&remote="+server.URL()+"/testD", request.JSON)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
buf, err := request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
// Make sure Dockerfile exists.
|
||||
// Make sure 'baz' doesn't exist ANYWHERE despite being mentioned in the URL
|
||||
out := string(buf)
|
||||
c.Assert(out, checker.Contains, "RUN find /tmp")
|
||||
c.Assert(out, checker.Not(checker.Contains), "baz")
|
||||
assert.Assert(c, is.Contains(out, "RUN find /tmp"))
|
||||
assert.Assert(c, !strings.Contains(out, "baz"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
||||
@ -64,15 +63,11 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
||||
Name: "Dockerfile",
|
||||
Size: int64(len(dockerfile)),
|
||||
})
|
||||
// failed to write tar file header
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err, "failed to write tar file header")
|
||||
|
||||
_, err = tw.Write(dockerfile)
|
||||
// failed to write tar file content
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// failed to close tar archive
|
||||
c.Assert(tw.Close(), checker.IsNil)
|
||||
assert.NilError(c, err, "failed to write tar file content")
|
||||
assert.NilError(c, tw.Close(), "failed to close tar archive")
|
||||
|
||||
server := fakestorage.New(c, "", fakecontext.WithBinaryFiles(map[string]*bytes.Buffer{
|
||||
"testT.tar": buffer,
|
||||
@ -80,8 +75,8 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
||||
defer server.Close()
|
||||
|
||||
res, b, err := request.Post("/build?remote="+server.URL()+"/testT.tar", request.ContentType("application/tar"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
b.Close()
|
||||
}
|
||||
|
||||
@ -97,11 +92,11 @@ RUN echo 'wrong'`)
|
||||
Size: int64(len(dockerfile)),
|
||||
})
|
||||
// failed to write tar file header
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
_, err = tw.Write(dockerfile)
|
||||
// failed to write tar file content
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
custom := []byte(`FROM busybox
|
||||
RUN echo 'right'
|
||||
@ -112,14 +107,14 @@ RUN echo 'right'
|
||||
})
|
||||
|
||||
// failed to write tar file header
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
_, err = tw.Write(custom)
|
||||
// failed to write tar file content
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
// failed to close tar archive
|
||||
c.Assert(tw.Close(), checker.IsNil)
|
||||
assert.NilError(c, tw.Close())
|
||||
|
||||
server := fakestorage.New(c, "", fakecontext.WithBinaryFiles(map[string]*bytes.Buffer{
|
||||
"testT.tar": buffer,
|
||||
@ -128,15 +123,15 @@ RUN echo 'right'
|
||||
|
||||
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar"
|
||||
res, body, err := request.Post(url, request.ContentType("application/tar"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
defer body.Close()
|
||||
content, err := request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
// Build used the wrong dockerfile.
|
||||
c.Assert(string(content), checker.Not(checker.Contains), "wrong")
|
||||
assert.Assert(c, !strings.Contains(string(content), "wrong"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPILowerDockerfile(c *check.C) {
|
||||
@ -147,14 +142,14 @@ RUN echo from dockerfile`,
|
||||
defer git.Close()
|
||||
|
||||
res, body, err := request.Post("/build?remote="+git.RepoURL, request.JSON)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
buf, err := request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out := string(buf)
|
||||
c.Assert(out, checker.Contains, "from dockerfile")
|
||||
assert.Assert(c, is.Contains(out, "from dockerfile"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *check.C) {
|
||||
@ -168,14 +163,14 @@ RUN echo from Dockerfile`,
|
||||
|
||||
// Make sure it tries to 'dockerfile' query param value
|
||||
res, body, err := request.Post("/build?dockerfile=baz&remote="+git.RepoURL, request.JSON)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
buf, err := request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out := string(buf)
|
||||
c.Assert(out, checker.Contains, "from baz")
|
||||
assert.Assert(c, is.Contains(out, "from baz"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *check.C) {
|
||||
@ -190,14 +185,14 @@ RUN echo from dockerfile`,
|
||||
|
||||
// Make sure it tries to 'dockerfile' query param value
|
||||
res, body, err := request.Post("/build?remote="+git.RepoURL, request.JSON)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
buf, err := request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
out := string(buf)
|
||||
c.Assert(out, checker.Contains, "from Dockerfile")
|
||||
assert.Assert(c, is.Contains(out, "from Dockerfile"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
|
||||
@ -216,35 +211,37 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
|
||||
Size: int64(len(dockerfile)),
|
||||
})
|
||||
//failed to write tar file header
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
_, err = tw.Write(dockerfile)
|
||||
// failed to write Dockerfile in tar file content
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
err = tw.WriteHeader(&tar.Header{
|
||||
Name: "dir/./file",
|
||||
Size: int64(len(fileContents)),
|
||||
})
|
||||
//failed to write tar file header
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
_, err = tw.Write(fileContents)
|
||||
// failed to write file contents in tar file content
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
|
||||
// failed to close tar archive
|
||||
c.Assert(tw.Close(), checker.IsNil)
|
||||
assert.NilError(c, tw.Close())
|
||||
|
||||
res, body, err := request.Post("/build", request.RawContent(ioutil.NopCloser(buffer)), request.ContentType("application/x-tar"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
assert.NilError(c, err)
|
||||
lines := strings.Split(string(out), "\n")
|
||||
c.Assert(len(lines), checker.GreaterThan, 1)
|
||||
c.Assert(lines[len(lines)-2], checker.Matches, ".*Successfully built [0-9a-f]{12}.*")
|
||||
assert.Assert(c, len(lines) > 1)
|
||||
matched, err := regexp.MatchString(".*Successfully built [0-9a-f]{12}.*", lines[len(lines)-2])
|
||||
assert.NilError(c, err)
|
||||
assert.Assert(c, matched)
|
||||
|
||||
re := regexp.MustCompile("Successfully built ([0-9a-f]{12})")
|
||||
matches := re.FindStringSubmatch(lines[len(lines)-2])
|
||||
@ -254,7 +251,7 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
|
||||
imageA := buildFromTarContext([]byte("abc"))
|
||||
imageB := buildFromTarContext([]byte("def"))
|
||||
|
||||
c.Assert(imageA, checker.Not(checker.Equals), imageB)
|
||||
assert.Assert(c, imageA != imageB)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildOnBuildWithCopy(c *check.C) {
|
||||
@ -274,12 +271,12 @@ func (s *DockerSuite) TestBuildOnBuildWithCopy(c *check.C) {
|
||||
"/build",
|
||||
request.RawContent(ctx.AsTarReader(c)),
|
||||
request.ContentType("application/x-tar"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(string(out), checker.Contains, "Successfully built")
|
||||
assert.NilError(c, err)
|
||||
assert.Assert(c, is.Contains(string(out), "Successfully built"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
|
||||
@ -427,8 +424,8 @@ func (s *DockerSuite) TestBuildChownOnCopy(c *check.C) {
|
||||
"/build",
|
||||
request.RawContent(ctx.AsTarReader(c)),
|
||||
request.ContentType("application/x-tar"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
assert.NilError(c, err)
|
||||
@ -531,8 +528,8 @@ ENV foo bar`
|
||||
"/build",
|
||||
request.RawContent(ctx.AsTarReader(c)),
|
||||
request.ContentType("application/x-tar"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||
assert.NilError(c, err)
|
||||
assert.Equal(c, res.StatusCode, http.StatusOK)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
assert.NilError(c, err)
|
||||
|
Reference in New Issue
Block a user