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