integration-cli: DockerCLIHistorySuite: replace dockerCmd

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-28 10:24:40 +02:00
parent 268e72f10f
commit 6ce6b63482
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -8,6 +8,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
@ -28,7 +29,7 @@ func (s *DockerCLIHistorySuite) OnTimeout(c *testing.T) {
// This is a heisen-test. Because the created timestamp of images and the behavior of
// sort is not predictable it doesn't always fail.
func (s *DockerCLIHistorySuite) TestBuildHistory(c *testing.T) {
name := "testbuildhistory"
const name = "testbuildhistory"
buildImageSuccessfully(c, name, build.WithDockerfile(`FROM `+minimalBaseImage()+`
LABEL label.A="A"
LABEL label.B="B"
@ -57,7 +58,7 @@ LABEL label.X="X"
LABEL label.Y="Y"
LABEL label.Z="Z"`))
out, _ := dockerCmd(c, "history", name)
out := cli.DockerCmd(c, "history", name).Combined()
actualValues := strings.Split(out, "\n")[1:27]
expectedValues := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"}
@ -69,7 +70,7 @@ LABEL label.Z="Z"`))
}
func (s *DockerCLIHistorySuite) TestHistoryExistentImage(c *testing.T) {
dockerCmd(c, "history", "busybox")
cli.DockerCmd(c, "history", "busybox")
}
func (s *DockerCLIHistorySuite) TestHistoryNonExistentImage(c *testing.T) {
@ -78,26 +79,24 @@ func (s *DockerCLIHistorySuite) TestHistoryNonExistentImage(c *testing.T) {
}
func (s *DockerCLIHistorySuite) TestHistoryImageWithComment(c *testing.T) {
name := "testhistoryimagewithcomment"
const name = "testhistoryimagewithcomment"
// make an image through docker commit <container id> [ -m messages ]
cli.DockerCmd(c, "run", "--name", name, "busybox", "true")
cli.DockerCmd(c, "wait", name)
dockerCmd(c, "run", "--name", name, "busybox", "true")
dockerCmd(c, "wait", name)
comment := "This_is_a_comment"
dockerCmd(c, "commit", "-m="+comment, name, name)
const comment = "This_is_a_comment"
cli.DockerCmd(c, "commit", "-m="+comment, name, name)
// test docker history <image id> to check comment messages
out, _ := dockerCmd(c, "history", name)
out := cli.DockerCmd(c, "history", name).Combined()
outputTabs := strings.Fields(strings.Split(out, "\n")[1])
actualValue := outputTabs[len(outputTabs)-1]
assert.Assert(c, strings.Contains(actualValue, comment))
}
func (s *DockerCLIHistorySuite) TestHistoryHumanOptionFalse(c *testing.T) {
out, _ := dockerCmd(c, "history", "--human=false", "busybox")
out := cli.DockerCmd(c, "history", "--human=false", "busybox").Combined()
lines := strings.Split(out, "\n")
sizeColumnRegex, _ := regexp.Compile("SIZE +")
indices := sizeColumnRegex.FindStringIndex(lines[0])
@ -115,7 +114,7 @@ func (s *DockerCLIHistorySuite) TestHistoryHumanOptionFalse(c *testing.T) {
}
func (s *DockerCLIHistorySuite) TestHistoryHumanOptionTrue(c *testing.T) {
out, _ := dockerCmd(c, "history", "--human=true", "busybox")
out := cli.DockerCmd(c, "history", "--human=true", "busybox").Combined()
lines := strings.Split(out, "\n")
sizeColumnRegex, _ := regexp.Compile("SIZE +")
humanSizeRegexRaw := "\\d+.*B" // Matches human sizes like 10 MB, 3.2 KB, etc