mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 21:21:42 +00:00
adding support for port ranges on --expose
Closes #1834 Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
This commit is contained in:
@@ -13,11 +13,13 @@ import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/nat"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/pkg/networkfs/resolvconf"
|
||||
"github.com/kr/pty"
|
||||
@@ -2473,3 +2475,31 @@ func TestRunSlowStdoutConsumer(t *testing.T) {
|
||||
|
||||
logDone("run - slow consumer")
|
||||
}
|
||||
|
||||
func TestRunAllowPortRangeThroughExpose(t *testing.T) {
|
||||
cmd := exec.Command(dockerBinary, "run", "-d", "--expose", "3000-3003", "-P", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id := strings.TrimSpace(out)
|
||||
portstr, err := inspectFieldJSON(id, "NetworkSettings.Ports")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var ports nat.PortMap
|
||||
err = unmarshalJSON([]byte(portstr), &ports)
|
||||
for port, binding := range ports {
|
||||
portnum, _ := strconv.Atoi(strings.Split(string(port), "/")[0])
|
||||
if portnum < 3000 || portnum > 3003 {
|
||||
t.Fatalf("Port is out of range ", portnum, binding, out)
|
||||
}
|
||||
if binding == nil || len(binding) != 1 || len(binding[0].HostPort) == 0 {
|
||||
t.Fatal("Port is not mapped for the port "+port, out)
|
||||
}
|
||||
}
|
||||
if err := deleteContainer(id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logDone("run - allow port range through --expose flag")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user