github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/delete_service_broker_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	"code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub"
     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("delete-service-broker command", func() {
    14  	Context("Help", func() {
    15  		It("appears in cf help -a", func() {
    16  			session := helpers.CF("help", "-a")
    17  			Eventually(session).Should(Exit(0))
    18  			Expect(session).To(HaveCommandInCategoryWithDescription("delete-service-broker", "SERVICE ADMIN", "Delete a service broker"))
    19  		})
    20  
    21  		It("displays the help information", func() {
    22  			session := helpers.CF("delete-service-broker", "--help")
    23  			Eventually(session).Should(Say(`NAME:`))
    24  			Eventually(session).Should(Say(`delete-service-broker - Delete a service broker\n`))
    25  			Eventually(session).Should(Say(`\n`))
    26  
    27  			Eventually(session).Should(Say(`USAGE:`))
    28  			Eventually(session).Should(Say(`cf delete-service-broker SERVICE_BROKER \[-f\]\n`))
    29  			Eventually(session).Should(Say(`\n`))
    30  
    31  			Eventually(session).Should(Say(`OPTIONS:`))
    32  			Eventually(session).Should(Say(`-f\s+Force deletion without confirmation`))
    33  			Eventually(session).Should(Say(`\n`))
    34  
    35  			Eventually(session).Should(Say(`SEE ALSO:`))
    36  			Eventually(session).Should(Say(`delete-service, purge-service-offering, service-brokers`))
    37  
    38  			Eventually(session).Should(Exit(0))
    39  		})
    40  	})
    41  
    42  	When("an api is targeted and the user is logged in", func() {
    43  		BeforeEach(func() {
    44  			helpers.LoginCF()
    45  		})
    46  
    47  		When("there is a service broker without any instances", func() {
    48  			var (
    49  				orgName string
    50  				broker  *servicebrokerstub.ServiceBrokerStub
    51  			)
    52  
    53  			BeforeEach(func() {
    54  				orgName = helpers.NewOrgName()
    55  				helpers.SetupCF(orgName, helpers.NewSpaceName())
    56  				broker = servicebrokerstub.EnableServiceAccess()
    57  			})
    58  
    59  			AfterEach(func() {
    60  				helpers.QuickDeleteOrg(orgName)
    61  				broker.Forget()
    62  			})
    63  
    64  			It("should delete the service broker", func() {
    65  				session := helpers.CF("delete-service-broker", broker.Name, "-f", "-v")
    66  				Eventually(session).Should(Exit(0))
    67  
    68  				session = helpers.CF("service-brokers")
    69  				Consistently(session).ShouldNot(Say(broker.Name))
    70  				Eventually(session).Should(Exit(0))
    71  
    72  				session = helpers.CF("marketplace")
    73  				Consistently(session).ShouldNot(Say(broker.FirstServiceOfferingName()))
    74  				Consistently(session).ShouldNot(Say(broker.FirstServicePlanName()))
    75  				Eventually(session).Should(Exit(0))
    76  			})
    77  		})
    78  
    79  		When("there is a service broker with a service instance", func() {
    80  			var (
    81  				orgName string
    82  				broker  *servicebrokerstub.ServiceBrokerStub
    83  			)
    84  
    85  			BeforeEach(func() {
    86  				orgName = helpers.NewOrgName()
    87  				helpers.SetupCF(orgName, helpers.NewSpaceName())
    88  				broker = servicebrokerstub.EnableServiceAccess()
    89  
    90  				serviceName := helpers.NewServiceInstanceName()
    91  				session := helpers.CF("create-service", broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), serviceName)
    92  				Eventually(session).Should(Exit(0))
    93  			})
    94  
    95  			AfterEach(func() {
    96  				helpers.QuickDeleteOrg(orgName)
    97  				broker.Forget()
    98  			})
    99  
   100  			It("should fail to delete the service broker", func() {
   101  				session := helpers.CF("delete-service-broker", broker.Name, "-f")
   102  				Eventually(session.Err).Should(Say("Can not remove brokers that have associated service instances"))
   103  				Eventually(session).Should(Exit(1))
   104  
   105  				session = helpers.CF("service-brokers")
   106  				Eventually(session).Should(Say(broker.Name))
   107  				Eventually(session).Should(Exit(0))
   108  
   109  				session = helpers.CF("marketplace")
   110  				Eventually(session).Should(Say(broker.FirstServiceOfferingName()))
   111  				Eventually(session).Should(Say(broker.FirstServicePlanName()))
   112  				Eventually(session).Should(Exit(0))
   113  			})
   114  		})
   115  
   116  		When("the service broker doesn't exist", func() {
   117  			It("should exit 0 (idempotent case)", func() {
   118  				session := helpers.CF("delete-service-broker", "not-a-broker", "-f")
   119  				Eventually(session).Should(Say(`Service broker 'not-a-broker' does not exist.`))
   120  				Eventually(session).Should(Exit(0))
   121  			})
   122  		})
   123  
   124  		When("the service broker is not specified", func() {
   125  			It("displays error and exits 1", func() {
   126  				session := helpers.CF("delete-service-broker")
   127  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SERVICE_BROKER` was not provided\n"))
   128  				Eventually(session.Err).Should(Say("\n"))
   129  				Eventually(session).Should(Say("NAME:\n"))
   130  				Eventually(session).Should(Exit(1))
   131  			})
   132  		})
   133  	})
   134  })