github.com/sleungcy/cli@v7.1.0+incompatible/actor/v7pushaction/handle_random_route_override_test.go (about) 1 package v7pushaction_test 2 3 import ( 4 "code.cloudfoundry.org/cli/command/translatableerror" 5 "code.cloudfoundry.org/cli/util/manifestparser" 6 7 . "code.cloudfoundry.org/cli/actor/v7pushaction" 8 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("HandleRandomRouteOverride", func() { 14 var ( 15 originalManifest manifestparser.Manifest 16 transformedManifest manifestparser.Manifest 17 overrides FlagOverrides 18 executeErr error 19 ) 20 21 BeforeEach(func() { 22 originalManifest = manifestparser.Manifest{} 23 overrides = FlagOverrides{} 24 }) 25 26 JustBeforeEach(func() { 27 transformedManifest, executeErr = HandleRandomRouteOverride(originalManifest, overrides) 28 }) 29 30 When("manifest app does not specify random-route", func() { 31 BeforeEach(func() { 32 originalManifest.Applications = []manifestparser.Application{ 33 {}, 34 } 35 }) 36 37 When("random-route is not set on the flag overrides", func() { 38 It("does not change the manifest", func() { 39 Expect(executeErr).ToNot(HaveOccurred()) 40 Expect(transformedManifest.Applications).To(ConsistOf( 41 manifestparser.Application{}, 42 )) 43 }) 44 }) 45 46 When("random-route is set on the flag overrides", func() { 47 BeforeEach(func() { 48 overrides.RandomRoute = true 49 }) 50 51 It("changes the random-route field of the only app in the manifest", func() { 52 Expect(executeErr).ToNot(HaveOccurred()) 53 Expect(transformedManifest.Applications).To(ConsistOf( 54 manifestparser.Application{ 55 RandomRoute: true, 56 }, 57 )) 58 }) 59 }) 60 }) 61 62 When("random-route flag is set and there are multiple apps in the manifest", func() { 63 BeforeEach(func() { 64 overrides.RandomRoute = true 65 66 originalManifest.Applications = []manifestparser.Application{ 67 {}, 68 {}, 69 } 70 }) 71 72 It("returns an error", func() { 73 Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{})) 74 }) 75 }) 76 })