github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/purge_service_offering_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("purge-service-offering command", func() {
    13  	Describe("help", func() {
    14  		matchHelpMessage := SatisfyAll(
    15  			Say("NAME:"),
    16  			Say("purge-service-offering - Recursively remove a service offering and child objects from Cloud Foundry database without making requests to a service broker"),
    17  			Say("USAGE:"),
    18  			Say(`cf purge-service-offering SERVICE_OFFERING \[-b BROKER\] \[-f\]`),
    19  			Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service offering will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."),
    20  			Say("OPTIONS:"),
    21  			Say("-b\\s+Purge a service offering from a particular service broker. Required when service offering name is ambiguous"),
    22  			Say("-f\\s+Force deletion without confirmation"),
    23  			Say("SEE ALSO:"),
    24  			Say("marketplace, purge-service-instance, service-brokers"),
    25  		)
    26  
    27  		When("the --help flag is set", func() {
    28  			It("displays command usage to output", func() {
    29  				session := helpers.CF("purge-service-offering", "--help")
    30  
    31  				Eventually(session).Should(Exit(0))
    32  				Expect(session.Out).To(matchHelpMessage)
    33  			})
    34  		})
    35  
    36  		When("no args are passed", func() {
    37  			It("displays an error message with help text", func() {
    38  				session := helpers.CF("purge-service-offering")
    39  
    40  				Eventually(session).Should(Exit(1))
    41  				Expect(session.Err).To(Say("Incorrect Usage: the required argument `SERVICE_OFFERING` was not provided"))
    42  				Expect(session.Out).To(matchHelpMessage)
    43  			})
    44  		})
    45  
    46  		When("more than required number of args are passed", func() {
    47  			It("displays an error message with help text and exits 1", func() {
    48  				session := helpers.CF("purge-service-offering", "service-name", "extra")
    49  
    50  				Eventually(session).Should(Exit(1))
    51  				Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "extra"`))
    52  				Expect(session.Out).To(matchHelpMessage)
    53  			})
    54  		})
    55  	})
    56  
    57  	When("logged in", func() {
    58  		var orgName, spaceName string
    59  
    60  		BeforeEach(func() {
    61  			orgName = helpers.NewOrgName()
    62  			spaceName = helpers.NewSpaceName()
    63  			helpers.SetupCF(orgName, spaceName)
    64  		})
    65  
    66  		AfterEach(func() {
    67  			helpers.QuickDeleteOrg(orgName)
    68  		})
    69  
    70  		When("the service exists", func() {
    71  			var broker *servicebrokerstub.ServiceBrokerStub
    72  
    73  			BeforeEach(func() {
    74  				broker = servicebrokerstub.EnableServiceAccess()
    75  			})
    76  
    77  			AfterEach(func() {
    78  				broker.Forget()
    79  			})
    80  
    81  			It("purges the service offering and plans", func() {
    82  				session := helpers.CF("purge-service-offering", broker.FirstServiceOfferingName(), "-f")
    83  				Eventually(session).Should(Exit(0))
    84  
    85  				Expect(session).To(Say(`Purging service offering %s\.\.\.`, broker.FirstServiceOfferingName()))
    86  				Expect(session).To(Say(`OK`))
    87  
    88  				session = helpers.CF("marketplace")
    89  				Eventually(session).Should(Exit(0))
    90  				Expect(session).NotTo(Say(broker.FirstServiceOfferingName()))
    91  				Expect(session).NotTo(Say(broker.FirstServicePlanName()))
    92  			})
    93  
    94  			When("the service name is ambiguous", func() {
    95  				var secondBroker *servicebrokerstub.ServiceBrokerStub
    96  
    97  				BeforeEach(func() {
    98  					secondBroker = servicebrokerstub.New()
    99  					secondBroker.Services[0].Name = broker.FirstServiceOfferingName()
   100  					secondBroker.Create().Register().EnableServiceAccess()
   101  				})
   102  
   103  				AfterEach(func() {
   104  					secondBroker.Forget()
   105  				})
   106  
   107  				It("fails, asking the user to disambiguate", func() {
   108  					session := helpers.CF("purge-service-offering", broker.FirstServiceOfferingName(), "-f")
   109  					Eventually(session).Should(Exit(1))
   110  					Expect(session.Err).To(Say(`Service '%s' is provided by multiple service brokers: %s, %s`, broker.FirstServiceOfferingName(), broker.Name, secondBroker.Name))
   111  					Expect(session.Err).To(Say(`Specify a broker by using the '-b' flag.`))
   112  				})
   113  			})
   114  		})
   115  
   116  		When("the service does not exist", func() {
   117  			It("succeeds, printing a message", func() {
   118  				session := helpers.CF("purge-service-offering", "no-such-service", "-f")
   119  
   120  				Eventually(session).Should(Exit(0))
   121  				Expect(session.Out).To(Say(`Service offering 'no-such-service' not found.`))
   122  				Expect(session.Out).To(Say(`OK`))
   123  			})
   124  		})
   125  	})
   126  
   127  	When("the environment is not targeted correctly", func() {
   128  		It("fails with the appropriate errors", func() {
   129  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "purge-service-offering", "-f", "foo")
   130  		})
   131  	})
   132  })