зеркало из https://github.com/microsoft/docker.git
Replace dashes in link name with underscores
Docker-DCO-1.1-Signed-off-by: Jonathan Camp <jonathan@irondojo.com> (github: kung-foo)
This commit is contained in:
Родитель
7393eafde7
Коммит
6e74754a50
|
@ -49,7 +49,7 @@ func (l *Link) Alias() string {
|
|||
|
||||
func (l *Link) ToEnv() []string {
|
||||
env := []string{}
|
||||
alias := strings.ToUpper(l.Alias())
|
||||
alias := strings.Replace(strings.ToUpper(l.Alias()), "-", "_", -1)
|
||||
|
||||
if p := l.getDefaultPort(); p != nil {
|
||||
env = append(env, fmt.Sprintf("%s_PORT=%s://%s:%s", alias, p.Proto(), l.ChildIP, p.Port()))
|
||||
|
|
|
@ -6,6 +6,36 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestLinkNaming(t *testing.T) {
|
||||
ports := make(nat.PortSet)
|
||||
ports[nat.Port("6379/tcp")] = struct{}{}
|
||||
|
||||
link, err := NewLink("172.0.17.3", "172.0.17.2", "/db/docker-1", nil, 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]
|
||||
}
|
||||
|
||||
value, ok := env["DOCKER_1_PORT"]
|
||||
|
||||
if !ok {
|
||||
t.Fatalf("DOCKER_1_PORT not found in env")
|
||||
}
|
||||
|
||||
if value != "tcp://172.0.17.2:6379" {
|
||||
t.Fatalf("Expected 172.0.17.2:6379, got %s", env["DOCKER_1_PORT"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinkNew(t *testing.T) {
|
||||
ports := make(nat.PortSet)
|
||||
ports[nat.Port("6379/tcp")] = struct{}{}
|
||||
|
|
Загрузка…
Ссылка в новой задаче