Browse code

fix naming, add a test for port range on docker ps

Docker-DCO-1.1-Signed-off-by: Jessie Frazelle <jess@docker.com> (github: jfrazelle)

Jessica Frazelle authored on 2015/02/17 04:08:32
Showing 2 changed files
... ...
@@ -34,10 +34,10 @@ func DisplayablePorts(ports *engine.Table) string {
34 34
 	var (
35 35
 		result          = []string{}
36 36
 		hostMappings    = []string{}
37
-		startOfGroupMap map[string]int
37
+		firstInGroupMap map[string]int
38 38
 		lastInGroupMap  map[string]int
39 39
 	)
40
-	startOfGroupMap = make(map[string]int)
40
+	firstInGroupMap = make(map[string]int)
41 41
 	lastInGroupMap = make(map[string]int)
42 42
 	ports.SetKey("PrivatePort")
43 43
 	ports.Sort()
... ...
@@ -45,7 +45,7 @@ func DisplayablePorts(ports *engine.Table) string {
45 45
 		var (
46 46
 			current      = port.GetInt("PrivatePort")
47 47
 			portKey      = port.Get("Type")
48
-			startOfGroup int
48
+			firstInGroup int
49 49
 			lastInGroup  int
50 50
 		)
51 51
 		if port.Get("IP") != "" {
... ...
@@ -55,11 +55,11 @@ func DisplayablePorts(ports *engine.Table) string {
55 55
 			}
56 56
 			portKey = fmt.Sprintf("%s/%s", port.Get("IP"), port.Get("Type"))
57 57
 		}
58
-		startOfGroup = startOfGroupMap[portKey]
58
+		firstInGroup = firstInGroupMap[portKey]
59 59
 		lastInGroup = lastInGroupMap[portKey]
60 60
 
61
-		if startOfGroup == 0 {
62
-			startOfGroupMap[portKey] = current
61
+		if firstInGroup == 0 {
62
+			firstInGroupMap[portKey] = current
63 63
 			lastInGroupMap[portKey] = current
64 64
 			continue
65 65
 		}
... ...
@@ -68,12 +68,12 @@ func DisplayablePorts(ports *engine.Table) string {
68 68
 			lastInGroupMap[portKey] = current
69 69
 			continue
70 70
 		}
71
-		result = append(result, FormGroup(portKey, startOfGroup, lastInGroup))
72
-		startOfGroupMap[portKey] = current
71
+		result = append(result, FormGroup(portKey, firstInGroup, lastInGroup))
72
+		firstInGroupMap[portKey] = current
73 73
 		lastInGroupMap[portKey] = current
74 74
 	}
75
-	for portKey, startOfGroup := range startOfGroupMap {
76
-		result = append(result, FormGroup(portKey, startOfGroup, lastInGroupMap[portKey]))
75
+	for portKey, firstInGroup := range firstInGroupMap {
76
+		result = append(result, FormGroup(portKey, firstInGroup, lastInGroupMap[portKey]))
77 77
 	}
78 78
 	result = append(result, hostMappings...)
79 79
 	return strings.Join(result, ", ")
... ...
@@ -566,3 +566,25 @@ func TestPsLinkedWithNoTrunc(t *testing.T) {
566 566
 		t.Fatalf("Expected array: %v, got: %v", expected, names)
567 567
 	}
568 568
 }
569
+
570
+func TestPsGroupPortRange(t *testing.T) {
571
+	defer deleteAllContainers()
572
+
573
+	portRange := "3300-3900"
574
+	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top"))
575
+	if err != nil {
576
+		t.Fatal(out, err)
577
+	}
578
+
579
+	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps"))
580
+	if err != nil {
581
+		t.Fatal(out, err)
582
+	}
583
+
584
+	// check that the port range is in the output
585
+	if !strings.Contains(string(out), portRange) {
586
+		t.Fatalf("docker ps output should have had the port range %q: %s", portRange, string(out))
587
+	}
588
+
589
+	logDone("ps - port range")
590
+}