github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/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(Say("FAILED"))
    54  				Eventually(session.Err).Should(Say("Service broker 'does-not-exist' not found."))
    55  				Eventually(session).Should(Exit(1))
    56  			})
    57  		})
    58  
    59  		When("the rename fails", func() {
    60  			It("prints an error message", func() {
    61  				originalName := helpers.NewServiceBrokerName()
    62  
    63  				broker1 := fakeservicebroker.New().EnsureBrokerIsAvailable()
    64  				broker2 := fakeservicebroker.New().WithName(originalName).EnsureBrokerIsAvailable()
    65  				defer broker2.Destroy()
    66  
    67  				session := helpers.CF("rename-service-broker", broker2.Name(), broker1.Name())
    68  
    69  				Eventually(session.Wait().Out).Should(SatisfyAll(
    70  					Say("Renaming service broker %s to %s as %s", broker2.Name(), broker1.Name(), cfUsername),
    71  					Say("FAILED"),
    72  				))
    73  				Eventually(session.Err).Should(Say("Name must be unique"))
    74  				Eventually(session).Should(Exit(1))
    75  			})
    76  		})
    77  	})
    78  
    79  	When("passing incorrect parameters", func() {
    80  		It("prints an error message", func() {
    81  			session := helpers.CF("rename-service-broker")
    82  
    83  			Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SERVICE_BROKER` and `NEW_SERVICE_BROKER` were not provided"))
    84  			eventuallyRendersRenameServiceBrokerHelp(session)
    85  			Eventually(session).Should(Exit(1))
    86  		})
    87  	})
    88  
    89  	When("the environment is not targeted correctly", func() {
    90  		It("fails with the appropriate errors", func() {
    91  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "rename-service-broker", "foo", "bar")
    92  		})
    93  	})
    94  
    95  	When("passing --help", func() {
    96  		It("displays command usage to output", func() {
    97  			session := helpers.CF("rename-service-broker", "--help")
    98  
    99  			eventuallyRendersRenameServiceBrokerHelp(session)
   100  			Eventually(session).Should(Exit(0))
   101  		})
   102  	})
   103  })
   104  
   105  func eventuallyRendersRenameServiceBrokerHelp(s *Session) {
   106  	Eventually(s).Should(Say("NAME:"))
   107  	Eventually(s).Should(Say("rename-service-broker - Rename a service broker"))
   108  	Eventually(s).Should(Say("USAGE:"))
   109  	Eventually(s).Should(Say("cf rename-service-broker SERVICE_BROKER NEW_SERVICE_BROKER"))
   110  	Eventually(s).Should(Say("SEE ALSO:"))
   111  	Eventually(s).Should(Say("service-brokers, update-service-broker"))
   112  }