github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+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/fakeservicebroker" 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 := fakeservicebroker.New().WithName(originalName).EnsureBrokerIsAvailable() 34 defer broker.Destroy() 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) // Destroy() 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 originalName := helpers.NewServiceBrokerName() 64 65 broker1 := fakeservicebroker.New().EnsureBrokerIsAvailable() 66 broker2 := fakeservicebroker.New().WithName(originalName).EnsureBrokerIsAvailable() 67 defer broker2.Destroy() 68 69 session := helpers.CF("rename-service-broker", broker2.Name(), broker1.Name()) 70 71 Eventually(session.Wait().Out).Should(SatisfyAll( 72 Say("Renaming service broker %s to %s as %s", broker2.Name(), broker1.Name(), cfUsername), 73 Say("FAILED"), 74 Say("Server error, status code: 400, error code: 270002, message: The service broker name is taken"), 75 )) 76 Eventually(session).Should(Exit(1)) 77 }) 78 }) 79 }) 80 81 When("passing incorrect parameters", func() { 82 It("prints an error message", func() { 83 session := helpers.CF("rename-service-broker") 84 85 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SERVICE_BROKER` and `NEW_SERVICE_BROKER` were not provided")) 86 eventuallyRendersRenameServiceBrokerHelp(session) 87 Eventually(session).Should(Exit(1)) 88 }) 89 }) 90 91 When("the environment is not targeted correctly", func() { 92 It("fails with the appropriate errors", func() { 93 helpers.UnrefactoredCheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "rename-service-broker", "foo", "bar") 94 }) 95 }) 96 97 When("passing --help", func() { 98 It("displays command usage to output", func() { 99 session := helpers.CF("rename-service-broker", "--help") 100 101 eventuallyRendersRenameServiceBrokerHelp(session) 102 Eventually(session).Should(Exit(0)) 103 }) 104 }) 105 }) 106 107 func eventuallyRendersRenameServiceBrokerHelp(s *Session) { 108 Eventually(s).Should(Say("NAME:")) 109 Eventually(s).Should(Say("rename-service-broker - Rename a service broker")) 110 Eventually(s).Should(Say("USAGE:")) 111 Eventually(s).Should(Say("cf rename-service-broker SERVICE_BROKER NEW_SERVICE_BROKER")) 112 Eventually(s).Should(Say("SEE ALSO:")) 113 Eventually(s).Should(Say("service-brokers, update-service-broker")) 114 }