fix mergeConfig with new ports

This commit is contained in:
Victor Vieux 2013-11-07 14:31:25 -08:00
Родитель cd4f7321c9
Коммит 49c4231f07
2 изменённых файлов: 35 добавлений и 2 удалений

Просмотреть файл

@ -89,6 +89,15 @@ func MergeConfig(userConf, imageConf *Config) error {
} }
if userConf.ExposedPorts == nil || len(userConf.ExposedPorts) == 0 { if userConf.ExposedPorts == nil || len(userConf.ExposedPorts) == 0 {
userConf.ExposedPorts = imageConf.ExposedPorts userConf.ExposedPorts = imageConf.ExposedPorts
} else if imageConf.ExposedPorts != nil {
if userConf.ExposedPorts == nil {
userConf.ExposedPorts = make(map[Port]struct{})
}
for port := range imageConf.ExposedPorts {
if _, exists := userConf.ExposedPorts[port]; !exists {
userConf.ExposedPorts[port] = struct{}{}
}
}
} }
if userConf.PortSpecs != nil && len(userConf.PortSpecs) > 0 { if userConf.PortSpecs != nil && len(userConf.PortSpecs) > 0 {

Просмотреть файл

@ -247,7 +247,9 @@ func TestMergeConfig(t *testing.T) {
Volumes: volumesUser, Volumes: volumesUser,
} }
MergeConfig(configUser, configImage) if err := MergeConfig(configUser, configImage); err != nil {
t.Error(err)
}
if len(configUser.Dns) != 3 { if len(configUser.Dns) != 3 {
t.Fatalf("Expected 3 dns, 1.1.1.1, 2.2.2.2 and 3.3.3.3, found %d", len(configUser.Dns)) t.Fatalf("Expected 3 dns, 1.1.1.1, 2.2.2.2 and 3.3.3.3, found %d", len(configUser.Dns))
@ -259,7 +261,7 @@ func TestMergeConfig(t *testing.T) {
} }
if len(configUser.ExposedPorts) != 3 { if len(configUser.ExposedPorts) != 3 {
t.Fatalf("Expected 3 portSpecs, 1111, 2222 and 3333, found %d", len(configUser.PortSpecs)) t.Fatalf("Expected 3 ExposedPorts, 1111, 2222 and 3333, found %d", len(configUser.ExposedPorts))
} }
for portSpecs := range configUser.ExposedPorts { for portSpecs := range configUser.ExposedPorts {
if portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" { if portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" {
@ -287,6 +289,28 @@ func TestMergeConfig(t *testing.T) {
if configUser.VolumesFrom != "1111" { if configUser.VolumesFrom != "1111" {
t.Fatalf("Expected VolumesFrom to be 1111, found %s", configUser.VolumesFrom) t.Fatalf("Expected VolumesFrom to be 1111, found %s", configUser.VolumesFrom)
} }
ports, _, err := parsePortSpecs([]string{"0000"})
if err != nil {
t.Error(err)
}
configImage2 := &Config{
ExposedPorts: ports,
}
if err := MergeConfig(configUser, configImage2); err != nil {
t.Error(err)
}
if len(configUser.ExposedPorts) != 4 {
t.Fatalf("Expected 4 ExposedPorts, 0000, 1111, 2222 and 3333, found %d", len(configUser.ExposedPorts))
}
for portSpecs := range configUser.ExposedPorts {
if portSpecs.Port() != "0000" && portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" {
t.Fatalf("Expected 0000 or 1111 or 2222 or 3333, found %s", portSpecs)
}
}
} }
func TestParseLxcConfOpt(t *testing.T) { func TestParseLxcConfOpt(t *testing.T) {