From ba99a73c2fc3050475bd6c066c32dcb557cf6f25 Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Mon, 16 Feb 2015 11:08:32 -0800 Subject: [PATCH] fix naming, add a test for port range on docker ps Docker-DCO-1.1-Signed-off-by: Jessie Frazelle (github: jfrazelle) --- api/common.go | 20 ++++++++++---------- integration-cli/docker_cli_ps_test.go | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/api/common.go b/api/common.go index a8dc1a82a9..9e85c5ec3b 100644 --- a/api/common.go +++ b/api/common.go @@ -34,10 +34,10 @@ func DisplayablePorts(ports *engine.Table) string { var ( result = []string{} hostMappings = []string{} - startOfGroupMap map[string]int + firstInGroupMap map[string]int lastInGroupMap map[string]int ) - startOfGroupMap = make(map[string]int) + firstInGroupMap = make(map[string]int) lastInGroupMap = make(map[string]int) ports.SetKey("PrivatePort") ports.Sort() @@ -45,7 +45,7 @@ func DisplayablePorts(ports *engine.Table) string { var ( current = port.GetInt("PrivatePort") portKey = port.Get("Type") - startOfGroup int + firstInGroup int lastInGroup int ) if port.Get("IP") != "" { @@ -55,11 +55,11 @@ func DisplayablePorts(ports *engine.Table) string { } portKey = fmt.Sprintf("%s/%s", port.Get("IP"), port.Get("Type")) } - startOfGroup = startOfGroupMap[portKey] + firstInGroup = firstInGroupMap[portKey] lastInGroup = lastInGroupMap[portKey] - if startOfGroup == 0 { - startOfGroupMap[portKey] = current + if firstInGroup == 0 { + firstInGroupMap[portKey] = current lastInGroupMap[portKey] = current continue } @@ -68,12 +68,12 @@ func DisplayablePorts(ports *engine.Table) string { lastInGroupMap[portKey] = current continue } - result = append(result, FormGroup(portKey, startOfGroup, lastInGroup)) - startOfGroupMap[portKey] = current + result = append(result, FormGroup(portKey, firstInGroup, lastInGroup)) + firstInGroupMap[portKey] = current lastInGroupMap[portKey] = current } - for portKey, startOfGroup := range startOfGroupMap { - result = append(result, FormGroup(portKey, startOfGroup, lastInGroupMap[portKey])) + for portKey, firstInGroup := range firstInGroupMap { + result = append(result, FormGroup(portKey, firstInGroup, lastInGroupMap[portKey])) } result = append(result, hostMappings...) return strings.Join(result, ", ") diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index b92c80416c..e171ac0038 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -566,3 +566,25 @@ func TestPsLinkedWithNoTrunc(t *testing.T) { t.Fatalf("Expected array: %v, got: %v", expected, names) } } + +func TestPsGroupPortRange(t *testing.T) { + defer deleteAllContainers() + + portRange := "3300-3900" + out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top")) + if err != nil { + t.Fatal(out, err) + } + + out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps")) + if err != nil { + t.Fatal(out, err) + } + + // check that the port range is in the output + if !strings.Contains(string(out), portRange) { + t.Fatalf("docker ps output should have had the port range %q: %s", portRange, string(out)) + } + + logDone("ps - port range") +}