mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #6270 from kung-foo/5418-underscore
Replace dashes in link name with underscores
This commit is contained in:
commit
a613ac1907
2 changed files with 31 additions and 1 deletions
|
@ -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{}{}
|
||||
|
|
Loading…
Reference in a new issue