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