Signed-off-by: Vincent Demeester <vincent@sbr.pm>
| ... | ... |
@@ -1,11 +1,11 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 |
-import( |
|
| 3 |
+import ( |
|
| 4 | 4 |
"testing" |
| 5 | 5 |
|
| 6 |
- "github.com/docker/docker/container" |
|
| 7 | 6 |
"github.com/docker/docker/api/types" |
| 8 | 7 |
"github.com/docker/docker/api/types/filters" |
| 8 |
+ "github.com/docker/docker/container" |
|
| 9 | 9 |
"github.com/gotestyourself/gotestyourself/assert" |
| 10 | 10 |
is "github.com/gotestyourself/gotestyourself/assert/cmp" |
| 11 | 11 |
) |
| ... | ... |
@@ -23,4 +23,4 @@ func TestListInvalidFilter(t *testing.T) {
|
| 23 | 23 |
Filters: f, |
| 24 | 24 |
}) |
| 25 | 25 |
assert.Assert(t, is.Error(err, "Invalid filter 'invalid'")) |
| 26 |
-} |
|
| 27 | 26 |
\ No newline at end of file |
| 27 |
+} |
| ... | ... |
@@ -2,9 +2,6 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
- "io/ioutil" |
|
| 6 |
- "os" |
|
| 7 |
- "path/filepath" |
|
| 8 | 5 |
"sort" |
| 9 | 6 |
"strconv" |
| 10 | 7 |
"strings" |
| ... | ... |
@@ -512,48 +509,6 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
| 512 | 512 |
} |
| 513 | 513 |
} |
| 514 | 514 |
|
| 515 |
-func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
|
|
| 516 |
- // Problematic on Windows as it doesn't support links as of Jan 2016 |
|
| 517 |
- testRequires(c, DaemonIsLinux) |
|
| 518 |
- existingContainers := ExistingContainerIDs(c) |
|
| 519 |
- runSleepingContainer(c, "--name=first") |
|
| 520 |
- runSleepingContainer(c, "--name=second", "--link=first:first") |
|
| 521 |
- |
|
| 522 |
- out, _ := dockerCmd(c, "ps", "--no-trunc") |
|
| 523 |
- lines := strings.Split(strings.TrimSpace(string(out)), "\n") |
|
| 524 |
- // strip header |
|
| 525 |
- lines = lines[1:] |
|
| 526 |
- lines = RemoveLinesForExistingElements(lines, existingContainers) |
|
| 527 |
- expected := []string{"second", "first,second/first"}
|
|
| 528 |
- var names []string |
|
| 529 |
- for _, l := range lines {
|
|
| 530 |
- fields := strings.Fields(l) |
|
| 531 |
- names = append(names, fields[len(fields)-1]) |
|
| 532 |
- } |
|
| 533 |
- c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array: %v, got: %v", expected, names))
|
|
| 534 |
-} |
|
| 535 |
- |
|
| 536 |
-func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
|
|
| 537 |
- // Problematic on Windows as it doesn't support port ranges as of Jan 2016 |
|
| 538 |
- testRequires(c, DaemonIsLinux) |
|
| 539 |
- portRange := "3850-3900" |
|
| 540 |
- dockerCmd(c, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top") |
|
| 541 |
- |
|
| 542 |
- out, _ := dockerCmd(c, "ps") |
|
| 543 |
- |
|
| 544 |
- c.Assert(string(out), checker.Contains, portRange, check.Commentf("docker ps output should have had the port range %q: %s", portRange, string(out)))
|
|
| 545 |
- |
|
| 546 |
-} |
|
| 547 |
- |
|
| 548 |
-func (s *DockerSuite) TestPsWithSize(c *check.C) {
|
|
| 549 |
- // Problematic on Windows as it doesn't report the size correctly @swernli |
|
| 550 |
- testRequires(c, DaemonIsLinux) |
|
| 551 |
- dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top") |
|
| 552 |
- |
|
| 553 |
- out, _ := dockerCmd(c, "ps", "--size") |
|
| 554 |
- c.Assert(out, checker.Contains, "virtual", check.Commentf("docker ps with --size should show virtual size of container"))
|
|
| 555 |
-} |
|
| 556 |
- |
|
| 557 | 515 |
func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
| 558 | 516 |
// create a container |
| 559 | 517 |
out, _ := dockerCmd(c, "create", "busybox") |
| ... | ... |
@@ -584,69 +539,6 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
| 584 | 584 |
c.Assert(cID, checker.HasPrefix, containerOut) |
| 585 | 585 |
} |
| 586 | 586 |
|
| 587 |
-func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
|
|
| 588 |
- // Problematic on Windows as it doesn't support link as of Jan 2016 |
|
| 589 |
- testRequires(c, DaemonIsLinux) |
|
| 590 |
- existingContainers := ExistingContainerNames(c) |
|
| 591 |
- //create 2 containers and link them |
|
| 592 |
- dockerCmd(c, "run", "--name=child", "-d", "busybox", "top") |
|
| 593 |
- dockerCmd(c, "run", "--name=parent", "--link=child:linkedone", "-d", "busybox", "top") |
|
| 594 |
- |
|
| 595 |
- //use the new format capabilities to only list the names and --no-trunc to get all names |
|
| 596 |
- out, _ := dockerCmd(c, "ps", "--format", "{{.Names}}", "--no-trunc")
|
|
| 597 |
- out = RemoveOutputForExistingElements(out, existingContainers) |
|
| 598 |
- lines := strings.Split(strings.TrimSpace(string(out)), "\n") |
|
| 599 |
- expected := []string{"parent", "child,parent/linkedone"}
|
|
| 600 |
- var names []string |
|
| 601 |
- names = append(names, lines...) |
|
| 602 |
- c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with non-truncated names: %v, got: %v", expected, names))
|
|
| 603 |
- |
|
| 604 |
- //now list without turning off truncation and make sure we only get the non-link names |
|
| 605 |
- out, _ = dockerCmd(c, "ps", "--format", "{{.Names}}")
|
|
| 606 |
- out = RemoveOutputForExistingElements(out, existingContainers) |
|
| 607 |
- lines = strings.Split(strings.TrimSpace(string(out)), "\n") |
|
| 608 |
- expected = []string{"parent", "child"}
|
|
| 609 |
- var truncNames []string |
|
| 610 |
- truncNames = append(truncNames, lines...) |
|
| 611 |
- c.Assert(expected, checker.DeepEquals, truncNames, check.Commentf("Expected array with truncated names: %v, got: %v", expected, truncNames))
|
|
| 612 |
-} |
|
| 613 |
- |
|
| 614 |
-// Test for GitHub issue #21772 |
|
| 615 |
-func (s *DockerSuite) TestPsNamesMultipleTime(c *check.C) {
|
|
| 616 |
- existingContainers := ExistingContainerNames(c) |
|
| 617 |
- runSleepingContainer(c, "--name=test1") |
|
| 618 |
- runSleepingContainer(c, "--name=test2") |
|
| 619 |
- |
|
| 620 |
- //use the new format capabilities to list the names twice |
|
| 621 |
- out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Names}}")
|
|
| 622 |
- lines := strings.Split(strings.TrimSpace(string(out)), "\n") |
|
| 623 |
- lines = RemoveLinesForExistingElements(lines, existingContainers) |
|
| 624 |
- expected := []string{"test2 test2", "test1 test1"}
|
|
| 625 |
- var names []string |
|
| 626 |
- names = append(names, lines...) |
|
| 627 |
- c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with names displayed twice: %v, got: %v", expected, names))
|
|
| 628 |
-} |
|
| 629 |
- |
|
| 630 |
-func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
|
|
| 631 |
- existingContainers := ExistingContainerIDs(c) |
|
| 632 |
- config := `{
|
|
| 633 |
- "psFormat": "default {{ .ID }}"
|
|
| 634 |
-}` |
|
| 635 |
- d, err := ioutil.TempDir("", "integration-cli-")
|
|
| 636 |
- c.Assert(err, checker.IsNil) |
|
| 637 |
- defer os.RemoveAll(d) |
|
| 638 |
- |
|
| 639 |
- err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644) |
|
| 640 |
- c.Assert(err, checker.IsNil) |
|
| 641 |
- |
|
| 642 |
- out := runSleepingContainer(c, "--name=test") |
|
| 643 |
- id := strings.TrimSpace(out) |
|
| 644 |
- |
|
| 645 |
- out, _ = dockerCmd(c, "--config", d, "ps", "-q") |
|
| 646 |
- out = RemoveOutputForExistingElements(out, existingContainers) |
|
| 647 |
- c.Assert(id, checker.HasPrefix, strings.TrimSpace(out), check.Commentf("Expected to print only the container id, got %v\n", out))
|
|
| 648 |
-} |
|
| 649 |
- |
|
| 650 | 587 |
// Test for GitHub issue #12595 |
| 651 | 588 |
func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
| 652 | 589 |
// TODO: Investigate why this fails on Windows to Windows CI further. |
| ... | ... |
@@ -815,23 +707,6 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
| 815 | 815 |
c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0) |
| 816 | 816 |
} |
| 817 | 817 |
|
| 818 |
-func (s *DockerSuite) TestPsFormatSize(c *check.C) {
|
|
| 819 |
- testRequires(c, DaemonIsLinux) |
|
| 820 |
- runSleepingContainer(c) |
|
| 821 |
- |
|
| 822 |
- out, _ := dockerCmd(c, "ps", "--format", "table {{.Size}}")
|
|
| 823 |
- lines := strings.Split(out, "\n") |
|
| 824 |
- c.Assert(lines[1], checker.Not(checker.Equals), "0 B", check.Commentf("Should not display a size of 0 B"))
|
|
| 825 |
- |
|
| 826 |
- out, _ = dockerCmd(c, "ps", "--size", "--format", "table {{.Size}}")
|
|
| 827 |
- lines = strings.Split(out, "\n") |
|
| 828 |
- c.Assert(lines[0], checker.Equals, "SIZE", check.Commentf("Should only have one size column"))
|
|
| 829 |
- |
|
| 830 |
- out, _ = dockerCmd(c, "ps", "--size", "--format", "raw") |
|
| 831 |
- lines = strings.Split(out, "\n") |
|
| 832 |
- c.Assert(lines[8], checker.HasPrefix, "size:", check.Commentf("Size should be appended on a newline"))
|
|
| 833 |
-} |
|
| 834 |
- |
|
| 835 | 818 |
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
| 836 | 819 |
existing := ExistingContainerIDs(c) |
| 837 | 820 |
|
| ... | ... |
@@ -936,20 +811,6 @@ func (s *DockerSuite) TestPsByOrder(c *check.C) {
|
| 936 | 936 |
c.Assert(strings.TrimSpace(out), checker.Equals, fmt.Sprintf("%s\n%s", container2, container1))
|
| 937 | 937 |
} |
| 938 | 938 |
|
| 939 |
-func (s *DockerSuite) TestPsFilterMissingArgErrorCode(c *check.C) {
|
|
| 940 |
- _, errCode, _ := dockerCmdWithError("ps", "--filter")
|
|
| 941 |
- c.Assert(errCode, checker.Equals, 125) |
|
| 942 |
-} |
|
| 943 |
- |
|
| 944 |
-// Test case for 30291 |
|
| 945 |
-func (s *DockerSuite) TestPsFormatTemplateWithArg(c *check.C) {
|
|
| 946 |
- existingContainers := ExistingContainerNames(c) |
|
| 947 |
- runSleepingContainer(c, "-d", "--name", "top", "--label", "some.label=label.foo-bar") |
|
| 948 |
- out, _ := dockerCmd(c, "ps", "--format", `{{.Names}} {{.Label "some.label"}}`)
|
|
| 949 |
- out = RemoveOutputForExistingElements(out, existingContainers) |
|
| 950 |
- c.Assert(strings.TrimSpace(out), checker.Equals, "top label.foo-bar") |
|
| 951 |
-} |
|
| 952 |
- |
|
| 953 | 939 |
func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
|
| 954 | 940 |
testRequires(c, DaemonIsLinux) |
| 955 | 941 |
existingContainers := ExistingContainerIDs(c) |
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"time" |
| 10 | 10 |
|
| 11 | 11 |
"github.com/docker/docker/api/types" |
| 12 |
+ "github.com/docker/docker/api/types/filters" |
|
| 12 | 13 |
"github.com/docker/docker/integration/internal/container" |
| 13 | 14 |
"github.com/docker/docker/integration/internal/request" |
| 14 | 15 |
"github.com/docker/docker/pkg/stdcopy" |
| ... | ... |
@@ -44,3 +45,23 @@ func TestLinksEtcHostsContentMatch(t *testing.T) {
|
| 44 | 44 |
|
| 45 | 45 |
assert.Equal(t, string(hosts), b.String()) |
| 46 | 46 |
} |
| 47 |
+ |
|
| 48 |
+func TestLinksContainerNames(t *testing.T) {
|
|
| 49 |
+ skip.If(t, testEnv.DaemonInfo.OSType != "linux") |
|
| 50 |
+ |
|
| 51 |
+ defer setupTest(t)() |
|
| 52 |
+ client := request.NewAPIClient(t) |
|
| 53 |
+ ctx := context.Background() |
|
| 54 |
+ |
|
| 55 |
+ container.Run(t, ctx, client, container.WithName("first"))
|
|
| 56 |
+ container.Run(t, ctx, client, container.WithName("second"), container.WithLinks("first:first"))
|
|
| 57 |
+ |
|
| 58 |
+ f := filters.NewArgs(filters.Arg("name", "first"))
|
|
| 59 |
+ |
|
| 60 |
+ containers, err := client.ContainerList(ctx, types.ContainerListOptions{
|
|
| 61 |
+ Filters: f, |
|
| 62 |
+ }) |
|
| 63 |
+ require.NoError(t, err) |
|
| 64 |
+ assert.Equal(t, 1, len(containers)) |
|
| 65 |
+ assert.Equal(t, []string{"/first", "/second/first"}, containers[0].Names)
|
|
| 66 |
+} |