Improve port label validation and diff testing

This commit is contained in:
Michael Schurter 2017-12-07 22:09:37 -08:00
parent 91282315d1
commit af8964e896
2 changed files with 13 additions and 3 deletions

View file

@ -3507,6 +3507,12 @@ func TestTaskDiff(t *testing.T) {
Type: DiffTypeEdited,
Name: "Check",
Fields: []*FieldDiff{
{
Type: DiffTypeNone,
Name: "AddressMode",
Old: "",
New: "",
},
{
Type: DiffTypeNone,
Name: "Command",

View file

@ -3473,10 +3473,14 @@ func validateServices(t *Task) error {
knownServices[service.Name+service.PortLabel] = struct{}{}
if service.PortLabel != "" {
if _, err := strconv.Atoi(service.PortLabel); service.AddressMode == "driver" && err == nil {
// Numeric ports are valid when AddressMode=driver
if service.AddressMode == "driver" {
// Numeric port labels are valid for address_mode=driver
_, err := strconv.Atoi(service.PortLabel)
if err != nil {
// Not a numeric port label, add it to list to check
servicePorts[service.PortLabel] = append(servicePorts[service.PortLabel], service.Name)
}
} else {
servicePorts[service.PortLabel] = append(servicePorts[service.PortLabel], service.Name)
}
}