github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/shared/isolated/purge_service_offering_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 5 "code.cloudfoundry.org/cli/integration/helpers" 6 "code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker" 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("purge-service-offering command", func() { 14 Describe("help", func() { 15 When("the --help flag is set", func() { 16 It("displays command usage to output", func() { 17 session := helpers.CF("purge-service-offering", "--help") 18 19 Eventually(session).Should(Say("NAME:")) 20 Eventually(session).Should(Say("purge-service-offering - Recursively remove a service and child objects from Cloud Foundry database without making requests to a service broker")) 21 Eventually(session).Should(Say("USAGE:")) 22 Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-p PROVIDER\] \[-f\]`)) 23 Eventually(session).Should(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 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 Eventually(session).Should(Say("OPTIONS:")) 25 Eventually(session).Should(Say("-b\\s+Purge a service from a particular service broker. Required when service name is ambiguous")) 26 Eventually(session).Should(Say("-f\\s+Force deletion without confirmation")) 27 Eventually(session).Should(Say("-p\\s+Provider")) 28 Eventually(session).Should(Say("SEE ALSO:")) 29 Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers")) 30 Eventually(session).Should(Exit(0)) 31 }) 32 }) 33 34 When("no args are passed", func() { 35 It("displays an error message with help text", func() { 36 session := helpers.CF("purge-service-offering") 37 38 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SERVICE` was not provided")) 39 Eventually(session).Should(Say("NAME:")) 40 Eventually(session).Should(Say("purge-service-offering - Recursively remove a service and child objects from Cloud Foundry database without making requests to a service broker")) 41 Eventually(session).Should(Say("USAGE:")) 42 Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-p PROVIDER\] \[-f\]`)) 43 Eventually(session).Should(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 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 Eventually(session).Should(Say("OPTIONS:")) 45 Eventually(session).Should(Say("-b\\s+Purge a service from a particular service broker. Required when service name is ambiguous")) 46 Eventually(session).Should(Say("-f\\s+Force deletion without confirmation")) 47 Eventually(session).Should(Say("-p\\s+Provider")) 48 Eventually(session).Should(Say("SEE ALSO:")) 49 Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers")) 50 Eventually(session).Should(Exit(1)) 51 }) 52 }) 53 54 When("more than required number of args are passed", func() { 55 It("displays an error message with help text and exits 1", func() { 56 session := helpers.CF("purge-service-offering", "service-name", "extra") 57 58 Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "extra"`)) 59 Eventually(session).Should(Say("NAME:")) 60 Eventually(session).Should(Say("purge-service-offering - Recursively remove a service and child objects from Cloud Foundry database without making requests to a service broker")) 61 Eventually(session).Should(Say("USAGE:")) 62 Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-p PROVIDER\] \[-f\]`)) 63 Eventually(session).Should(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 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\\.")) 64 Eventually(session).Should(Say("OPTIONS:")) 65 Eventually(session).Should(Say("-b\\s+Purge a service from a particular service broker. Required when service name is ambiguous")) 66 Eventually(session).Should(Say("-f\\s+Force deletion without confirmation")) 67 Eventually(session).Should(Say("-p\\s+Provider")) 68 Eventually(session).Should(Say("SEE ALSO:")) 69 Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers")) 70 Eventually(session).Should(Exit(1)) 71 }) 72 }) 73 }) 74 75 When("service name is passed", func() { 76 When("an API target is not set", func() { 77 BeforeEach(func() { 78 helpers.UnsetAPI() 79 }) 80 81 It("displays an error message that no API endpoint is set", func() { 82 session := helpers.CF("purge-service-offering", "service-name") 83 84 Eventually(session).Should(Say("FAILED")) 85 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 86 Eventually(session).Should(Exit(1)) 87 }) 88 }) 89 90 When("user is not logged in", func() { 91 BeforeEach(func() { 92 helpers.LogoutCF() 93 }) 94 95 It("displays an error message that user is not logged in", func() { 96 session := helpers.CF("purge-service-offering", "service-name") 97 98 Eventually(session).Should(Say("FAILED")) 99 Eventually(session.Err).Should(Say(`Not logged in\. Use 'cf login' or 'cf login --sso' to log in\.`)) 100 Eventually(session).Should(Exit(1)) 101 }) 102 }) 103 104 When("user is logged in", func() { 105 BeforeEach(func() { 106 helpers.LoginCF() 107 }) 108 109 When("the service exists", func() { 110 var ( 111 orgName string 112 spaceName string 113 broker *fakeservicebroker.FakeServiceBroker 114 buffer *Buffer 115 ) 116 117 BeforeEach(func() { 118 buffer = NewBuffer() 119 120 orgName = helpers.NewOrgName() 121 spaceName = helpers.NewSpaceName() 122 helpers.SetupCF(orgName, spaceName) 123 124 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 125 }) 126 127 AfterEach(func() { 128 broker.Destroy() 129 helpers.QuickDeleteOrg(orgName) 130 }) 131 132 When("the user enters 'y'", func() { 133 BeforeEach(func() { 134 _, err := buffer.Write([]byte("y\n")) 135 Expect(err).ToNot(HaveOccurred()) 136 }) 137 138 It("purges the service offering, asking for confirmation", func() { 139 session := helpers.CFWithStdin(buffer, "purge-service-offering", broker.ServiceName()) 140 141 Eventually(session).Should(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 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\\.")) 142 Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", broker.ServiceName())) 143 Eventually(session).Should(Say("Purging service %s...", broker.ServiceName())) 144 Eventually(session).Should(Say("OK")) 145 Eventually(session).Should(Exit(0)) 146 147 session = helpers.CF("marketplace") 148 Eventually(session).Should(Say("OK")) 149 Consistently(session).ShouldNot(Say(broker.ServiceName())) 150 Eventually(session).Should(Exit(0)) 151 }) 152 }) 153 154 When("the user enters something other than 'y' or 'yes'", func() { 155 BeforeEach(func() { 156 _, err := buffer.Write([]byte("wat\n\n")) 157 Expect(err).ToNot(HaveOccurred()) 158 }) 159 160 It("asks again", func() { 161 session := helpers.CFWithStdin(buffer, "purge-service-offering", broker.ServiceName()) 162 163 Eventually(session).Should(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 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\\.")) 164 Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", broker.ServiceName())) 165 Eventually(session).Should(Say(`invalid input \(not y, n, yes, or no\)`)) 166 Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", broker.ServiceName())) 167 Eventually(session).Should(Exit(0)) 168 }) 169 }) 170 171 When("the user enters 'n' or 'no'", func() { 172 BeforeEach(func() { 173 _, err := buffer.Write([]byte("n\n")) 174 Expect(err).ToNot(HaveOccurred()) 175 }) 176 177 It("does not purge the service offering", func() { 178 session := helpers.CFWithStdin(buffer, "purge-service-offering", broker.ServiceName()) 179 180 Eventually(session).Should(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 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\\.")) 181 Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", broker.ServiceName())) 182 Eventually(session).ShouldNot(Say("Purging service %s...", broker.ServiceName())) 183 Eventually(session).ShouldNot(Say("OK")) 184 Eventually(session).Should(Exit(0)) 185 }) 186 }) 187 188 When("the -f flag is provided", func() { 189 It("purges the service offering without asking for confirmation", func() { 190 session := helpers.CF("purge-service-offering", broker.ServiceName(), "-f") 191 192 Eventually(session).Should(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 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\\.")) 193 Eventually(session).Should(Say("Purging service %s...", broker.ServiceName())) 194 Eventually(session).Should(Say("OK")) 195 Eventually(session).Should(Exit(0)) 196 }) 197 }) 198 }) 199 200 When("the service does not exist", func() { 201 It("prints a message the service offering does not exist, exiting 0", func() { 202 session := helpers.CF("purge-service-offering", "missing-service") 203 204 Eventually(session).Should(Say("Service offering 'missing-service' not found")) 205 Eventually(session).Should(Exit(0)) 206 }) 207 }) 208 209 When("the -p flag is provided", func() { 210 It("prints a warning that this flag is no longer supported", func() { 211 session := helpers.CF("purge-service-offering", "some-service", "-p", "some-provider") 212 213 Eventually(session).Should(Say("FAILED")) 214 Eventually(session.Err).Should(Say("Flag '-p' is no longer supported")) 215 Eventually(session).ShouldNot(Say("Purging service")) 216 Eventually(session).ShouldNot(Say("OK")) 217 Eventually(session).Should(Exit(1)) 218 }) 219 }) 220 221 When("the -b flag is provided", func() { 222 var ( 223 orgName string 224 spaceName string 225 broker1 *fakeservicebroker.FakeServiceBroker 226 broker2 *fakeservicebroker.FakeServiceBroker 227 buffer *Buffer 228 ) 229 230 It("fails when service broker is not registered yet", func() { 231 session := helpers.CF("purge-service-offering", "some-service", "-b", "non-existent-broker") 232 233 Eventually(session.Err).Should(Say("Service broker 'non-existent-broker' not found")) 234 Eventually(session.Err).Should(Say("TIP: Use 'cf service-brokers' to see a list of available brokers.")) 235 Eventually(session).Should(Say("FAILED")) 236 Eventually(session).Should(Exit(1)) 237 }) 238 239 When("the service is provided by multiple brokers", func() { 240 BeforeEach(func() { 241 helpers.SkipIfVersionLessThan(ccversion.MinVersionMultiServiceRegistrationV2) 242 243 buffer = NewBuffer() 244 _, err := buffer.Write([]byte("y\n")) 245 Expect(err).ToNot(HaveOccurred()) 246 orgName = helpers.NewOrgName() 247 spaceName = helpers.NewSpaceName() 248 helpers.SetupCF(orgName, spaceName) 249 250 broker1 = fakeservicebroker.New().EnsureBrokerIsAvailable() 251 broker2 = fakeservicebroker.NewAlternate() 252 broker2.Services[0].Name = broker1.ServiceName() 253 broker2.EnsureBrokerIsAvailable() 254 255 session := helpers.CF("enable-service-access", broker1.ServiceName(), "-b", broker1.Name()) 256 Eventually(session).Should(Exit(0)) 257 session = helpers.CF("enable-service-access", broker1.ServiceName(), "-b", broker2.Name()) 258 Eventually(session).Should(Exit(0)) 259 }) 260 261 AfterEach(func() { 262 broker1.Destroy() 263 broker2.Destroy() 264 helpers.QuickDeleteOrg(orgName) 265 }) 266 267 When("the user specifies the desired broker", func() { 268 269 It("purges the service offering, asking for confirmation", func() { 270 session := helpers.CFWithStdin(buffer, "purge-service-offering", broker1.ServiceName(), "-b", broker1.Name()) 271 272 Eventually(session).Should(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 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\\.")) 273 Eventually(session).Should(Say("Really purge service offering %s from broker %s from Cloud Foundry?", broker1.ServiceName(), broker1.Name())) 274 Eventually(session).Should(Say("Purging service %s...", broker1.ServiceName())) 275 Eventually(session).Should(Say("OK")) 276 Eventually(session).Should(Exit(0)) 277 278 session = helpers.CF("marketplace") 279 Eventually(session).Should(Say("OK")) 280 Consistently(session).ShouldNot(Say(`%s.+%s`, broker1.ServiceName(), broker1.Name())) 281 Eventually(session).Should(Say(`%s.+%s`, broker1.ServiceName(), broker2.Name())) 282 Eventually(session).Should(Exit(0)) 283 }) 284 }) 285 286 When("the user does not specify the desired broker", func() { 287 It("does not purge the service offering", func() { 288 session := helpers.CFWithStdin(buffer, "purge-service-offering", broker1.ServiceName()) 289 290 Eventually(session.Err).Should(Say("Service '%s' is provided by multiple service brokers. Specify a broker by using the '-b' flag.", broker1.ServiceName())) 291 Eventually(session).Should(Say("FAILED")) 292 293 Eventually(session).ShouldNot(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 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\\.")) 294 Eventually(session).ShouldNot(Say("Purging service %s...", broker1.ServiceName())) 295 Eventually(session).ShouldNot(Say("OK")) 296 Eventually(session).Should(Exit(1)) 297 }) 298 }) 299 }) 300 }) 301 }) 302 }) 303 })