mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Clean some cli-only integration tests
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
05e7f2cf58
commit
641c73d211
3 changed files with 24 additions and 142 deletions
|
@ -1,11 +1,11 @@
|
|||
package daemon
|
||||
|
||||
import(
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
@ -23,4 +23,4 @@ func TestListInvalidFilter(t *testing.T) {
|
|||
Filters: f,
|
||||
})
|
||||
assert.Assert(t, is.Error(err, "Invalid filter 'invalid'"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -512,48 +509,6 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
|
||||
// Problematic on Windows as it doesn't support links as of Jan 2016
|
||||
testRequires(c, DaemonIsLinux)
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
runSleepingContainer(c, "--name=first")
|
||||
runSleepingContainer(c, "--name=second", "--link=first:first")
|
||||
|
||||
out, _ := dockerCmd(c, "ps", "--no-trunc")
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
// strip header
|
||||
lines = lines[1:]
|
||||
lines = RemoveLinesForExistingElements(lines, existingContainers)
|
||||
expected := []string{"second", "first,second/first"}
|
||||
var names []string
|
||||
for _, l := range lines {
|
||||
fields := strings.Fields(l)
|
||||
names = append(names, fields[len(fields)-1])
|
||||
}
|
||||
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array: %v, got: %v", expected, names))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
|
||||
// Problematic on Windows as it doesn't support port ranges as of Jan 2016
|
||||
testRequires(c, DaemonIsLinux)
|
||||
portRange := "3850-3900"
|
||||
dockerCmd(c, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top")
|
||||
|
||||
out, _ := dockerCmd(c, "ps")
|
||||
|
||||
c.Assert(string(out), checker.Contains, portRange, check.Commentf("docker ps output should have had the port range %q: %s", portRange, string(out)))
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsWithSize(c *check.C) {
|
||||
// Problematic on Windows as it doesn't report the size correctly @swernli
|
||||
testRequires(c, DaemonIsLinux)
|
||||
dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top")
|
||||
|
||||
out, _ := dockerCmd(c, "ps", "--size")
|
||||
c.Assert(out, checker.Contains, "virtual", check.Commentf("docker ps with --size should show virtual size of container"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
||||
// create a container
|
||||
out, _ := dockerCmd(c, "create", "busybox")
|
||||
|
@ -584,69 +539,6 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
|||
c.Assert(cID, checker.HasPrefix, containerOut)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
|
||||
// Problematic on Windows as it doesn't support link as of Jan 2016
|
||||
testRequires(c, DaemonIsLinux)
|
||||
existingContainers := ExistingContainerNames(c)
|
||||
//create 2 containers and link them
|
||||
dockerCmd(c, "run", "--name=child", "-d", "busybox", "top")
|
||||
dockerCmd(c, "run", "--name=parent", "--link=child:linkedone", "-d", "busybox", "top")
|
||||
|
||||
//use the new format capabilities to only list the names and --no-trunc to get all names
|
||||
out, _ := dockerCmd(c, "ps", "--format", "{{.Names}}", "--no-trunc")
|
||||
out = RemoveOutputForExistingElements(out, existingContainers)
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
expected := []string{"parent", "child,parent/linkedone"}
|
||||
var names []string
|
||||
names = append(names, lines...)
|
||||
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with non-truncated names: %v, got: %v", expected, names))
|
||||
|
||||
//now list without turning off truncation and make sure we only get the non-link names
|
||||
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}}")
|
||||
out = RemoveOutputForExistingElements(out, existingContainers)
|
||||
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
expected = []string{"parent", "child"}
|
||||
var truncNames []string
|
||||
truncNames = append(truncNames, lines...)
|
||||
c.Assert(expected, checker.DeepEquals, truncNames, check.Commentf("Expected array with truncated names: %v, got: %v", expected, truncNames))
|
||||
}
|
||||
|
||||
// Test for GitHub issue #21772
|
||||
func (s *DockerSuite) TestPsNamesMultipleTime(c *check.C) {
|
||||
existingContainers := ExistingContainerNames(c)
|
||||
runSleepingContainer(c, "--name=test1")
|
||||
runSleepingContainer(c, "--name=test2")
|
||||
|
||||
//use the new format capabilities to list the names twice
|
||||
out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Names}}")
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
lines = RemoveLinesForExistingElements(lines, existingContainers)
|
||||
expected := []string{"test2 test2", "test1 test1"}
|
||||
var names []string
|
||||
names = append(names, lines...)
|
||||
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with names displayed twice: %v, got: %v", expected, names))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
config := `{
|
||||
"psFormat": "default {{ .ID }}"
|
||||
}`
|
||||
d, err := ioutil.TempDir("", "integration-cli-")
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
out := runSleepingContainer(c, "--name=test")
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
out, _ = dockerCmd(c, "--config", d, "ps", "-q")
|
||||
out = RemoveOutputForExistingElements(out, existingContainers)
|
||||
c.Assert(id, checker.HasPrefix, strings.TrimSpace(out), check.Commentf("Expected to print only the container id, got %v\n", out))
|
||||
}
|
||||
|
||||
// Test for GitHub issue #12595
|
||||
func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
||||
// TODO: Investigate why this fails on Windows to Windows CI further.
|
||||
|
@ -815,23 +707,6 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|||
c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsFormatSize(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
runSleepingContainer(c)
|
||||
|
||||
out, _ := dockerCmd(c, "ps", "--format", "table {{.Size}}")
|
||||
lines := strings.Split(out, "\n")
|
||||
c.Assert(lines[1], checker.Not(checker.Equals), "0 B", check.Commentf("Should not display a size of 0 B"))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--size", "--format", "table {{.Size}}")
|
||||
lines = strings.Split(out, "\n")
|
||||
c.Assert(lines[0], checker.Equals, "SIZE", check.Commentf("Should only have one size column"))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--size", "--format", "raw")
|
||||
lines = strings.Split(out, "\n")
|
||||
c.Assert(lines[8], checker.HasPrefix, "size:", check.Commentf("Size should be appended on a newline"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
||||
existing := ExistingContainerIDs(c)
|
||||
|
||||
|
@ -936,20 +811,6 @@ func (s *DockerSuite) TestPsByOrder(c *check.C) {
|
|||
c.Assert(strings.TrimSpace(out), checker.Equals, fmt.Sprintf("%s\n%s", container2, container1))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsFilterMissingArgErrorCode(c *check.C) {
|
||||
_, errCode, _ := dockerCmdWithError("ps", "--filter")
|
||||
c.Assert(errCode, checker.Equals, 125)
|
||||
}
|
||||
|
||||
// Test case for 30291
|
||||
func (s *DockerSuite) TestPsFormatTemplateWithArg(c *check.C) {
|
||||
existingContainers := ExistingContainerNames(c)
|
||||
runSleepingContainer(c, "-d", "--name", "top", "--label", "some.label=label.foo-bar")
|
||||
out, _ := dockerCmd(c, "ps", "--format", `{{.Names}} {{.Label "some.label"}}`)
|
||||
out = RemoveOutputForExistingElements(out, existingContainers)
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, "top label.foo-bar")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/integration/internal/request"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
|
@ -44,3 +45,23 @@ func TestLinksEtcHostsContentMatch(t *testing.T) {
|
|||
|
||||
assert.Equal(t, string(hosts), b.String())
|
||||
}
|
||||
|
||||
func TestLinksContainerNames(t *testing.T) {
|
||||
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
||||
|
||||
defer setupTest(t)()
|
||||
client := request.NewAPIClient(t)
|
||||
ctx := context.Background()
|
||||
|
||||
container.Run(t, ctx, client, container.WithName("first"))
|
||||
container.Run(t, ctx, client, container.WithName("second"), container.WithLinks("first:first"))
|
||||
|
||||
f := filters.NewArgs(filters.Arg("name", "first"))
|
||||
|
||||
containers, err := client.ContainerList(ctx, types.ContainerListOptions{
|
||||
Filters: f,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(containers))
|
||||
assert.Equal(t, []string{"/first", "/second/first"}, containers[0].Names)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue