Ensure that job names are unique in parsed configs.
Change-Id: I6bd89e6401bd924315981db797af21bdf0b81252
This commit is contained in:
parent
740d448983
commit
78ebc1a61f
|
@ -69,7 +69,13 @@ func (c Config) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check each job configuration for validity.
|
// Check each job configuration for validity.
|
||||||
|
jobNames := map[string]bool{}
|
||||||
for _, job := range c.Job {
|
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()) {
|
if !jobNameRE.MatchString(job.GetName()) {
|
||||||
return fmt.Errorf("Invalid job name '%s'", job.GetName())
|
return fmt.Errorf("Invalid job name '%s'", job.GetName())
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,11 @@ var configTests = []struct {
|
||||||
shouldFail: true,
|
shouldFail: true,
|
||||||
errContains: "Specified both DNS-SD name and target group",
|
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) {
|
func TestConfigs(t *testing.T) {
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
job: <
|
||||||
|
name: "testjob1"
|
||||||
|
>
|
||||||
|
|
||||||
|
job: <
|
||||||
|
name: "testjob2"
|
||||||
|
>
|
||||||
|
|
||||||
|
job: <
|
||||||
|
name: "testjob1"
|
||||||
|
>
|
Loading…
Reference in New Issue