Merge pull request #1144 from hashicorp/unique-service-names
Ensuring check names are unique
This commit is contained in:
commit
d41939fefd
|
@ -1789,6 +1789,15 @@ func validateServices(t *Task) error {
|
|||
if service.PortLabel != "" {
|
||||
servicePorts[service.PortLabel] = append(servicePorts[service.PortLabel], service.Name)
|
||||
}
|
||||
|
||||
// Ensure that check names are unique.
|
||||
knownChecks := make(map[string]struct{})
|
||||
for _, check := range service.Checks {
|
||||
if _, ok := knownChecks[check.Name]; ok {
|
||||
mErr.Errors = append(mErr.Errors, fmt.Errorf("check %q is duplicate", check.Name))
|
||||
}
|
||||
knownChecks[check.Name] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the set of port labels.
|
||||
|
|
|
@ -284,6 +284,10 @@ func TestTask_Validate_Services(t *testing.T) {
|
|||
Name: "check-name",
|
||||
Type: ServiceCheckTCP,
|
||||
},
|
||||
{
|
||||
Name: "check-name",
|
||||
Type: ServiceCheckTCP,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -313,6 +317,10 @@ func TestTask_Validate_Services(t *testing.T) {
|
|||
if !strings.Contains(err.Error(), "service \"service-name\" is duplicate") {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), "check \"check-name\" is duplicate") {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTask_Validate_LogConfig(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue