Add Test for port allocation bug (port already in use by other programs than docker)

Signed-off-by: Tibor Vass <teabee89@gmail.com>
This commit is contained in:
Tibor Vass 2014-09-05 18:59:31 -07:00 committed by Alexandr Morozov
parent 32b5d145fa
commit 3109fc9537
1 changed files with 19 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
"path"
@ -1875,3 +1876,21 @@ func TestRunDeallocatePortOnMissingIptablesRule(t *testing.T) {
deleteAllContainers()
logDone("run - port should be deallocated even on iptables error")
}
func TestRunPortInUse(t *testing.T) {
port := "1234"
l, err := net.Listen("tcp", ":"+port)
if err != nil {
t.Fatal(err)
}
defer l.Close()
cmd := exec.Command(dockerBinary, "run", "-p", port+":80", "busybox", "true")
out, _, err := runCommandWithOutput(cmd)
if err == nil {
t.Fatalf("Host port %s already in use, has been allocated by docker: %q", port, out)
}
deleteAllContainers()
logDone("run - port in use")
}