github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/isolated/rename_service_broker_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gbytes" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 var _ = Describe("rename-service-broker command", func() { 13 When("logged in", func() { 14 var ( 15 org string 16 cfUsername string 17 ) 18 19 BeforeEach(func() { 20 org = helpers.SetupCFWithGeneratedOrgAndSpaceNames() 21 cfUsername, _ = helpers.GetCredentials() 22 }) 23 24 AfterEach(func() { 25 helpers.QuickDeleteOrg(org) 26 }) 27 28 It("renames the service broker", func() { 29 originalName := helpers.NewServiceBrokerName() 30 updatedName := helpers.NewServiceBrokerName() 31 32 broker := servicebrokerstub.New().WithName(originalName).Create().Register() 33 defer broker.Forget() 34 35 session := helpers.CF("rename-service-broker", originalName, updatedName) 36 37 Eventually(session.Wait().Out).Should(SatisfyAll( 38 Say("Renaming service broker %s to %s as %s", originalName, updatedName, cfUsername), 39 Say("OK"), 40 )) 41 Eventually(session).Should(Exit(0)) 42 session = helpers.CF("service-brokers") 43 Eventually(session.Out).Should(Say(updatedName)) 44 45 broker.WithName(updatedName) // Forget() needs to know the new name 46 }) 47 48 When("the service broker doesn't exist", func() { 49 It("prints an error message", func() { 50 session := helpers.CF("rename-service-broker", "does-not-exist", "new-name") 51 52 Eventually(session).Should(Say("FAILED")) 53 Eventually(session.Err).Should(Say("Service broker 'does-not-exist' not found.")) 54 Eventually(session).Should(Exit(1)) 55 }) 56 }) 57 58 When("the rename fails", func() { 59 It("prints an error message", func() { 60 originalName := helpers.NewServiceBrokerName() 61 62 broker1 := servicebrokerstub.New().Create().Register() 63 broker2 := servicebrokerstub.New().WithName(originalName).Create().Register() 64 defer broker1.Forget() 65 defer broker2.Forget() 66 67 session := helpers.CF("rename-service-broker", broker2.Name, broker1.Name) 68 69 Eventually(session.Wait().Out).Should(SatisfyAll( 70 Say("Renaming service broker %s to %s as %s", broker2.Name, broker1.Name, cfUsername), 71 Say("FAILED"), 72 )) 73 Eventually(session.Err).Should(Say("Name must be unique")) 74 Eventually(session).Should(Exit(1)) 75 }) 76 }) 77 }) 78 79 When("passing incorrect parameters", func() { 80 It("prints an error message", func() { 81 session := helpers.CF("rename-service-broker") 82 83 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SERVICE_BROKER` and `NEW_SERVICE_BROKER` were not provided")) 84 eventuallyRendersRenameServiceBrokerHelp(session) 85 Eventually(session).Should(Exit(1)) 86 }) 87 }) 88 89 When("the environment is not targeted correctly", func() { 90 It("fails with the appropriate errors", func() { 91 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "rename-service-broker", "foo", "bar") 92 }) 93 }) 94 95 When("passing --help", func() { 96 It("displays command usage to output", func() { 97 session := helpers.CF("rename-service-broker", "--help") 98 99 eventuallyRendersRenameServiceBrokerHelp(session) 100 Eventually(session).Should(Exit(0)) 101 }) 102 }) 103 }) 104 105 func eventuallyRendersRenameServiceBrokerHelp(s *Session) { 106 Eventually(s).Should(Say("NAME:")) 107 Eventually(s).Should(Say("rename-service-broker - Rename a service broker")) 108 Eventually(s).Should(Say("USAGE:")) 109 Eventually(s).Should(Say("cf rename-service-broker SERVICE_BROKER NEW_SERVICE_BROKER")) 110 Eventually(s).Should(Say("SEE ALSO:")) 111 Eventually(s).Should(Say("service-brokers, update-service-broker")) 112 }