github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/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.Register()
    30  			broker2 := servicebrokerstub.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 was updated but warnings happened", func() {
    46  			var (
    47  				serviceInstance string
    48  				broker          *servicebrokerstub.ServiceBrokerStub
    49  			)
    50  
    51  			BeforeEach(func() {
    52  				broker = servicebrokerstub.EnableServiceAccess()
    53  
    54  				serviceInstance = helpers.NewServiceInstanceName()
    55  				session := helpers.CF("create-service", broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), serviceInstance, "-b", broker.Name)
    56  				Eventually(session).Should(Exit(0))
    57  
    58  				broker.Services[0].Plans[0].Name = "different-plan-name"
    59  				broker.Services[0].Plans[0].ID = "different-plan-id"
    60  				broker.Configure()
    61  			})
    62  
    63  			AfterEach(func() {
    64  				helpers.CF("delete-service", "-f", serviceInstance)
    65  				broker.Forget()
    66  			})
    67  
    68  			It("should yield a warning", func() {
    69  				session := helpers.CF("update-service-broker", broker.Name, broker.Username, broker.Password, broker.URL)
    70  
    71  				Eventually(session.Wait().Out).Should(SatisfyAll(
    72  					Say("Updating service broker %s as %s...", broker.Name, cfUsername),
    73  					Say("OK"),
    74  				))
    75  				Eventually(session.Err).Should(Say("Warning: Service plans are missing from the broker's catalog"))
    76  			})
    77  		})
    78  
    79  		When("the service broker doesn't exist", func() {
    80  			It("prints an error message", func() {
    81  				session := helpers.CF("update-service-broker", "does-not-exist", "test-user", "test-password", "http://test.com")
    82  
    83  				Eventually(session).Should(Say("FAILED"))
    84  				Eventually(session.Err).Should(SatisfyAll(
    85  					Say("Service broker 'does-not-exist' not found"),
    86  				))
    87  				Eventually(session).Should(Exit(1))
    88  			})
    89  		})
    90  
    91  		When("the update fails before starting a synchronization job", func() {
    92  			It("prints an error message", func() {
    93  				broker := servicebrokerstub.Register()
    94  
    95  				session := helpers.CF("update-service-broker", broker.Name, broker.Username, broker.Password, "not-a-valid-url")
    96  
    97  				Eventually(session.Wait().Out).Should(SatisfyAll(
    98  					Say("Updating service broker %s as %s...", broker.Name, cfUsername),
    99  					Say("FAILED"),
   100  				))
   101  
   102  				Eventually(session.Err).Should(
   103  					Say("must be a valid url"),
   104  				)
   105  
   106  				Eventually(session).Should(Exit(1))
   107  			})
   108  		})
   109  
   110  		When("the update fails after starting a synchronization job", func() {
   111  			var broker *servicebrokerstub.ServiceBrokerStub
   112  
   113  			BeforeEach(func() {
   114  				broker = servicebrokerstub.Register()
   115  				broker.WithCatalogResponse(500).Configure()
   116  			})
   117  
   118  			AfterEach(func() {
   119  				broker.Forget()
   120  			})
   121  
   122  			It("prints an error message and the job guid", func() {
   123  				session := helpers.CF("update-service-broker", broker.Name, broker.Username, broker.Password, broker.URL)
   124  
   125  				Eventually(session.Wait().Out).Should(SatisfyAll(
   126  					Say("Updating service broker %s as %s...", broker.Name, cfUsername),
   127  					Say("FAILED"),
   128  				))
   129  
   130  				Eventually(session.Err).Should(SatisfyAll(
   131  					Say("Job (.*) failed"),
   132  					Say("The service broker returned an invalid response"),
   133  					Say("Status Code: 500 Internal Server Error"),
   134  				))
   135  
   136  				Eventually(session).Should(Exit(1))
   137  			})
   138  		})
   139  	})
   140  
   141  	When("passing incorrect parameters", func() {
   142  		It("prints an error message", func() {
   143  			session := helpers.CF("update-service-broker", "b1")
   144  
   145  			Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `USERNAME`, `PASSWORD` and `URL` were not provided"))
   146  			eventuallyRendersUpdateServiceBrokerHelp(session)
   147  			Eventually(session).Should(Exit(1))
   148  		})
   149  	})
   150  
   151  	When("the environment is not targeted correctly", func() {
   152  		It("fails with the appropriate errors", func() {
   153  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "update-service-broker", "broker-name", "username", "password", "https://test.com")
   154  		})
   155  	})
   156  
   157  	When("passing --help", func() {
   158  		It("displays command usage to output", func() {
   159  			session := helpers.CF("update-service-broker", "--help")
   160  
   161  			eventuallyRendersUpdateServiceBrokerHelp(session)
   162  			Eventually(session).Should(Exit(0))
   163  		})
   164  	})
   165  })
   166  
   167  func eventuallyRendersUpdateServiceBrokerHelp(s *Session) {
   168  	Eventually(s).Should(Say("NAME:"))
   169  	Eventually(s).Should(Say("update-service-broker - Update a service broker"))
   170  	Eventually(s).Should(Say("USAGE:"))
   171  	Eventually(s).Should(Say("cf update-service-broker SERVICE_BROKER USERNAME PASSWORD URL"))
   172  	Eventually(s).Should(Say("SEE ALSO:"))
   173  	Eventually(s).Should(Say("rename-service-broker, service-brokers"))
   174  }