diff --git a/config/config.go b/config/config.go index 3ca193004..281881867 100644 --- a/config/config.go +++ b/config/config.go @@ -69,7 +69,13 @@ func (c Config) Validate() error { } // Check each job configuration for validity. + jobNames := map[string]bool{} for _, job := range c.Job { + if jobNames[job.GetName()] { + return fmt.Errorf("Found multiple jobs configured with the same name: '%s'", job.GetName()) + } + jobNames[job.GetName()] = true + if !jobNameRE.MatchString(job.GetName()) { return fmt.Errorf("Invalid job name '%s'", job.GetName()) } diff --git a/config/config_test.go b/config/config_test.go index 79407f550..b2459229e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -60,6 +60,11 @@ var configTests = []struct { shouldFail: true, errContains: "Specified both DNS-SD name and target group", }, + { + inputFile: "repeated_job_name.conf.input", + shouldFail: true, + errContains: "Found multiple jobs configured with the same name: 'testjob1'", + }, } func TestConfigs(t *testing.T) { diff --git a/config/fixtures/repeated_job_name.conf.input b/config/fixtures/repeated_job_name.conf.input new file mode 100644 index 000000000..c59486219 --- /dev/null +++ b/config/fixtures/repeated_job_name.conf.input @@ -0,0 +1,11 @@ +job: < + name: "testjob1" +> + +job: < + name: "testjob2" +> + +job: < + name: "testjob1" +>