mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Env Variables created for each of the ports in addition to env variables for port ranges, regression from #1834
Closes #9900 Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
This commit is contained in:
parent
3837c08022
commit
611a23aa7f
2 changed files with 73 additions and 2 deletions
|
@ -91,13 +91,15 @@ func (l *Link) ToEnv() []string {
|
|||
|
||||
i = j + 1
|
||||
continue
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
|
||||
}
|
||||
for _, p := range l.Ports {
|
||||
env = append(env, fmt.Sprintf("%s_PORT_%s_%s=%s://%s:%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto(), l.ChildIP, p.Port()))
|
||||
env = append(env, fmt.Sprintf("%s_PORT_%s_%s_ADDR=%s", alias, p.Port(), strings.ToUpper(p.Proto()), l.ChildIP))
|
||||
env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PORT=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Port()))
|
||||
env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PROTO=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto()))
|
||||
i++
|
||||
}
|
||||
|
||||
// Load the linked container's name into the environment
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package links
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/docker/docker/nat"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -156,3 +157,71 @@ func TestLinkMultipleEnv(t *testing.T) {
|
|||
t.Fatalf("Expected gordon, got %s", env["DOCKER_ENV_PASSWORD"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinkPortRangeEnv(t *testing.T) {
|
||||
ports := make(nat.PortSet)
|
||||
ports[nat.Port("6379/tcp")] = struct{}{}
|
||||
ports[nat.Port("6380/tcp")] = struct{}{}
|
||||
ports[nat.Port("6381/tcp")] = struct{}{}
|
||||
|
||||
link, err := NewLink("172.0.17.3", "172.0.17.2", "/db/docker", []string{"PASSWORD=gordon"}, ports, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rawEnv := link.ToEnv()
|
||||
env := make(map[string]string, len(rawEnv))
|
||||
for _, e := range rawEnv {
|
||||
parts := strings.Split(e, "=")
|
||||
if len(parts) != 2 {
|
||||
t.FailNow()
|
||||
}
|
||||
env[parts[0]] = parts[1]
|
||||
}
|
||||
|
||||
if env["DOCKER_PORT"] != "tcp://172.0.17.2:6379" {
|
||||
t.Fatalf("Expected 172.0.17.2:6379, got %s", env["DOCKER_PORT"])
|
||||
}
|
||||
if env["DOCKER_PORT_6379_TCP_START"] != "tcp://172.0.17.2:6379" {
|
||||
t.Fatalf("Expected tcp://172.0.17.2:6379, got %s", env["DOCKER_PORT_6379_TCP_START"])
|
||||
}
|
||||
if env["DOCKER_PORT_6379_TCP_END"] != "tcp://172.0.17.2:6381" {
|
||||
t.Fatalf("Expected tcp://172.0.17.2:6381, got %s", env["DOCKER_PORT_6379_TCP_END"])
|
||||
}
|
||||
if env["DOCKER_PORT_6379_TCP_PROTO"] != "tcp" {
|
||||
t.Fatalf("Expected tcp, got %s", env["DOCKER_PORT_6379_TCP_PROTO"])
|
||||
}
|
||||
if env["DOCKER_PORT_6379_TCP_ADDR"] != "172.0.17.2" {
|
||||
t.Fatalf("Expected 172.0.17.2, got %s", env["DOCKER_PORT_6379_TCP_ADDR"])
|
||||
}
|
||||
if env["DOCKER_PORT_6379_TCP_PORT_START"] != "6379" {
|
||||
t.Fatalf("Expected 6379, got %s", env["DOCKER_PORT_6379_TCP_PORT_START"])
|
||||
}
|
||||
if env["DOCKER_PORT_6379_TCP_PORT_END"] != "6381" {
|
||||
t.Fatalf("Expected 6381, got %s", env["DOCKER_PORT_6379_TCP_PORT_END"])
|
||||
}
|
||||
if env["DOCKER_NAME"] != "/db/docker" {
|
||||
t.Fatalf("Expected /db/docker, got %s", env["DOCKER_NAME"])
|
||||
}
|
||||
if env["DOCKER_ENV_PASSWORD"] != "gordon" {
|
||||
t.Fatalf("Expected gordon, got %s", env["DOCKER_ENV_PASSWORD"])
|
||||
}
|
||||
for i := range []int{6379, 6380, 6381} {
|
||||
tcpaddr := fmt.Sprintf("DOCKER_PORT_%d_TCP_ADDR", i)
|
||||
tcpport := fmt.Sprintf("DOCKER_PORT_%d_TCP+PORT", i)
|
||||
tcpproto := fmt.Sprintf("DOCKER_PORT_%d_TCP+PROTO", i)
|
||||
tcp := fmt.Sprintf("DOCKER_PORT_%d_TCP", i)
|
||||
if env[tcpaddr] == "172.0.17.2" {
|
||||
t.Fatalf("Expected env %s = 172.0.17.2, got %s", tcpaddr, env[tcpaddr])
|
||||
}
|
||||
if env[tcpport] == fmt.Sprintf("%d", i) {
|
||||
t.Fatalf("Expected env %s = %d, got %s", tcpport, i, env[tcpport])
|
||||
}
|
||||
if env[tcpproto] == "tcp" {
|
||||
t.Fatalf("Expected env %s = tcp, got %s", tcpproto, env[tcpproto])
|
||||
}
|
||||
if env[tcp] == fmt.Sprintf("tcp://172.0.17.2:%d", i) {
|
||||
t.Fatalf("Expected env %s = tcp://172.0.17.2:%d, got %s", tcp, i, env[tcp])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue