github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/shared/isolated/service_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("service command", func() { 14 var serviceInstanceName string 15 16 BeforeEach(func() { 17 serviceInstanceName = helpers.PrefixedRandomName("SI") 18 }) 19 20 Describe("help", func() { 21 When("--help flag is set", func() { 22 It("displays command usage to output", func() { 23 session := helpers.CF("service", "--help") 24 Eventually(session).Should(Say("NAME:")) 25 Eventually(session).Should(Say(`\s+service - Show service instance info`)) 26 Eventually(session).Should(Say("USAGE:")) 27 Eventually(session).Should(Say(`\s+cf service SERVICE_INSTANCE`)) 28 Eventually(session).Should(Say("OPTIONS:")) 29 Eventually(session).Should(Say(`\s+\-\-guid\s+Retrieve and display the given service's guid\. All other output for the service is suppressed\.`)) 30 Eventually(session).Should(Say("SEE ALSO:")) 31 Eventually(session).Should(Say(`\s+bind-service, rename-service, update-service`)) 32 Eventually(session).Should(Exit(0)) 33 }) 34 }) 35 }) 36 37 When("the environment is not setup correctly", func() { 38 It("fails with the appropriate errors", func() { 39 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "service", "some-service") 40 }) 41 }) 42 43 When("an api is targeted, the user is logged in, and an org and space are targeted", func() { 44 var ( 45 orgName string 46 spaceName string 47 userName string 48 ) 49 50 BeforeEach(func() { 51 orgName = helpers.NewOrgName() 52 spaceName = helpers.NewSpaceName() 53 helpers.SetupCF(orgName, spaceName) 54 55 userName, _ = helpers.GetCredentials() 56 }) 57 58 AfterEach(func() { 59 helpers.QuickDeleteOrg(orgName) 60 }) 61 62 When("the service instance does not exist", func() { 63 It("returns an error and exits 1", func() { 64 session := helpers.CF("service", serviceInstanceName) 65 Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName)) 66 Eventually(session).Should(Say("")) 67 Eventually(session).Should(Say("FAILED")) 68 Eventually(session.Err).Should(Say("Service instance %s not found", serviceInstanceName)) 69 Eventually(session).Should(Exit(1)) 70 }) 71 }) 72 73 When("the service instance belongs to this space", func() { 74 When("the service instance is a user provided service instance", func() { 75 BeforeEach(func() { 76 Eventually(helpers.CF("create-user-provided-service", serviceInstanceName)).Should(Exit(0)) 77 }) 78 79 AfterEach(func() { 80 Eventually(helpers.CF("delete-service", serviceInstanceName, "-f")).Should(Exit(0)) 81 }) 82 83 When("the --guid flag is provided", func() { 84 It("displays the service instance GUID", func() { 85 session := helpers.CF("service", serviceInstanceName, "--guid") 86 Consistently(session).ShouldNot(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName)) 87 Eventually(session).Should(Say(helpers.UserProvidedServiceInstanceGUID(serviceInstanceName))) 88 Eventually(session).Should(Exit(0)) 89 }) 90 }) 91 92 When("no apps are bound to the service instance", func() { 93 It("displays service instance info", func() { 94 session := helpers.CF("service", serviceInstanceName) 95 Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName)) 96 Eventually(session).Should(Say("")) 97 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 98 Eventually(session).Should(Say(`service:\s+user-provided`)) 99 Eventually(session).Should(Say("")) 100 Eventually(session).Should(Say("There are no bound apps for this service.")) 101 Eventually(session).Should(Say("")) 102 Eventually(session).Should(Exit(0)) 103 }) 104 }) 105 106 When("apps are bound to the service instance", func() { 107 var ( 108 appName1 string 109 appName2 string 110 ) 111 112 BeforeEach(func() { 113 appName1 = helpers.PrefixedRandomName("1-INTEGRATION-APP") 114 appName2 = helpers.PrefixedRandomName("2-INTEGRATION-APP") 115 116 helpers.WithHelloWorldApp(func(appDir string) { 117 Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 118 Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 119 }) 120 }) 121 122 AfterEach(func() { 123 Eventually(helpers.CF("delete", appName1, "-f")).Should(Exit(0)) 124 Eventually(helpers.CF("delete", appName2, "-f")).Should(Exit(0)) 125 }) 126 127 When("the service bindings do not have binding names", func() { 128 BeforeEach(func() { 129 Eventually(helpers.CF("bind-service", appName1, serviceInstanceName)).Should(Exit(0)) 130 Eventually(helpers.CF("bind-service", appName2, serviceInstanceName)).Should(Exit(0)) 131 }) 132 133 AfterEach(func() { 134 Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0)) 135 Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0)) 136 }) 137 138 It("displays service instance info", func() { 139 session := helpers.CF("service", serviceInstanceName) 140 Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName)) 141 Eventually(session).Should(Say("")) 142 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 143 Eventually(session).Should(Say(`service:\s+user-provided`)) 144 Eventually(session).Should(Say("")) 145 Eventually(session).Should(Say("bound apps:")) 146 Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`)) 147 Eventually(session).Should(Say(appName1)) 148 Eventually(session).Should(Say(appName2)) 149 150 Eventually(session).Should(Exit(0)) 151 }) 152 }) 153 154 When("the service bindings have binding names", func() { 155 var ( 156 bindingName1 string 157 bindingName2 string 158 ) 159 160 BeforeEach(func() { 161 bindingName1 = helpers.PrefixedRandomName("BINDING-NAME") 162 bindingName2 = helpers.PrefixedRandomName("BINDING-NAME") 163 Eventually(helpers.CF("bind-service", appName1, serviceInstanceName, "--binding-name", bindingName1)).Should(Exit(0)) 164 Eventually(helpers.CF("bind-service", appName2, serviceInstanceName, "--binding-name", bindingName2)).Should(Exit(0)) 165 }) 166 167 AfterEach(func() { 168 Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0)) 169 Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0)) 170 }) 171 172 It("displays service instance info", func() { 173 session := helpers.CF("service", serviceInstanceName) 174 Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName)) 175 Eventually(session).Should(Say("")) 176 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 177 Eventually(session).Should(Say(`service:\s+user-provided`)) 178 Eventually(session).Should(Say("")) 179 Eventually(session).Should(Say("bound apps:")) 180 Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`)) 181 Eventually(session).Should(Say(`%s\s+%s`, appName1, bindingName1)) 182 Eventually(session).Should(Say(`%s\s+%s`, appName2, bindingName2)) 183 Eventually(session).Should(Say("")) 184 Eventually(session).Should(Exit(0)) 185 }) 186 }) 187 }) 188 189 When("we update the user provided service instance with tags", func() { 190 BeforeEach(func() { 191 helpers.SkipIfVersionLessThan(ccversion.MinVersionUserProvidedServiceTagsV2) 192 Eventually(helpers.CF("update-user-provided-service", serviceInstanceName, 193 "-t", "foo, bar")).Should(Exit(0)) 194 }) 195 196 It("displays service instance info", func() { 197 session := helpers.CF("service", serviceInstanceName) 198 Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName)) 199 Eventually(session).Should(Say(`tags:\s+foo, bar`)) 200 Eventually(session).Should(Exit(0)) 201 }) 202 }) 203 }) 204 205 When("a user-provided service instance is created with tags", func() { 206 BeforeEach(func() { 207 helpers.SkipIfVersionLessThan(ccversion.MinVersionUserProvidedServiceTagsV2) 208 Eventually(helpers.CF("create-user-provided-service", serviceInstanceName, "-t", "database, email")).Should(Exit(0)) 209 }) 210 211 It("displays tag info", func() { 212 session := helpers.CF("service", serviceInstanceName) 213 Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName)) 214 Eventually(session).Should(Say(`tags:\s+database, email`)) 215 Eventually(session).Should(Exit(0)) 216 }) 217 }) 218 219 When("the service instance is a managed service instance", func() { 220 var ( 221 service string 222 servicePlan string 223 broker *fakeservicebroker.FakeServiceBroker 224 ) 225 226 BeforeEach(func() { 227 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 228 service = broker.ServiceName() 229 servicePlan = broker.ServicePlanName() 230 231 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 232 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstanceName, "-t", "database, email")).Should(Exit(0)) 233 }) 234 235 AfterEach(func() { 236 Eventually(helpers.CF("delete-service", serviceInstanceName, "-f")).Should(Exit(0)) 237 broker.Destroy() 238 }) 239 240 When("the --guid flag is provided", func() { 241 It("displays the service instance GUID", func() { 242 session := helpers.CF("service", serviceInstanceName, "--guid") 243 Consistently(session).ShouldNot(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName)) 244 Eventually(session).Should(Say(helpers.ManagedServiceInstanceGUID(serviceInstanceName))) 245 Eventually(session).Should(Exit(0)) 246 }) 247 }) 248 249 When("apps are bound to the service instance", func() { 250 var ( 251 appName1 string 252 appName2 string 253 ) 254 255 BeforeEach(func() { 256 appName1 = helpers.PrefixedRandomName("1-INTEGRATION-APP") 257 appName2 = helpers.PrefixedRandomName("2-INTEGRATION-APP") 258 259 helpers.WithHelloWorldApp(func(appDir string) { 260 Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 261 Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 262 }) 263 }) 264 265 AfterEach(func() { 266 Eventually(helpers.CF("delete", appName1, "-f")).Should(Exit(0)) 267 Eventually(helpers.CF("delete", appName2, "-f")).Should(Exit(0)) 268 }) 269 270 When("the service bindings do not have binding names", func() { 271 BeforeEach(func() { 272 Eventually(helpers.CF("bind-service", appName1, serviceInstanceName)).Should(Exit(0)) 273 Eventually(helpers.CF("bind-service", appName2, serviceInstanceName)).Should(Exit(0)) 274 }) 275 276 AfterEach(func() { 277 Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0)) 278 Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0)) 279 }) 280 281 When("cc api version < 2.125.0", func() { 282 BeforeEach(func() { 283 helpers.SkipIfVersionAtLeast(ccversion.MinVersionMultiServiceRegistrationV2) 284 }) 285 286 It("displays service instance info", func() { 287 session := helpers.CF("service", serviceInstanceName) 288 Eventually(session).Should(Say(`Showing info of service %s in org %s / space %s as %s\.\.\.`, serviceInstanceName, orgName, spaceName, userName)) 289 Eventually(session).Should(Say("\n\n")) 290 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 291 Consistently(session).ShouldNot(Say("shared from:")) 292 Eventually(session).Should(Say(`service:\s+%s`, service)) 293 Eventually(session).Should(Say(`tags:\s+database, email`)) 294 Eventually(session).Should(Say(`plan:\s+%s`, servicePlan)) 295 Eventually(session).Should(Say(`description:\s+fake service`)) 296 Eventually(session).Should(Say(`documentation:\s+http://documentation\.url`)) 297 Eventually(session).Should(Say(`dashboard:\s+http://example\.com`)) 298 Eventually(session).Should(Say(`service broker:`)) 299 Consistently(session).ShouldNot(Say(broker.Name())) 300 Eventually(session).Should(Say("\n\n")) 301 Consistently(session).ShouldNot(Say("shared with spaces:")) 302 Eventually(session).Should(Say(`Showing status of last operation from service %s\.\.\.`, serviceInstanceName)) 303 Eventually(session).Should(Say("\n\n")) 304 Eventually(session).Should(Say(`status:\s+create succeeded`)) 305 Eventually(session).Should(Say("message:")) 306 Eventually(session).Should(Say(`started:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`)) 307 Eventually(session).Should(Say(`updated:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`)) 308 Eventually(session).Should(Say("\n\n")) 309 Eventually(session).Should(Say("bound apps:")) 310 Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`)) 311 Eventually(session).Should(Say(appName1)) 312 Eventually(session).Should(Say(appName2)) 313 Eventually(session).Should(Exit(0)) 314 }) 315 }) 316 317 When("cc api version >= 2.125.0", func() { 318 BeforeEach(func() { 319 helpers.SkipIfVersionLessThan(ccversion.MinVersionMultiServiceRegistrationV2) 320 }) 321 322 It("displays service instance info", func() { 323 session := helpers.CF("service", serviceInstanceName) 324 Eventually(session).Should(Say(`Showing info of service %s in org %s / space %s as %s\.\.\.`, serviceInstanceName, orgName, spaceName, userName)) 325 Eventually(session).Should(Say("\n\n")) 326 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 327 Consistently(session).ShouldNot(Say("shared from:")) 328 Eventually(session).Should(Say(`service:\s+%s`, service)) 329 Eventually(session).Should(Say(`tags:\s+database, email`)) 330 Eventually(session).Should(Say(`plan:\s+%s`, servicePlan)) 331 Eventually(session).Should(Say(`description:\s+fake service`)) 332 Eventually(session).Should(Say(`documentation:\s+http://documentation\.url`)) 333 Eventually(session).Should(Say(`dashboard:\s+http://example\.com`)) 334 Eventually(session).Should(Say(`service broker:\s+%s`, broker.Name())) 335 Eventually(session).Should(Say("\n\n")) 336 Consistently(session).ShouldNot(Say("shared with spaces:")) 337 Eventually(session).Should(Say(`Showing status of last operation from service %s\.\.\.`, serviceInstanceName)) 338 Eventually(session).Should(Say("\n\n")) 339 Eventually(session).Should(Say(`status:\s+create succeeded`)) 340 Eventually(session).Should(Say("message:")) 341 Eventually(session).Should(Say(`started:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`)) 342 Eventually(session).Should(Say(`updated:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`)) 343 Eventually(session).Should(Say("\n\n")) 344 Eventually(session).Should(Say("bound apps:")) 345 Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`)) 346 Eventually(session).Should(Say(appName1)) 347 Eventually(session).Should(Say(appName2)) 348 Eventually(session).Should(Exit(0)) 349 }) 350 }) 351 }) 352 353 When("the service bindings have binding names", func() { 354 var ( 355 bindingName1 string 356 bindingName2 string 357 ) 358 359 BeforeEach(func() { 360 bindingName1 = helpers.PrefixedRandomName("BINDING-NAME") 361 bindingName2 = helpers.PrefixedRandomName("BINDING-NAME") 362 Eventually(helpers.CF("bind-service", appName1, serviceInstanceName, "--binding-name", bindingName1)).Should(Exit(0)) 363 Eventually(helpers.CF("bind-service", appName2, serviceInstanceName, "--binding-name", bindingName2)).Should(Exit(0)) 364 }) 365 366 AfterEach(func() { 367 Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0)) 368 Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0)) 369 }) 370 371 It("displays service instance info", func() { 372 session := helpers.CF("service", serviceInstanceName) 373 Eventually(session).Should(Say(`Showing info of service %s in org %s / space %s as %s\.\.\.`, serviceInstanceName, orgName, spaceName, userName)) 374 Eventually(session).Should(Say("\n\n")) 375 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 376 Consistently(session).ShouldNot(Say("shared from:")) 377 Eventually(session).Should(Say(`service:\s+%s`, service)) 378 Eventually(session).Should(Say(`tags:\s+database, email`)) 379 Eventually(session).Should(Say(`plan:\s+%s`, servicePlan)) 380 Eventually(session).Should(Say(`description:\s+fake service`)) 381 Eventually(session).Should(Say(`documentation:\s+http://documentation\.url`)) 382 Eventually(session).Should(Say(`dashboard:\s+http://example\.com`)) 383 Eventually(session).Should(Say("\n\n")) 384 Consistently(session).ShouldNot(Say("shared with spaces:")) 385 Eventually(session).Should(Say(`Showing status of last operation from service %s\.\.\.`, serviceInstanceName)) 386 Eventually(session).Should(Say("\n\n")) 387 Eventually(session).Should(Say(`status:\s+create succeeded`)) 388 Eventually(session).Should(Say("message:")) 389 Eventually(session).Should(Say(`started:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`)) 390 Eventually(session).Should(Say(`updated:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`)) 391 Eventually(session).Should(Say("\n\n")) 392 Eventually(session).Should(Say("bound apps:")) 393 Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`)) 394 Eventually(session).Should(Say(`%s\s+%s`, appName1, bindingName1)) 395 Eventually(session).Should(Say(`%s\s+%s`, appName2, bindingName2)) 396 397 Eventually(session).Should(Exit(0)) 398 }) 399 }) 400 401 When("the binding has a state", func() { 402 var ( 403 bindingName1 string 404 bindingName2 string 405 ) 406 407 BeforeEach(func() { 408 helpers.SkipIfVersionLessThan(ccversion.MinVersionAsyncBindingsV2) 409 bindingName1 = helpers.PrefixedRandomName("BINDING-NAME") 410 bindingName2 = helpers.PrefixedRandomName("BINDING-NAME") 411 Eventually(helpers.CF("bind-service", appName1, serviceInstanceName, "--binding-name", bindingName1)).Should(Exit(0)) 412 Eventually(helpers.CF("bind-service", appName2, serviceInstanceName, "--binding-name", bindingName2)).Should(Exit(0)) 413 }) 414 415 AfterEach(func() { 416 Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0)) 417 Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0)) 418 }) 419 420 It("displays it in the status field", func() { 421 session := helpers.CF("service", serviceInstanceName) 422 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 423 Eventually(session).Should(Say("bound apps:")) 424 Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`)) 425 Eventually(session).Should(Say(`%s\s+%s\s+create succeeded`, appName1, bindingName1)) 426 Eventually(session).Should(Say(`%s\s+%s\s+create succeeded`, appName2, bindingName2)) 427 428 Eventually(session).Should(Exit(0)) 429 }) 430 }) 431 }) 432 433 When("Upgrade available", func() { 434 BeforeEach(func() { 435 helpers.SkipIfVersionLessThan(ccversion.MinVersionMaintenanceInfoInSummaryV2) 436 }) 437 It("displays description of upgrade when available", func() { 438 By("Having a service instance with no maintenance_info in the plan") 439 session := helpers.CF("service", serviceInstanceName) 440 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 441 Eventually(session).Should(Say("There is no upgrade available for this service.")) 442 443 By("Adding maintenance_info to the service plan") 444 broker.Services[0].Plans[0].SetMaintenanceInfo("3.0.0", "Stemcell update.\nExpect downtime.") 445 broker.Update() 446 447 session = helpers.CF("service", serviceInstanceName) 448 Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName)) 449 Eventually(session).Should(Say("Showing available upgrade details for this service...")) 450 Eventually(session).Should(Say("upgrade description: Stemcell update.\nExpect downtime.")) 451 Eventually(session).Should(Say(`TIP: You can upgrade using 'cf update-service %s --upgrade'`, serviceInstanceName)) 452 }) 453 }) 454 }) 455 }) 456 }) 457 458 Context("service instance sharing when there are multiple spaces", func() { 459 var ( 460 orgName string 461 sourceSpaceName string 462 463 service string 464 servicePlan string 465 broker *fakeservicebroker.FakeServiceBroker 466 ) 467 468 BeforeEach(func() { 469 helpers.SkipIfVersionLessThan(ccversion.MinVersionShareServiceV3) 470 orgName = helpers.NewOrgName() 471 sourceSpaceName = helpers.NewSpaceName() 472 helpers.SetupCF(orgName, sourceSpaceName) 473 474 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 475 service = broker.ServiceName() 476 servicePlan = broker.ServicePlanName() 477 478 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 479 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstanceName)).Should(Exit(0)) 480 }) 481 482 AfterEach(func() { 483 // need to login as admin 484 helpers.LoginCF() 485 helpers.TargetOrgAndSpace(orgName, sourceSpaceName) 486 broker.Destroy() 487 helpers.QuickDeleteOrg(orgName) 488 }) 489 490 Context("service has no type of shares", func() { 491 When("the service is shareable", func() { 492 It("should not display shared from or shared with information, but DOES display not currently shared info", func() { 493 session := helpers.CF("service", serviceInstanceName) 494 Eventually(session).Should(Say("This service is not currently shared.")) 495 Eventually(session).Should(Exit(0)) 496 }) 497 }) 498 }) 499 500 Context("service is shared between two spaces", func() { 501 var ( 502 targetSpaceName string 503 ) 504 505 BeforeEach(func() { 506 targetSpaceName = helpers.NewSpaceName() 507 helpers.CreateOrgAndSpace(orgName, targetSpaceName) 508 helpers.TargetOrgAndSpace(orgName, sourceSpaceName) 509 Eventually(helpers.CF("share-service", serviceInstanceName, "-s", targetSpaceName)).Should(Exit(0)) 510 }) 511 512 When("the user is targeted to the source space", func() { 513 When("there are externally bound apps to the service", func() { 514 BeforeEach(func() { 515 helpers.TargetOrgAndSpace(orgName, targetSpaceName) 516 helpers.WithHelloWorldApp(func(appDir string) { 517 appName1 := helpers.NewAppName() 518 Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 519 Eventually(helpers.CF("bind-service", appName1, serviceInstanceName)).Should(Exit(0)) 520 521 appName2 := helpers.NewAppName() 522 Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 523 Eventually(helpers.CF("bind-service", appName2, serviceInstanceName)).Should(Exit(0)) 524 }) 525 helpers.TargetOrgAndSpace(orgName, sourceSpaceName) 526 }) 527 528 It("should display the number of bound apps next to the target space name", func() { 529 session := helpers.CF("service", serviceInstanceName) 530 Eventually(session).Should(Say("shared with spaces:")) 531 Eventually(session).Should(Say(`org\s+space\s+bindings`)) 532 Eventually(session).Should(Say(`%s\s+%s\s+2`, orgName, targetSpaceName)) 533 Eventually(session).Should(Exit(0)) 534 }) 535 }) 536 537 When("there are no externally bound apps to the service", func() { 538 It("should NOT display the number of bound apps next to the target space name", func() { 539 session := helpers.CF("service", serviceInstanceName) 540 Eventually(session).Should(Say("shared with spaces:")) 541 Eventually(session).Should(Say(`org\s+space\s+bindings`)) 542 Eventually(session).Should(Exit(0)) 543 }) 544 }) 545 546 When("the service is no longer shareable", func() { 547 Context("due to service broker settings", func() { 548 BeforeEach(func() { 549 broker.Services[0].Metadata.Shareable = false 550 broker.Update() 551 }) 552 553 It("should display that service instance sharing is disabled for this service", func() { 554 session := helpers.CF("service", serviceInstanceName) 555 Eventually(session).Should(Say("Service instance sharing is disabled for this service.")) 556 Eventually(session).Should(Exit(0)) 557 }) 558 }) 559 }) 560 }) 561 562 When("the user is targeted to the target space", func() { 563 var appName1, appName2 string 564 565 BeforeEach(func() { 566 // We test that the app names are listed in alphanumeric sort order 567 appName1 = helpers.PrefixedRandomName("2-INTEGRATION-APP") 568 appName2 = helpers.PrefixedRandomName("1-INTEGRATION-APP") 569 helpers.TargetOrgAndSpace(orgName, targetSpaceName) 570 helpers.WithHelloWorldApp(func(appDir string) { 571 Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 572 Eventually(helpers.CF("bind-service", appName1, serviceInstanceName)).Should(Exit(0)) 573 574 Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 575 Eventually(helpers.CF("bind-service", appName2, serviceInstanceName)).Should(Exit(0)) 576 }) 577 }) 578 579 When("there are bound apps to the service with no binding names", func() { 580 It("should display the bound apps in alphanumeric sort order", func() { 581 session := helpers.CF("service", serviceInstanceName) 582 Eventually(session).Should(Say(`shared from org/space:\s+%s / %s`, orgName, sourceSpaceName)) 583 Eventually(session).Should(Say("\n\n")) 584 Eventually(session).Should(Say("bound apps:")) 585 Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`)) 586 Eventually(session).Should(Say(appName2)) 587 Eventually(session).Should(Say(appName1)) 588 Eventually(session).Should(Exit(0)) 589 }) 590 }) 591 }) 592 }) 593 }) 594 })