Ensure that job names are unique in parsed configs.

Change-Id: I6bd89e6401bd924315981db797af21bdf0b81252
This commit is contained in:
Julius Volz 2013-12-03 11:59:38 +01:00
parent 740d448983
commit 78ebc1a61f
3 changed files with 22 additions and 0 deletions

View File

@ -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())
}

View File

@ -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) {

View File

@ -0,0 +1,11 @@
job: <
name: "testjob1"
>
job: <
name: "testjob2"
>
job: <
name: "testjob1"
>