Skip to content

Commit

Permalink
integration-cli: DockerCLIInfoSuite: replace dockerCmd and waitRun
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Oct 19, 2023
1 parent 4562f07 commit ba32beb
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions integration-cli/docker_cli_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"testing"

"github.com/docker/docker/integration-cli/cli"
"gotest.tools/v3/assert"
)

Expand All @@ -24,7 +25,7 @@ func (s *DockerCLIInfoSuite) OnTimeout(c *testing.T) {

// ensure docker info succeeds
func (s *DockerCLIInfoSuite) TestInfoEnsureSucceeds(c *testing.T) {
out, _ := dockerCmd(c, "info")
out := cli.DockerCmd(c, "info").Stdout()

// always shown fields
stringsToCheck := []string{
Expand Down Expand Up @@ -71,8 +72,8 @@ func (s *DockerCLIInfoSuite) TestInfoDisplaysRunningContainers(c *testing.T) {

existing := existingContainerStates(c)

dockerCmd(c, "run", "-d", "busybox", "top")
out, _ := dockerCmd(c, "info")
cli.DockerCmd(c, "run", "-d", "busybox", "top")
out := cli.DockerCmd(c, "info").Stdout()
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]+1)))
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"])))
Expand All @@ -84,12 +85,11 @@ func (s *DockerCLIInfoSuite) TestInfoDisplaysPausedContainers(c *testing.T) {

existing := existingContainerStates(c)

out := runSleepingContainer(c, "-d")
cleanedContainerID := strings.TrimSpace(out)
id := runSleepingContainer(c, "-d")

dockerCmd(c, "pause", cleanedContainerID)
cli.DockerCmd(c, "pause", id)

out, _ = dockerCmd(c, "info")
out := cli.DockerCmd(c, "info").Stdout()
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"])))
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]+1)))
Expand All @@ -101,20 +101,20 @@ func (s *DockerCLIInfoSuite) TestInfoDisplaysStoppedContainers(c *testing.T) {

existing := existingContainerStates(c)

out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout()
cleanedContainerID := strings.TrimSpace(out)

dockerCmd(c, "stop", cleanedContainerID)
cli.DockerCmd(c, "stop", cleanedContainerID)

out, _ = dockerCmd(c, "info")
out = cli.DockerCmd(c, "info").Stdout()
assert.Assert(c, strings.Contains(out, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1)))
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"])))
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"])))
assert.Assert(c, strings.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]+1)))
}

func existingContainerStates(c *testing.T) map[string]int {
out, _ := dockerCmd(c, "info", "--format", "{{json .}}")
out := cli.DockerCmd(c, "info", "--format", "{{json .}}").Stdout()
var m map[string]interface{}
err := json.Unmarshal([]byte(out), &m)
assert.NilError(c, err)
Expand Down

0 comments on commit ba32beb

Please sign in to comment.