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:
parent
32b5d145fa
commit
3109fc9537
|
@ -4,6 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
@ -1875,3 +1876,21 @@ func TestRunDeallocatePortOnMissingIptablesRule(t *testing.T) {
|
||||||
deleteAllContainers()
|
deleteAllContainers()
|
||||||
logDone("run - port should be deallocated even on iptables error")
|
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")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue