github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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/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 was updated but warnings happened", func() {
    45  			var (
    46  				serviceInstance string
    47  				broker          *fakeservicebroker.FakeServiceBroker
    48  			)
    49  
    50  			BeforeEach(func() {
    51  				// Note, because we re-configure the broker we should make sure that we don't use the re-usable one
    52  				broker = fakeservicebroker.New().WithName(helpers.NewServiceBrokerName()).EnsureBrokerIsAvailable()
    53  				broker.EnableServiceAccess()
    54  
    55  				serviceInstance = helpers.NewServiceInstanceName()
    56  				session := helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), serviceInstance, "-b", broker.Name())
    57  				Eventually(session).Should(Exit(0))
    58  
    59  				broker.Services[0].Plans[0].Name = "different-plan-name"
    60  				broker.Services[0].Plans[0].ID = "different-plan-id"
    61  				broker.Configure()
    62  			})
    63  
    64  			AfterEach(func() {
    65  				broker.Destroy()
    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 := fakeservicebroker.New().EnsureBrokerIsAvailable()
    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 *fakeservicebroker.FakeServiceBroker
   112  
   113  			BeforeEach(func() {
   114  				broker = fakeservicebroker.New().EnsureBrokerIsAvailable()
   115  				broker.WithCatalogStatus(500).Configure()
   116  			})
   117  
   118  			AfterEach(func() {
   119  				broker.WithCatalogStatus(200).Configure()
   120  				broker.Destroy()
   121  			})
   122  
   123  			It("prints an error message and the job guid", func() {
   124  				session := helpers.CF("update-service-broker", broker.Name(), broker.Username(), broker.Password(), broker.URL())
   125  
   126  				Eventually(session.Wait().Out).Should(SatisfyAll(
   127  					Say("Updating service broker %s as %s...", broker.Name(), cfUsername),
   128  					Say("FAILED"),
   129  				))
   130  
   131  				Eventually(session.Err).Should(SatisfyAll(
   132  					Say("Job (.*) failed"),
   133  					Say("The service broker returned an invalid response for the request "),
   134  					Say("Status Code: 500 Internal Server Error"),
   135  				))
   136  
   137  				Eventually(session).Should(Exit(1))
   138  			})
   139  		})
   140  	})
   141  
   142  	When("passing incorrect parameters", func() {
   143  		It("prints an error message", func() {
   144  			session := helpers.CF("update-service-broker", "b1")
   145  
   146  			Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `USERNAME`, `PASSWORD` and `URL` were not provided"))
   147  			eventuallyRendersUpdateServiceBrokerHelp(session)
   148  			Eventually(session).Should(Exit(1))
   149  		})
   150  	})
   151  
   152  	When("the environment is not targeted correctly", func() {
   153  		It("fails with the appropriate errors", func() {
   154  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "update-service-broker", "broker-name", "username", "password", "https://test.com")
   155  		})
   156  	})
   157  
   158  	When("passing --help", func() {
   159  		It("displays command usage to output", func() {
   160  			session := helpers.CF("update-service-broker", "--help")
   161  
   162  			eventuallyRendersUpdateServiceBrokerHelp(session)
   163  			Eventually(session).Should(Exit(0))
   164  		})
   165  	})
   166  })
   167  
   168  func eventuallyRendersUpdateServiceBrokerHelp(s *Session) {
   169  	Eventually(s).Should(Say("NAME:"))
   170  	Eventually(s).Should(Say("update-service-broker - Update a service broker"))
   171  	Eventually(s).Should(Say("USAGE:"))
   172  	Eventually(s).Should(Say("cf update-service-broker SERVICE_BROKER USERNAME PASSWORD URL"))
   173  	Eventually(s).Should(Say("SEE ALSO:"))
   174  	Eventually(s).Should(Say("rename-service-broker, service-brokers"))
   175  }