From 78ebc1a61f1c56746ecf16b5d61424e37e14897c Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 3 Dec 2013 11:59:38 +0100 Subject: [PATCH] Ensure that job names are unique in parsed configs. Change-Id: I6bd89e6401bd924315981db797af21bdf0b81252 --- config/config.go | 6 ++++++ config/config_test.go | 5 +++++ config/fixtures/repeated_job_name.conf.input | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 config/fixtures/repeated_job_name.conf.input 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" +>