github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/isolated/update_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 . "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("update-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("updates the service broker", func() { 29 broker1 := fakeservicebroker.New().EnsureBrokerIsAvailable() 30 broker2 := fakeservicebroker.New().WithName("single-use").EnsureAppIsDeployed() 31 defer broker2.Destroy() 32 33 session := helpers.CF("update-service-broker", broker1.Name(), broker2.Username(), broker2.Password(), broker2.URL()) 34 35 Eventually(session.Wait().Out).Should(SatisfyAll( 36 Say("Updating service broker %s as %s...", broker1.Name(), cfUsername), 37 Say("OK"), 38 )) 39 Eventually(session).Should(Exit(0)) 40 session = helpers.CF("service-brokers") 41 Eventually(session.Out).Should(Say("%s[[:space:]]+%s", broker1.Name(), broker2.URL())) 42 }) 43 44 When("the service broker doesn't exist", func() { 45 It("prints an error message", func() { 46 session := helpers.CF("update-service-broker", "does-not-exist", "test-user", "test-password", "http://test.com") 47 48 Eventually(session).Should(SatisfyAll( 49 Say("FAILED"), 50 Say("Service Broker does-not-exist not found"), 51 )) 52 Eventually(session).Should(Exit(1)) 53 }) 54 }) 55 56 When("the update fails", func() { 57 It("prints an error message", func() { 58 broker := fakeservicebroker.New().EnsureBrokerIsAvailable() 59 60 session := helpers.CF("update-service-broker", broker.Name(), broker.Username(), broker.Password(), "not-a-valid-url") 61 62 Eventually(session.Wait().Out).Should(SatisfyAll( 63 Say("Updating service broker %s as %s...", broker.Name(), cfUsername), 64 Say("FAILED"), 65 Say("Server error, status code: 400, error code: 270011, message: not-a-valid-url is not a valid URL"), 66 )) 67 Eventually(session).Should(Exit(1)) 68 }) 69 }) 70 }) 71 72 When("passing incorrect parameters", func() { 73 It("prints an error message", func() { 74 session := helpers.CF("update-service-broker", "b1") 75 76 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `USERNAME`, `PASSWORD` and `URL` were not provided")) 77 eventuallyRendersUpdateServiceBrokerHelp(session) 78 Eventually(session).Should(Exit(1)) 79 }) 80 }) 81 82 When("the environment is not targeted correctly", func() { 83 It("fails with the appropriate errors", func() { 84 helpers.UnrefactoredCheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "update-service-broker", "broker-name", "username", "password", "https://test.com") 85 }) 86 }) 87 88 When("passing --help", func() { 89 It("displays command usage to output", func() { 90 session := helpers.CF("update-service-broker", "--help") 91 92 eventuallyRendersUpdateServiceBrokerHelp(session) 93 Eventually(session).Should(Exit(0)) 94 }) 95 }) 96 }) 97 98 func eventuallyRendersUpdateServiceBrokerHelp(s *Session) { 99 Eventually(s).Should(Say("NAME:")) 100 Eventually(s).Should(Say("update-service-broker - Update a service broker")) 101 Eventually(s).Should(Say("USAGE:")) 102 Eventually(s).Should(Say("cf update-service-broker SERVICE_BROKER USERNAME PASSWORD URL")) 103 Eventually(s).Should(Say("SEE ALSO:")) 104 Eventually(s).Should(Say("rename-service-broker, service-brokers")) 105 }