github.com/sleungcy/cli@v7.1.0+incompatible/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 When("the --help flag is set", func() { 15 It("displays command usage to output", func() { 16 session := helpers.CF("purge-service-offering", "--help") 17 18 Eventually(session).Should(Exit(0)) 19 Expect(session).To(Say("NAME:")) 20 Expect(session).To(Say("purge-service-offering - Recursively remove a service offering and child objects from Cloud Foundry database without making requests to a service broker")) 21 Expect(session).To(Say("USAGE:")) 22 Expect(session).To(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-f\]`)) 23 Expect(session).To(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\\.")) 24 Expect(session).To(Say("OPTIONS:")) 25 Expect(session).To(Say("-b\\s+Purge a service offering from a particular service broker. Required when service offering name is ambiguous")) 26 Expect(session).To(Say("-f\\s+Force deletion without confirmation")) 27 Expect(session).To(Say("SEE ALSO:")) 28 Expect(session).To(Say("marketplace, purge-service-instance, service-brokers")) 29 }) 30 }) 31 32 When("no args are passed", func() { 33 It("displays an error message with help text", func() { 34 session := helpers.CF("purge-service-offering") 35 36 Eventually(session).Should(Exit(1)) 37 38 Expect(session.Err).To(Say("Incorrect Usage: the required argument `SERVICE` was not provided")) 39 Expect(session).To(Say("NAME:")) 40 Expect(session).To(Say("purge-service-offering - Recursively remove a service offering and child objects from Cloud Foundry database without making requests to a service broker")) 41 Expect(session).To(Say("USAGE:")) 42 Expect(session).To(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-f\]`)) 43 Expect(session).To(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\\.")) 44 Expect(session).To(Say("OPTIONS:")) 45 Expect(session).To(Say("-b\\s+Purge a service offering from a particular service broker. Required when service offering name is ambiguous")) 46 Expect(session).To(Say("-f\\s+Force deletion without confirmation")) 47 Expect(session).To(Say("SEE ALSO:")) 48 Expect(session).To(Say("marketplace, purge-service-instance, service-brokers")) 49 }) 50 }) 51 52 When("more than required number of args are passed", func() { 53 It("displays an error message with help text and exits 1", func() { 54 session := helpers.CF("purge-service-offering", "service-name", "extra") 55 56 Eventually(session).Should(Exit(1)) 57 Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "extra"`)) 58 Expect(session).To(Say("NAME:")) 59 Expect(session).To(Say("purge-service-offering - Recursively remove a service offering and child objects from Cloud Foundry database without making requests to a service broker")) 60 Expect(session).To(Say("USAGE:")) 61 Expect(session).To(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-f\]`)) 62 Expect(session).To(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\\.")) 63 Expect(session).To(Say("OPTIONS:")) 64 Expect(session).To(Say("-b\\s+Purge a service offering from a particular service broker. Required when service offering name is ambiguous")) 65 Expect(session).To(Say("-f\\s+Force deletion without confirmation")) 66 Expect(session).To(Say("SEE ALSO:")) 67 Expect(session).To(Say("marketplace, purge-service-instance, service-brokers")) 68 }) 69 }) 70 }) 71 72 When("logged in", func() { 73 var orgName, spaceName string 74 75 BeforeEach(func() { 76 orgName = helpers.NewOrgName() 77 spaceName = helpers.NewSpaceName() 78 helpers.SetupCF(orgName, spaceName) 79 }) 80 81 AfterEach(func() { 82 helpers.QuickDeleteOrg(orgName) 83 }) 84 85 When("the service exists", func() { 86 var broker *servicebrokerstub.ServiceBrokerStub 87 88 BeforeEach(func() { 89 broker = servicebrokerstub.EnableServiceAccess() 90 }) 91 92 AfterEach(func() { 93 broker.Forget() 94 }) 95 96 It("purges the service offering and plans", func() { 97 session := helpers.CF("purge-service-offering", broker.FirstServiceOfferingName(), "-f") 98 Eventually(session).Should(Exit(0)) 99 100 Expect(session).To(Say(`Purging service offering %s\.\.\.`, broker.FirstServiceOfferingName())) 101 Expect(session).To(Say(`OK`)) 102 103 session = helpers.CF("marketplace") 104 Eventually(session).Should(Exit(0)) 105 Expect(session).NotTo(Say(broker.FirstServiceOfferingName())) 106 Expect(session).NotTo(Say(broker.FirstServicePlanName())) 107 }) 108 109 When("the service name is ambiguous", func() { 110 var secondBroker *servicebrokerstub.ServiceBrokerStub 111 112 BeforeEach(func() { 113 secondBroker = servicebrokerstub.New() 114 secondBroker.Services[0].Name = broker.FirstServiceOfferingName() 115 secondBroker.Create().Register().EnableServiceAccess() 116 }) 117 118 AfterEach(func() { 119 secondBroker.Forget() 120 }) 121 122 It("fails, asking the user to disambiguate", func() { 123 session := helpers.CF("purge-service-offering", broker.FirstServiceOfferingName(), "-f") 124 Eventually(session).Should(Exit(1)) 125 Expect(session.Err).To(Say(`Service '%s' is provided by multiple service brokers: %s, %s`, broker.FirstServiceOfferingName(), broker.Name, secondBroker.Name)) 126 Expect(session.Err).To(Say(`Specify a broker by using the '-b' flag.`)) 127 }) 128 }) 129 }) 130 131 When("the service does not exist", func() { 132 It("succeeds, printing a message", func() { 133 session := helpers.CF("purge-service-offering", "no-such-service", "-f") 134 135 Eventually(session).Should(Exit(0)) 136 Expect(session.Out).To(Say(`Service offering 'no-such-service' not found.`)) 137 Expect(session.Out).To(Say(`OK`)) 138 }) 139 }) 140 }) 141 142 When("the environment is not targeted correctly", func() { 143 It("fails with the appropriate errors", func() { 144 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "purge-service-offering", "-f", "foo") 145 }) 146 }) 147 })