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