github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/shared/isolated/purge_service_offering_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("purge-service-offering command", func() { 12 BeforeEach(func() { 13 helpers.TurnOnExperimental() 14 }) 15 16 AfterEach(func() { 17 helpers.TurnOffExperimental() 18 }) 19 20 Describe("help", func() { 21 When("the --help flag is set", func() { 22 It("displays command usage to output", func() { 23 session := helpers.CF("purge-service-offering", "--help") 24 25 Eventually(session).Should(Say("NAME:")) 26 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")) 27 Eventually(session).Should(Say("USAGE:")) 28 Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-p PROVIDER\] \[-f\]`)) 29 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\\.")) 30 Eventually(session).Should(Say("OPTIONS:")) 31 Eventually(session).Should(Say("-f\\s+Force deletion without confirmation")) 32 Eventually(session).Should(Say("-p\\s+Provider")) 33 Eventually(session).Should(Say("SEE ALSO:")) 34 Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers")) 35 Eventually(session).Should(Exit(0)) 36 }) 37 }) 38 }) 39 40 When("no args are passed", func() { 41 It("displays an error message with help text", func() { 42 session := helpers.CF("purge-service-offering") 43 44 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SERVICE` was not provided")) 45 Eventually(session).Should(Say("NAME:")) 46 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")) 47 Eventually(session).Should(Say("USAGE:")) 48 Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-p PROVIDER\] \[-f\]`)) 49 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\\.")) 50 Eventually(session).Should(Say("OPTIONS:")) 51 Eventually(session).Should(Say("-f\\s+Force deletion without confirmation")) 52 Eventually(session).Should(Say("-p\\s+Provider")) 53 Eventually(session).Should(Say("SEE ALSO:")) 54 Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers")) 55 Eventually(session).Should(Exit(1)) 56 }) 57 }) 58 59 When("more than required number of args are passed", func() { 60 It("displays an error message with help text and exits 1", func() { 61 session := helpers.CF("purge-service-offering", "service-name", "extra") 62 63 Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "extra"`)) 64 Eventually(session).Should(Say("NAME:")) 65 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")) 66 Eventually(session).Should(Say("USAGE:")) 67 Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-p PROVIDER\] \[-f\]`)) 68 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\\.")) 69 Eventually(session).Should(Say("OPTIONS:")) 70 Eventually(session).Should(Say("-f\\s+Force deletion without confirmation")) 71 Eventually(session).Should(Say("-p\\s+Provider")) 72 Eventually(session).Should(Say("SEE ALSO:")) 73 Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers")) 74 Eventually(session).Should(Exit(1)) 75 }) 76 }) 77 78 When("service name is passed", func() { 79 When("an API target is not set", func() { 80 BeforeEach(func() { 81 helpers.UnsetAPI() 82 }) 83 84 It("displays an error message that no API endpoint is set", func() { 85 session := helpers.CF("purge-service-offering", "service-name") 86 87 Eventually(session).Should(Say("FAILED")) 88 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 89 Eventually(session).Should(Exit(1)) 90 }) 91 }) 92 93 When("user is not logged in", func() { 94 BeforeEach(func() { 95 helpers.LogoutCF() 96 }) 97 98 It("displays an error message that user is not logged in", func() { 99 session := helpers.CF("purge-service-offering", "service-name") 100 101 Eventually(session).Should(Say("FAILED")) 102 Eventually(session.Err).Should(Say(`Not logged in\. Use 'cf login' to log in\.`)) 103 Eventually(session).Should(Exit(1)) 104 }) 105 }) 106 107 When("user is logged in", func() { 108 BeforeEach(func() { 109 helpers.LoginCF() 110 }) 111 112 When("the service exists", func() { 113 var ( 114 orgName string 115 spaceName string 116 domain string 117 service string 118 servicePlan string 119 broker helpers.ServiceBroker 120 buffer *Buffer 121 ) 122 123 BeforeEach(func() { 124 buffer = NewBuffer() 125 126 orgName = helpers.NewOrgName() 127 spaceName = helpers.NewSpaceName() 128 helpers.SetupCF(orgName, spaceName) 129 130 domain = helpers.DefaultSharedDomain() 131 service = helpers.PrefixedRandomName("SERVICE") 132 servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN") 133 134 broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan) 135 broker.Push() 136 broker.Configure(true) 137 broker.Create() 138 }) 139 140 AfterEach(func() { 141 broker.Destroy() 142 helpers.QuickDeleteOrg(orgName) 143 }) 144 145 When("the user enters 'y'", func() { 146 BeforeEach(func() { 147 buffer.Write([]byte("y\n")) 148 }) 149 150 It("purges the service offering, asking for confirmation", func() { 151 session := helpers.CFWithStdin(buffer, "purge-service-offering", service) 152 153 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\\.")) 154 Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", service)) 155 Eventually(session).Should(Say("Purging service %s...", service)) 156 Eventually(session).Should(Say("OK")) 157 Eventually(session).Should(Exit(0)) 158 159 session = helpers.CF("marketplace") 160 Eventually(session).Should(Say("OK")) 161 Consistently(session).ShouldNot(Say(service)) 162 Eventually(session).Should(Exit(0)) 163 }) 164 }) 165 166 When("the user enters something other than 'y' or 'yes'", func() { 167 BeforeEach(func() { 168 buffer.Write([]byte("wat\n\n")) 169 }) 170 171 It("asks again", func() { 172 session := helpers.CFWithStdin(buffer, "purge-service-offering", service) 173 174 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\\.")) 175 Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", service)) 176 Eventually(session).Should(Say(`invalid input \(not y, n, yes, or no\)`)) 177 Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", service)) 178 Eventually(session).Should(Exit(0)) 179 }) 180 }) 181 182 When("the user enters 'n' or 'no'", func() { 183 BeforeEach(func() { 184 buffer.Write([]byte("n\n")) 185 }) 186 187 It("does not purge the service offering", func() { 188 session := helpers.CFWithStdin(buffer, "purge-service-offering", service) 189 190 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\\.")) 191 Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", service)) 192 Eventually(session).ShouldNot(Say("Purging service %s...", service)) 193 Eventually(session).ShouldNot(Say("OK")) 194 Eventually(session).Should(Exit(0)) 195 }) 196 }) 197 198 When("the -f flag is provided", func() { 199 It("purges the service offering without asking for confirmation", func() { 200 session := helpers.CF("purge-service-offering", service, "-f") 201 202 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\\.")) 203 Eventually(session).Should(Say("Purging service %s...", service)) 204 Eventually(session).Should(Say("OK")) 205 Eventually(session).Should(Exit(0)) 206 }) 207 }) 208 }) 209 210 When("the service does not exist", func() { 211 It("prints a message the service offering does not exist, exiting 0", func() { 212 session := helpers.CF("purge-service-offering", "missing-service") 213 214 Eventually(session).Should(Say("Service offering 'missing-service' not found")) 215 Eventually(session).Should(Exit(0)) 216 }) 217 }) 218 219 When("the -p flag is provided", func() { 220 It("prints a warning that this flag is no longer supported", func() { 221 session := helpers.CF("purge-service-offering", "some-service", "-p", "some-provider") 222 223 Eventually(session).Should(Say("FAILED")) 224 Eventually(session.Err).Should(Say("Flag '-p' is no longer supported")) 225 Eventually(session).ShouldNot(Say("Purging service")) 226 Eventually(session).ShouldNot(Say("OK")) 227 Eventually(session).Should(Exit(1)) 228 }) 229 }) 230 }) 231 }) 232 })