github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/unbind_route_service_command_test.go (about) 1 package isolated 2 3 import ( 4 "regexp" 5 "time" 6 7 "code.cloudfoundry.org/cli/integration/helpers" 8 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 9 "code.cloudfoundry.org/cli/resources" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gbytes" 13 . "github.com/onsi/gomega/gexec" 14 ) 15 16 var _ = Describe("unbind-route-service command", func() { 17 const command = "unbind-route-service" 18 19 Describe("help", func() { 20 matchHelpMessage := SatisfyAll( 21 Say("NAME:"), 22 Say("unbind-route-service - Unbind a service instance from an HTTP route"), 23 Say("USAGE:"), 24 Say(regexp.QuoteMeta("cf unbind-route-service DOMAIN [--hostname HOSTNAME] [--path PATH] SERVICE_INSTANCE [-f]")), 25 Say("EXAMPLES:"), 26 Say("cf unbind-route-service example.com --hostname myapp --path foo myratelimiter"), 27 Say("ALIAS:"), 28 Say("urs"), 29 Say("OPTIONS:"), 30 Say(`-f\s+Force unbinding without confirmation`), 31 Say(`--hostname, -n\s+Hostname used in combination with DOMAIN to specify the route to unbind`), 32 Say(`--path\s+Path used in combination with HOSTNAME and DOMAIN to specify the route to unbind`), 33 Say(`\s+--wait, -w\s+Wait for the operation to complete\n`), 34 Say("SEE ALSO:"), 35 Say("delete-service, routes, services"), 36 ) 37 38 When("the -h flag is specified", func() { 39 It("succeeds and prints help", func() { 40 session := helpers.CF(command, "-h") 41 Eventually(session).Should(Exit(0)) 42 Expect(session.Out).To(matchHelpMessage) 43 }) 44 }) 45 46 When("the --help flag is specified", func() { 47 It("succeeds and prints help", func() { 48 session := helpers.CF(command, "--help") 49 Eventually(session).Should(Exit(0)) 50 Expect(session.Out).To(matchHelpMessage) 51 }) 52 }) 53 54 When("no arguments are provided", func() { 55 It("displays a warning, the help text, and exits 1", func() { 56 session := helpers.CF(command) 57 Eventually(session).Should(Exit(1)) 58 Expect(session.Err).To(Say("Incorrect Usage: the required arguments `DOMAIN` and `SERVICE_INSTANCE` were not provided")) 59 Expect(session.Out).To(matchHelpMessage) 60 }) 61 }) 62 63 When("unknown flag is passed", func() { 64 It("displays a warning, the help text, and exits 1", func() { 65 session := helpers.CF(command, "-u") 66 Eventually(session).Should(Exit(1)) 67 Expect(session.Err).To(Say("Incorrect Usage: unknown flag `u")) 68 Expect(session.Out).To(matchHelpMessage) 69 }) 70 }) 71 }) 72 73 When("the environment is not setup correctly", func() { 74 It("fails with the appropriate errors", func() { 75 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, command, "foo", "bar") 76 }) 77 }) 78 79 When("targeting a space", func() { 80 var ( 81 orgName string 82 spaceName string 83 username string 84 ) 85 86 routeBindingCount := func(serviceInstanceName string) int { 87 var receiver struct { 88 Resources []resources.RouteBinding `json:"resources"` 89 } 90 helpers.Curl(&receiver, "/v3/service_route_bindings?service_instance_names=%s", serviceInstanceName) 91 return len(receiver.Resources) 92 } 93 94 BeforeEach(func() { 95 orgName = helpers.NewOrgName() 96 spaceName = helpers.NewSpaceName() 97 helpers.SetupCF(orgName, spaceName) 98 99 username, _ = helpers.GetCredentials() 100 }) 101 102 AfterEach(func() { 103 helpers.QuickDeleteOrg(orgName) 104 }) 105 106 Context("user-provided route service", func() { 107 var ( 108 routeServiceURL string 109 serviceInstanceName string 110 domain string 111 hostname string 112 path string 113 ) 114 115 BeforeEach(func() { 116 routeServiceURL = helpers.RandomURL() 117 serviceInstanceName = helpers.NewServiceInstanceName() 118 Eventually(helpers.CF("cups", serviceInstanceName, "-r", routeServiceURL)).Should(Exit(0)) 119 120 domain = helpers.DefaultSharedDomain() 121 hostname = helpers.NewHostName() 122 path = helpers.PrefixedRandomName("path") 123 Eventually(helpers.CF("create-route", domain, "--hostname", hostname, "--path", path)).Should(Exit(0)) 124 125 Eventually(helpers.CF("bind-route-service", domain, "--hostname", hostname, "--path", path, serviceInstanceName, "--wait")).Should(Exit(0)) 126 }) 127 128 It("deletes a route binding", func() { 129 session := helpers.CF(command, "-f", domain, "--hostname", hostname, "--path", path, serviceInstanceName) 130 Eventually(session).Should(Exit(0)) 131 132 Expect(session.Out).To(SatisfyAll( 133 Say(`Unbinding route %s.%s/%s from service instance %s in org %s / space %s as %s\.\.\.\n`, hostname, domain, path, serviceInstanceName, orgName, spaceName, username), 134 Say(`OK\n`), 135 )) 136 137 Expect(string(session.Err.Contents())).To(BeEmpty()) 138 Expect(routeBindingCount(serviceInstanceName)).To(BeZero()) 139 }) 140 }) 141 142 Context("managed route service with synchronous broker response", func() { 143 var ( 144 broker *servicebrokerstub.ServiceBrokerStub 145 serviceInstanceName string 146 domain string 147 hostname string 148 path string 149 ) 150 151 BeforeEach(func() { 152 broker = servicebrokerstub.New().WithRouteService().EnableServiceAccess() 153 serviceInstanceName = helpers.NewServiceInstanceName() 154 helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), serviceInstanceName) 155 156 domain = helpers.DefaultSharedDomain() 157 hostname = helpers.NewHostName() 158 path = helpers.PrefixedRandomName("path") 159 Eventually(helpers.CF("create-route", domain, "--hostname", hostname, "--path", path)).Should(Exit(0)) 160 161 Eventually(helpers.CF("bind-route-service", domain, "--hostname", hostname, "--path", path, serviceInstanceName, "--wait")).Should(Exit(0)) 162 }) 163 164 AfterEach(func() { 165 broker.Forget() 166 }) 167 168 It("deletes a route binding", func() { 169 session := helpers.CF(command, "-f", domain, "--hostname", hostname, "--path", path, serviceInstanceName) 170 Eventually(session).Should(Exit(0)) 171 172 Expect(session.Out).To(SatisfyAll( 173 Say(`Unbinding route %s.%s/%s from service instance %s in org %s / space %s as %s\.\.\.\n`, hostname, domain, path, serviceInstanceName, orgName, spaceName, username), 174 Say(`OK\n`), 175 )) 176 177 Expect(string(session.Err.Contents())).To(BeEmpty()) 178 Expect(routeBindingCount(serviceInstanceName)).To(BeZero()) 179 }) 180 }) 181 182 Context("managed route service with asynchronous broker response", func() { 183 var ( 184 broker *servicebrokerstub.ServiceBrokerStub 185 serviceInstanceName string 186 domain string 187 hostname string 188 path string 189 ) 190 191 BeforeEach(func() { 192 broker = servicebrokerstub.New().WithRouteService().EnableServiceAccess() 193 serviceInstanceName = helpers.NewServiceInstanceName() 194 helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), serviceInstanceName) 195 196 domain = helpers.DefaultSharedDomain() 197 hostname = helpers.NewHostName() 198 path = helpers.PrefixedRandomName("path") 199 Eventually(helpers.CF("create-route", domain, "--hostname", hostname, "--path", path)).Should(Exit(0)) 200 201 Eventually(helpers.CF("bind-route-service", domain, "--hostname", hostname, "--path", path, serviceInstanceName, "--wait")).Should(Exit(0)) 202 203 broker.WithAsyncDelay(time.Second).Configure() 204 }) 205 206 AfterEach(func() { 207 broker.Forget() 208 }) 209 210 It("starts to delete a route binding", func() { 211 session := helpers.CF(command, "-f", domain, "--hostname", hostname, "--path", path, serviceInstanceName) 212 Eventually(session).Should(Exit(0)) 213 214 Expect(session.Out).To(SatisfyAll( 215 Say(`Unbinding route %s.%s/%s from service instance %s in org %s / space %s as %s\.\.\.\n`, hostname, domain, path, serviceInstanceName, orgName, spaceName, username), 216 Say(`OK\n`), 217 Say(`\n`), 218 Say(`Unbinding in progress\.\n`), 219 )) 220 221 Expect(string(session.Err.Contents())).To(BeEmpty()) 222 223 Expect(routeBindingCount(serviceInstanceName)).NotTo(BeZero()) 224 }) 225 226 When("--wait flag specified", func() { 227 It("waits for completion", func() { 228 session := helpers.CF(command, "-f", domain, "--hostname", hostname, "--path", path, serviceInstanceName, "--wait") 229 Eventually(session).Should(Exit(0)) 230 231 Expect(session.Out).To(SatisfyAll( 232 Say(`Unbinding route %s.%s/%s from service instance %s in org %s / space %s as %s\.\.\.\n`, hostname, domain, path, serviceInstanceName, orgName, spaceName, username), 233 Say(`Waiting for the operation to complete\.+\n`), 234 Say(`\n`), 235 Say(`OK\n`), 236 )) 237 238 Expect(string(session.Err.Contents())).To(BeEmpty()) 239 240 Expect(routeBindingCount(serviceInstanceName)).To(BeZero()) 241 }) 242 }) 243 }) 244 245 Context("route binding does not exists", func() { 246 var ( 247 routeServiceURL string 248 serviceInstanceName string 249 domain string 250 hostname string 251 path string 252 ) 253 254 BeforeEach(func() { 255 routeServiceURL = helpers.RandomURL() 256 serviceInstanceName = helpers.NewServiceInstanceName() 257 Eventually(helpers.CF("cups", serviceInstanceName, "-r", routeServiceURL)).Should(Exit(0)) 258 259 domain = helpers.DefaultSharedDomain() 260 hostname = helpers.NewHostName() 261 path = helpers.PrefixedRandomName("path") 262 Eventually(helpers.CF("create-route", domain, "--hostname", hostname, "--path", path)).Should(Exit(0)) 263 264 session := helpers.CF(command, "-f", domain, "--hostname", hostname, "--path", path, serviceInstanceName) 265 Eventually(session).Should(Exit(0)) 266 }) 267 268 It("says OK", func() { 269 session := helpers.CF(command, "-f", domain, "--hostname", hostname, "--path", path, serviceInstanceName) 270 Eventually(session).Should(Exit(0)) 271 272 Expect(session.Out).To(SatisfyAll( 273 Say(`Unbinding route %s.%s/%s from service instance %s in org %s / space %s as %s\.\.\.\n`, hostname, domain, path, serviceInstanceName, orgName, spaceName, username), 274 Say(`Route %s.%s/%s was not bound to service instance %s\.\n`, hostname, domain, path, serviceInstanceName), 275 Say(`OK\n`), 276 )) 277 278 Expect(string(session.Err.Contents())).To(BeEmpty()) 279 }) 280 }) 281 }) 282 })