Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
validate get step names, not resources; add test
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed Jan 4, 2017
1 parent e5ccd5e commit 67ccc8b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
6 changes: 3 additions & 3 deletions validate.go
Expand Up @@ -222,12 +222,12 @@ func validateJobs(c Config) ([]Warning, error) {

encountered := map[string]int{}
for _, input := range job.Inputs() {
encountered[input.ResourceName()]++
encountered[input.Get]++

if encountered[input.ResourceName()] == 2 {
if encountered[input.Get] == 2 {
errorMessages = append(
errorMessages,
identifier+fmt.Sprintf(" has get steps with the same name: %s", input.ResourceName()),
fmt.Sprintf("%s has get steps with the same name: %s", identifier, input.Get),
)
}
}
Expand Down
43 changes: 42 additions & 1 deletion validate_test.go
@@ -1,9 +1,10 @@
package atc_test

import (
. "github.com/concourse/atc"
"strings"

. "github.com/concourse/atc"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -443,6 +444,46 @@ var _ = Describe("ValidateConfig", func() {
})
})

Context("when a job has duplicate inputs with different resources", func() {
BeforeEach(func() {
job.Plan = append(job.Plan, PlanConfig{
Get: "some-resource",
Resource: "a",
})
job.Plan = append(job.Plan, PlanConfig{
Get: "some-resource",
Resource: "b",
})

config.Jobs = append(config.Jobs, job)
})

It("returns a single error", func() {
Expect(errorMessages).To(HaveLen(1))
Expect(errorMessages[0]).To(ContainSubstring("invalid jobs:"))
Expect(strings.Count(errorMessages[0], "has get steps with the same name: some-resource")).To(Equal(1))
})
})

Context("when a job gets the same resource multiple times but with different names", func() {
BeforeEach(func() {
job.Plan = append(job.Plan, PlanConfig{
Get: "a",
Resource: "some-resource",
})
job.Plan = append(job.Plan, PlanConfig{
Get: "b",
Resource: "some-resource",
})

config.Jobs = append(config.Jobs, job)
})

It("returns no errors", func() {
Expect(errorMessages).To(HaveLen(0))
})
})

Context("when a job has duplicate inputs via aggregate", func() {
BeforeEach(func() {
job.Plan = append(job.Plan, PlanConfig{
Expand Down

0 comments on commit 67ccc8b

Please sign in to comment.