mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Merge pull request #9181 from icecrime/allocate_daemon_ports
Allocate daemon listening ports
This commit is contained in:
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -284,3 +285,33 @@ func TestDaemonLoggingLevel(t *testing.T) {
|
||||
|
||||
logDone("daemon - Logging Level")
|
||||
}
|
||||
|
||||
func TestDaemonAllocatesListeningPort(t *testing.T) {
|
||||
listeningPorts := [][]string{
|
||||
{"0.0.0.0", "0.0.0.0", "5678"},
|
||||
{"127.0.0.1", "127.0.0.1", "1234"},
|
||||
{"localhost", "127.0.0.1", "1235"},
|
||||
}
|
||||
|
||||
cmdArgs := []string{}
|
||||
for _, hostDirective := range listeningPorts {
|
||||
cmdArgs = append(cmdArgs, "--host", fmt.Sprintf("tcp://%s:%s", hostDirective[0], hostDirective[2]))
|
||||
}
|
||||
|
||||
d := NewDaemon(t)
|
||||
if err := d.StartWithBusybox(cmdArgs...); err != nil {
|
||||
t.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
}
|
||||
defer d.Stop()
|
||||
|
||||
for _, hostDirective := range listeningPorts {
|
||||
output, err := d.Cmd("run", "-p", fmt.Sprintf("%s:%s:80", hostDirective[1], hostDirective[2]), "busybox", "true")
|
||||
if err == nil {
|
||||
t.Fatalf("Container should not start, expected port already allocated error: %q", output)
|
||||
} else if !strings.Contains(output, "port is already allocated") {
|
||||
t.Fatalf("Expected port is already allocated error: %q", output)
|
||||
}
|
||||
}
|
||||
|
||||
logDone("daemon - daemon listening port is allocated")
|
||||
}
|
||||
|
Reference in New Issue
Block a user