mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	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)
This commit is contained in:
		
							parent
							
								
									5dfef4fe08
								
							
						
					
					
						commit
						ba99a73c2f
					
				
					 2 changed files with 32 additions and 10 deletions
				
			
		| 
						 | 
					@ -34,10 +34,10 @@ func DisplayablePorts(ports *engine.Table) string {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		result          = []string{}
 | 
							result          = []string{}
 | 
				
			||||||
		hostMappings    = []string{}
 | 
							hostMappings    = []string{}
 | 
				
			||||||
		startOfGroupMap map[string]int
 | 
							firstInGroupMap map[string]int
 | 
				
			||||||
		lastInGroupMap  map[string]int
 | 
							lastInGroupMap  map[string]int
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	startOfGroupMap = make(map[string]int)
 | 
						firstInGroupMap = make(map[string]int)
 | 
				
			||||||
	lastInGroupMap = make(map[string]int)
 | 
						lastInGroupMap = make(map[string]int)
 | 
				
			||||||
	ports.SetKey("PrivatePort")
 | 
						ports.SetKey("PrivatePort")
 | 
				
			||||||
	ports.Sort()
 | 
						ports.Sort()
 | 
				
			||||||
| 
						 | 
					@ -45,7 +45,7 @@ func DisplayablePorts(ports *engine.Table) string {
 | 
				
			||||||
		var (
 | 
							var (
 | 
				
			||||||
			current      = port.GetInt("PrivatePort")
 | 
								current      = port.GetInt("PrivatePort")
 | 
				
			||||||
			portKey      = port.Get("Type")
 | 
								portKey      = port.Get("Type")
 | 
				
			||||||
			startOfGroup int
 | 
								firstInGroup int
 | 
				
			||||||
			lastInGroup  int
 | 
								lastInGroup  int
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
		if port.Get("IP") != "" {
 | 
							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"))
 | 
								portKey = fmt.Sprintf("%s/%s", port.Get("IP"), port.Get("Type"))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		startOfGroup = startOfGroupMap[portKey]
 | 
							firstInGroup = firstInGroupMap[portKey]
 | 
				
			||||||
		lastInGroup = lastInGroupMap[portKey]
 | 
							lastInGroup = lastInGroupMap[portKey]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if startOfGroup == 0 {
 | 
							if firstInGroup == 0 {
 | 
				
			||||||
			startOfGroupMap[portKey] = current
 | 
								firstInGroupMap[portKey] = current
 | 
				
			||||||
			lastInGroupMap[portKey] = current
 | 
								lastInGroupMap[portKey] = current
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -68,12 +68,12 @@ func DisplayablePorts(ports *engine.Table) string {
 | 
				
			||||||
			lastInGroupMap[portKey] = current
 | 
								lastInGroupMap[portKey] = current
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result = append(result, FormGroup(portKey, startOfGroup, lastInGroup))
 | 
							result = append(result, FormGroup(portKey, firstInGroup, lastInGroup))
 | 
				
			||||||
		startOfGroupMap[portKey] = current
 | 
							firstInGroupMap[portKey] = current
 | 
				
			||||||
		lastInGroupMap[portKey] = current
 | 
							lastInGroupMap[portKey] = current
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for portKey, startOfGroup := range startOfGroupMap {
 | 
						for portKey, firstInGroup := range firstInGroupMap {
 | 
				
			||||||
		result = append(result, FormGroup(portKey, startOfGroup, lastInGroupMap[portKey]))
 | 
							result = append(result, FormGroup(portKey, firstInGroup, lastInGroupMap[portKey]))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	result = append(result, hostMappings...)
 | 
						result = append(result, hostMappings...)
 | 
				
			||||||
	return strings.Join(result, ", ")
 | 
						return strings.Join(result, ", ")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -566,3 +566,25 @@ func TestPsLinkedWithNoTrunc(t *testing.T) {
 | 
				
			||||||
		t.Fatalf("Expected array: %v, got: %v", expected, names)
 | 
							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")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue