Skip to content

Commit

Permalink
Fix manifest validation for random-route (#2635)
Browse files Browse the repository at this point in the history
The validator was always raising the following error
when random-route was specified:

"default-route and random-route may not be used together"

This change makes it so that it only errors when both default-route
and random-route are set to true.

Authored-by: Tim Downey <[email protected]>
  • Loading branch information
tcdowney authored Jun 23, 2023
1 parent 7a522fd commit 32b874e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/payloads/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (m Manifest) Validate() error {
func (a ManifestApplication) Validate() error {
return validation.ValidateStruct(&a,
validation.Field(&a.Name, payload_validation.StrictlyRequired),
validation.Field(&a.DefaultRoute, validation.When(a.RandomRoute, validation.Nil.Error("and random-route may not be used together"))),
validation.Field(&a.DefaultRoute, validation.When(a.RandomRoute && a.DefaultRoute, validation.Nil.Error("and random-route may not be used together"))),
validation.Field(&a.DiskQuota, validation.By(validateAmountWithUnit), validation.When(a.AltDiskQuota != nil, validation.Nil.Error("and disk-quota may not be used together"))),
validation.Field(&a.AltDiskQuota, validation.By(validateAmountWithUnit)),
validation.Field(&a.Instances, validation.Min(0)),
Expand Down
11 changes: 11 additions & 0 deletions api/payloads/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ var _ = Describe("Manifest payload", func() {
Expect(validateErr).To(MatchError("default-route: and random-route may not be used together."))
})
})

When("only the random-route flag is set", func() {
BeforeEach(func() {
testManifest.DefaultRoute = false
testManifest.RandomRoute = true
})

It("does not return a validation error", func() {
Expect(validateErr).NotTo(HaveOccurred())
})
})
})
})

Expand Down

0 comments on commit 32b874e

Please sign in to comment.