github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/service_command_test.go (about) 1 package v6_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/actor/v2action" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 10 "code.cloudfoundry.org/cli/command/commandfakes" 11 . "code.cloudfoundry.org/cli/command/v6" 12 "code.cloudfoundry.org/cli/command/v6/v6fakes" 13 "code.cloudfoundry.org/cli/util/configv3" 14 "code.cloudfoundry.org/cli/util/ui" 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 . "github.com/onsi/gomega/gbytes" 18 ) 19 20 var _ = Describe("service Command", func() { 21 var ( 22 cmd ServiceCommand 23 testUI *ui.UI 24 fakeConfig *commandfakes.FakeConfig 25 fakeSharedActor *commandfakes.FakeSharedActor 26 fakeActor *v6fakes.FakeServiceActor 27 binaryName string 28 executeErr error 29 ) 30 31 BeforeEach(func() { 32 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 33 fakeConfig = new(commandfakes.FakeConfig) 34 fakeSharedActor = new(commandfakes.FakeSharedActor) 35 fakeActor = new(v6fakes.FakeServiceActor) 36 37 cmd = ServiceCommand{ 38 UI: testUI, 39 Config: fakeConfig, 40 SharedActor: fakeSharedActor, 41 Actor: fakeActor, 42 } 43 44 binaryName = "faceman" 45 fakeConfig.BinaryNameReturns(binaryName) 46 47 cmd.RequiredArgs.ServiceInstance = "some-service-instance" 48 }) 49 50 JustBeforeEach(func() { 51 executeErr = cmd.Execute(nil) 52 }) 53 54 When("an error is encountered checking if the environment is setup correctly", func() { 55 BeforeEach(func() { 56 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 57 }) 58 59 It("returns an error", func() { 60 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 61 62 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 63 checkTargetedOrgArg, checkTargetedSpaceArg := fakeSharedActor.CheckTargetArgsForCall(0) 64 Expect(checkTargetedOrgArg).To(BeTrue()) 65 Expect(checkTargetedSpaceArg).To(BeTrue()) 66 }) 67 }) 68 69 When("the user is logged in and an org and space are targeted", func() { 70 BeforeEach(func() { 71 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 72 Name: "some-org", 73 }) 74 fakeConfig.TargetedSpaceReturns(configv3.Space{ 75 GUID: "some-space-guid", 76 Name: "some-space", 77 }) 78 }) 79 80 When("getting the current user fails", func() { 81 BeforeEach(func() { 82 fakeConfig.CurrentUserReturns(configv3.User{}, errors.New("get-user-error")) 83 }) 84 85 It("returns the error", func() { 86 Expect(executeErr).To(MatchError("get-user-error")) 87 Expect(fakeConfig.CurrentUserCallCount()).To(Equal(1)) 88 }) 89 }) 90 91 When("getting the current user succeeds", func() { 92 BeforeEach(func() { 93 fakeConfig.CurrentUserReturns(configv3.User{Name: "some-user"}, nil) 94 }) 95 96 When("the '--guid' flag is provided", func() { 97 BeforeEach(func() { 98 cmd.GUID = true 99 }) 100 101 When("the service instance does not exist", func() { 102 BeforeEach(func() { 103 fakeActor.GetServiceInstanceByNameAndSpaceReturns( 104 v2action.ServiceInstance{}, 105 v2action.Warnings{"get-service-instance-warning"}, 106 actionerror.ServiceInstanceNotFoundError{ 107 GUID: "non-existant-service-instance-guid", 108 Name: "non-existant-service-instance", 109 }) 110 }) 111 112 It("returns ServiceInstanceNotFoundError", func() { 113 Expect(executeErr).To(MatchError(actionerror.ServiceInstanceNotFoundError{ 114 GUID: "non-existant-service-instance-guid", 115 Name: "non-existant-service-instance", 116 })) 117 118 Expect(testUI.Err).To(Say("get-service-instance-warning")) 119 120 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1)) 121 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceByNameAndSpaceArgsForCall(0) 122 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 123 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 124 125 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(0)) 126 }) 127 }) 128 129 When("an error is encountered getting the service instance", func() { 130 var expectedErr error 131 132 BeforeEach(func() { 133 expectedErr = errors.New("get-service-instance-error") 134 fakeActor.GetServiceInstanceByNameAndSpaceReturns( 135 v2action.ServiceInstance{}, 136 v2action.Warnings{"get-service-instance-warning"}, 137 expectedErr, 138 ) 139 }) 140 141 It("returns the error", func() { 142 Expect(executeErr).To(MatchError(expectedErr)) 143 144 Expect(testUI.Err).To(Say("get-service-instance-warning")) 145 146 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1)) 147 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceByNameAndSpaceArgsForCall(0) 148 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 149 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 150 151 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(0)) 152 }) 153 }) 154 155 When("no errors are encountered getting the service instance", func() { 156 BeforeEach(func() { 157 fakeActor.GetServiceInstanceByNameAndSpaceReturns( 158 v2action.ServiceInstance{ 159 GUID: "some-service-instance-guid", 160 Name: "some-service-instance", 161 }, 162 v2action.Warnings{"get-service-instance-warning"}, 163 nil, 164 ) 165 }) 166 167 It("displays the service instance guid", func() { 168 Expect(executeErr).ToNot(HaveOccurred()) 169 170 Expect(testUI.Out).To(Say("some-service-instance-guid")) 171 Expect(testUI.Err).To(Say("get-service-instance-warning")) 172 173 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1)) 174 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceByNameAndSpaceArgsForCall(0) 175 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 176 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 177 178 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(0)) 179 }) 180 }) 181 }) 182 183 When("the '--guid' flag is not provided", func() { 184 When("the service instance does not exist", func() { 185 BeforeEach(func() { 186 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 187 v2action.ServiceInstanceSummary{}, 188 v2action.Warnings{"get-service-instance-summary-warning"}, 189 actionerror.ServiceInstanceNotFoundError{ 190 GUID: "non-existant-service-instance-guid", 191 Name: "non-existant-service-instance", 192 }) 193 }) 194 195 It("returns ServiceInstanceNotFoundError", func() { 196 Expect(executeErr).To(MatchError(actionerror.ServiceInstanceNotFoundError{ 197 GUID: "non-existant-service-instance-guid", 198 Name: "non-existant-service-instance", 199 })) 200 201 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 202 203 Expect(testUI.Err).To(Say("get-service-instance-summary-warning")) 204 205 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 206 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 207 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 208 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 209 210 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 211 }) 212 }) 213 214 When("an error is encountered getting the service instance summary", func() { 215 var expectedErr error 216 217 BeforeEach(func() { 218 expectedErr = errors.New("get-service-instance-summary-error") 219 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 220 v2action.ServiceInstanceSummary{}, 221 v2action.Warnings{"get-service-instance-summary-warning"}, 222 expectedErr) 223 }) 224 225 It("returns the error", func() { 226 Expect(executeErr).To(MatchError(expectedErr)) 227 228 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 229 230 Expect(testUI.Err).To(Say("get-service-instance-summary-warning")) 231 232 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 233 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 234 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 235 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 236 237 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 238 }) 239 }) 240 241 When("no errors are encountered getting the service instance summary", func() { 242 When("the service instance is a managed service instance", func() { 243 var returnedSummary v2action.ServiceInstanceSummary 244 245 BeforeEach(func() { 246 returnedSummary = v2action.ServiceInstanceSummary{ 247 ServiceInstance: v2action.ServiceInstance{ 248 Name: "some-service-instance", 249 Type: constant.ServiceInstanceTypeManagedService, 250 Tags: []string{"tag-1", "tag-2", "tag-3"}, 251 DashboardURL: "some-dashboard", 252 LastOperation: ccv2.LastOperation{ 253 Type: "some-type", 254 State: "some-state", 255 Description: "some-last-operation-description", 256 UpdatedAt: "some-updated-at-time", 257 CreatedAt: "some-created-at-time", 258 }, 259 }, 260 ServicePlan: v2action.ServicePlan{Name: "some-plan"}, 261 Service: v2action.Service{ 262 Label: "some-service", 263 Description: "some-description", 264 DocumentationURL: "some-docs-url", 265 }, 266 } 267 268 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 269 returnedSummary, 270 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 271 nil) 272 }) 273 274 When("the service instance is not shared and is not shareable", func() { 275 BeforeEach(func() { 276 returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsNotShared 277 returnedSummary.Service.Extra.Shareable = false 278 returnedSummary.BoundApplications = []v2action.BoundApplication{ 279 { 280 AppName: "app-1", 281 ServiceBindingName: "binding-name-1", 282 }, 283 { 284 AppName: "app-2", 285 ServiceBindingName: "binding-name-2", 286 LastOperation: v2action.LastOperation{ 287 Type: "delete", 288 State: constant.LastOperationInProgress, 289 Description: "10% complete", 290 UpdatedAt: "some-updated-at-time", 291 CreatedAt: "some-created-at-time", 292 }, 293 }, 294 { 295 AppName: "app-3", 296 ServiceBindingName: "binding-name-3", 297 LastOperation: v2action.LastOperation{ 298 Type: "create", 299 State: constant.LastOperationFailed, 300 Description: "Binding failed", 301 UpdatedAt: "some-updated-at-time", 302 CreatedAt: "some-created-at-time", 303 }, 304 }, 305 { 306 AppName: "app-4", 307 ServiceBindingName: "binding-name-4", 308 LastOperation: v2action.LastOperation{ 309 Type: "create", 310 State: constant.LastOperationSucceeded, 311 Description: "Binding created", 312 UpdatedAt: "some-updated-at-time", 313 CreatedAt: "some-created-at-time", 314 }, 315 }, 316 } 317 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 318 returnedSummary, 319 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 320 nil) 321 322 }) 323 324 It("displays the service instance summary, all warnings and bound applications in the correct position", func() { 325 Expect(executeErr).ToNot(HaveOccurred()) 326 327 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 328 Expect(testUI.Out).To(Say("\n\n")) 329 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 330 Expect(testUI.Out).ToNot(Say("shared from org/space:")) 331 Expect(testUI.Out).To(Say(`service:\s+some-service`)) 332 Expect(testUI.Out).To(Say(`tags:\s+tag-1, tag-2, tag-3`)) 333 Expect(testUI.Out).To(Say(`plan:\s+some-plan`)) 334 Expect(testUI.Out).To(Say(`description:\s+some-description`)) 335 Expect(testUI.Out).To(Say(`documentation:\s+some-docs-url`)) 336 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 337 Expect(testUI.Out).To(Say("\n\n")) 338 Expect(testUI.Out).ToNot(Say("shared with spaces:")) 339 Expect(testUI.Out).ToNot(Say(`org\s+space\s+bindings`)) 340 Expect(testUI.Out).ToNot(Say("This service is not currently shared.")) 341 342 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 343 Expect(testUI.Out).To(Say("\n\n")) 344 Expect(testUI.Out).To(Say(`status:\s+some-type some-state`)) 345 Expect(testUI.Out).To(Say(`message:\s+some-last-operation-description`)) 346 Expect(testUI.Out).To(Say(`started:\s+some-created-at-time`)) 347 Expect(testUI.Out).To(Say(`updated:\s+some-updated-at-time`)) 348 Expect(testUI.Out).To(Say("\n\n")) 349 350 Expect(testUI.Out).To(Say("bound apps:")) 351 Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`)) 352 Expect(testUI.Out).To(Say(`app-1\s+binding-name-1\s+`)) 353 Expect(testUI.Out).To(Say(`app-2\s+binding-name-2\s+delete in progress\s+10\% complete`)) 354 Expect(testUI.Out).To(Say(`app-3\s+binding-name-3\s+create failed\s+Binding failed`)) 355 Expect(testUI.Out).To(Say(`app-4\s+binding-name-4\s+create succeeded\s+Binding created`)) 356 357 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 358 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 359 360 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 361 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 362 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 363 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 364 365 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 366 }) 367 }) 368 369 When("the service instance is not shared and is shareable", func() { 370 BeforeEach(func() { 371 returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsNotShared 372 returnedSummary.ServiceInstanceSharingFeatureFlag = true 373 returnedSummary.Service.Extra.Shareable = true 374 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 375 returnedSummary, 376 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 377 nil) 378 }) 379 380 It("displays the service instance summary and all warnings", func() { 381 Expect(executeErr).ToNot(HaveOccurred()) 382 383 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 384 Expect(testUI.Out).To(Say("\n\n")) 385 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 386 Expect(testUI.Out).ToNot(Say("shared from org/space:")) 387 Expect(testUI.Out).To(Say(`service:\s+some-service`)) 388 Expect(testUI.Out).To(Say(`tags:\s+tag-1, tag-2, tag-3`)) 389 Expect(testUI.Out).To(Say(`plan:\s+some-plan`)) 390 Expect(testUI.Out).To(Say(`description:\s+some-description`)) 391 Expect(testUI.Out).To(Say(`documentation:\s+some-docs-url`)) 392 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 393 Expect(testUI.Out).To(Say("\n\n")) 394 Expect(testUI.Out).ToNot(Say("shared with spaces:")) 395 Expect(testUI.Out).ToNot(Say(`org\s+space\s+bindings`)) 396 Expect(testUI.Out).To(Say("This service is not currently shared.")) 397 Expect(testUI.Out).To(Say("\n\n")) 398 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 399 Expect(testUI.Out).To(Say("\n\n")) 400 Expect(testUI.Out).To(Say(`status:\s+some-type some-state`)) 401 Expect(testUI.Out).To(Say(`message:\s+some-last-operation-description`)) 402 Expect(testUI.Out).To(Say(`started:\s+some-created-at-time`)) 403 Expect(testUI.Out).To(Say(`updated:\s+some-updated-at-time`)) 404 405 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 406 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 407 408 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 409 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 410 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 411 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 412 413 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 414 }) 415 }) 416 417 When("the service instance is shared from another space", func() { 418 BeforeEach(func() { 419 returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsSharedFrom 420 returnedSummary.ServiceInstanceSharedFrom = v2action.ServiceInstanceSharedFrom{ 421 SpaceGUID: "some-space-guid", 422 SpaceName: "some-space-name", 423 OrganizationName: "some-org-name", 424 } 425 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 426 returnedSummary, 427 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 428 nil) 429 }) 430 431 It("displays the shared from info and does not display the shared to info", func() { 432 Expect(executeErr).ToNot(HaveOccurred()) 433 434 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 435 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 436 Expect(testUI.Out).To(Say(`shared from org/space:\s+some-org-name / some-space-name`)) 437 Expect(testUI.Out).To(Say(`service:\s+some-service`)) 438 Expect(testUI.Out).ToNot(Say("shared with spaces:")) 439 440 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 441 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 442 }) 443 }) 444 445 When("the service instance is shared to other spaces", func() { 446 BeforeEach(func() { 447 returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsSharedTo 448 returnedSummary.ServiceInstanceSharedTos = []v2action.ServiceInstanceSharedTo{ 449 { 450 SpaceGUID: "another-space-guid", 451 SpaceName: "another-space-name", 452 OrganizationName: "another-org-name", 453 BoundAppCount: 2, 454 }, 455 { 456 SpaceGUID: "yet-another-space-guid", 457 SpaceName: "yet-another-space-name", 458 OrganizationName: "yet-another-org-name", 459 BoundAppCount: 3, 460 }, 461 } 462 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 463 returnedSummary, 464 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 465 nil) 466 }) 467 468 When("the service instance is still shareable", func() { 469 It("displays the shared to info and does not display the shared from info", func() { 470 Expect(executeErr).ToNot(HaveOccurred()) 471 472 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 473 Expect(testUI.Out).ToNot(Say("shared from org/space:")) 474 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 475 Expect(testUI.Out).To(Say("shared with spaces:")) 476 Expect(testUI.Out).To(Say(`org\s+space\s+bindings`)) 477 Expect(testUI.Out).To(Say(`another-org-name\s+another-space-name\s+2`)) 478 Expect(testUI.Out).To(Say(`yet-another-org-name\s+yet-another-space-name\s+3`)) 479 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 480 481 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 482 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 483 }) 484 }) 485 486 When("the service instance is no longer shareable due to global settings only", func() { 487 BeforeEach(func() { 488 returnedSummary.ServiceInstanceSharingFeatureFlag = false 489 returnedSummary.Service.Extra.Shareable = true 490 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 491 returnedSummary, 492 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 493 nil) 494 }) 495 496 It("displays the shared to info and message that the service instance feature flag is disabled", func() { 497 Expect(executeErr).ToNot(HaveOccurred()) 498 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 499 Expect(testUI.Out).ToNot(Say("shared from org/space:")) 500 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 501 Expect(testUI.Out).To(Say("\n\n")) 502 Expect(testUI.Out).To(Say(`The "service_instance_sharing" feature flag is disabled for this Cloud Foundry platform.`)) 503 Expect(testUI.Out).To(Say("\n\n")) 504 Expect(testUI.Out).To(Say("shared with spaces:")) 505 Expect(testUI.Out).To(Say(`org\s+space\s+bindings`)) 506 Expect(testUI.Out).To(Say(`another-org-name\s+another-space-name\s+2`)) 507 Expect(testUI.Out).To(Say(`yet-another-org-name\s+yet-another-space-name\s+3`)) 508 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 509 510 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 511 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 512 }) 513 }) 514 515 When("the service instance is no longer shareable due to service broker settings only", func() { 516 BeforeEach(func() { 517 returnedSummary.ServiceInstanceSharingFeatureFlag = true 518 returnedSummary.Service.Extra.Shareable = false 519 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 520 returnedSummary, 521 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 522 nil) 523 }) 524 525 It("displays the shared to info and message that service instance sharing is disabled for the service", func() { 526 Expect(executeErr).ToNot(HaveOccurred()) 527 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 528 Expect(testUI.Out).ToNot(Say("shared from org/space:")) 529 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 530 Expect(testUI.Out).To(Say("\n\n")) 531 Expect(testUI.Out).To(Say("Service instance sharing is disabled for this service.")) 532 Expect(testUI.Out).To(Say("\n\n")) 533 Expect(testUI.Out).To(Say("shared with spaces:")) 534 Expect(testUI.Out).To(Say(`org\s+space\s+bindings`)) 535 Expect(testUI.Out).To(Say(`another-org-name\s+another-space-name\s+2`)) 536 Expect(testUI.Out).To(Say(`yet-another-org-name\s+yet-another-space-name\s+3`)) 537 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 538 539 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 540 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 541 }) 542 }) 543 When("the service instance is no longer shareable due to global settings AND service broker settings", func() { 544 BeforeEach(func() { 545 returnedSummary.ServiceInstanceSharingFeatureFlag = false 546 returnedSummary.Service.Extra.Shareable = false 547 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 548 returnedSummary, 549 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 550 nil) 551 }) 552 553 It("displays the shared to info, the message that the service instance feature flag is disabled and that service instance sharing is disabled for the service", func() { 554 Expect(executeErr).ToNot(HaveOccurred()) 555 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 556 Expect(testUI.Out).ToNot(Say("shared from org/space:")) 557 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 558 Expect(testUI.Out).To(Say("\n\n")) 559 Expect(testUI.Out).To(Say(`The "service_instance_sharing" feature flag is disabled for this Cloud Foundry platform. Also, service instance sharing is disabled for this service.`)) 560 Expect(testUI.Out).To(Say("\n\n")) 561 Expect(testUI.Out).To(Say("shared with spaces:")) 562 Expect(testUI.Out).To(Say(`org\s+space\s+bindings`)) 563 Expect(testUI.Out).To(Say(`another-org-name\s+another-space-name\s+2`)) 564 Expect(testUI.Out).To(Say(`yet-another-org-name\s+yet-another-space-name\s+3`)) 565 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 566 567 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 568 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 569 }) 570 }) 571 }) 572 573 When("the service instance has bound apps", func() { 574 When("the service bindings have binding names", func() { 575 BeforeEach(func() { 576 returnedSummary.BoundApplications = []v2action.BoundApplication{ 577 { 578 AppName: "app-1", 579 ServiceBindingName: "binding-name-1", 580 }, 581 { 582 AppName: "app-2", 583 ServiceBindingName: "binding-name-2", 584 }, 585 { 586 AppName: "app-3", 587 ServiceBindingName: "binding-name-3", 588 }, 589 } 590 591 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 592 returnedSummary, 593 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 594 nil) 595 }) 596 597 It("displays the bound apps table with service binding names", func() { 598 Expect(executeErr).ToNot(HaveOccurred()) 599 600 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 601 Expect(testUI.Out).To(Say("\n\n")) 602 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 603 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 604 Expect(testUI.Out).To(Say("\n\n")) 605 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 606 Expect(testUI.Out).To(Say("\n\n")) 607 Expect(testUI.Out).To(Say("bound apps:")) 608 Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`)) 609 Expect(testUI.Out).To(Say(`app-1\s+binding-name-1`)) 610 Expect(testUI.Out).To(Say(`app-2\s+binding-name-2`)) 611 Expect(testUI.Out).To(Say(`app-3\s+binding-name-3`)) 612 613 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 614 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 615 616 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 617 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 618 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 619 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 620 621 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 622 }) 623 }) 624 625 When("the service bindings do not have binding names", func() { 626 BeforeEach(func() { 627 returnedSummary.BoundApplications = []v2action.BoundApplication{ 628 {AppName: "app-1"}, 629 {AppName: "app-2"}, 630 {AppName: "app-3"}, 631 } 632 633 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 634 returnedSummary, 635 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 636 nil) 637 }) 638 639 It("displays the bound apps table with NO service binding names", func() { 640 Expect(executeErr).ToNot(HaveOccurred()) 641 642 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 643 Expect(testUI.Out).To(Say("\n\n")) 644 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 645 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 646 Expect(testUI.Out).To(Say("\n\n")) 647 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 648 Expect(testUI.Out).To(Say("\n\n")) 649 Expect(testUI.Out).To(Say("bound apps:")) 650 Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`)) 651 Expect(testUI.Out).To(Say("app-1")) 652 Expect(testUI.Out).To(Say("app-2")) 653 Expect(testUI.Out).To(Say("app-3")) 654 655 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 656 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 657 658 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 659 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 660 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 661 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 662 663 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 664 }) 665 }) 666 }) 667 668 When("the service instance does not have bound apps", func() { 669 It("displays a message indicating that there are no bound apps", func() { 670 Expect(executeErr).ToNot(HaveOccurred()) 671 672 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 673 Expect(testUI.Out).To(Say("\n\n")) 674 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 675 Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`)) 676 Expect(testUI.Out).To(Say("\n\n")) 677 Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`)) 678 Expect(testUI.Out).To(Say("\n\n")) 679 Expect(testUI.Out).To(Say("There are no bound apps for this service.")) 680 681 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 682 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 683 684 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 685 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 686 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 687 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 688 689 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 690 }) 691 692 }) 693 }) 694 695 When("the service instance is a user provided service instance", func() { 696 BeforeEach(func() { 697 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 698 v2action.ServiceInstanceSummary{ 699 ServiceInstance: v2action.ServiceInstance{ 700 Name: "some-service-instance", 701 Type: constant.ServiceInstanceTypeUserProvidedService, 702 }, 703 }, 704 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 705 nil, 706 ) 707 }) 708 709 It("displays a smaller service instance summary than for managed service instances", func() { 710 Expect(executeErr).ToNot(HaveOccurred()) 711 712 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 713 Expect(testUI.Out).To(Say("")) 714 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 715 Expect(testUI.Out).ToNot(Say("shared from")) 716 Expect(testUI.Out).To(Say(`service:\s+user-provided`)) 717 Expect(testUI.Out).To(Say("tags:")) 718 Expect(testUI.Out).ToNot(Say("plan:")) 719 Expect(testUI.Out).ToNot(Say("description:")) 720 Expect(testUI.Out).ToNot(Say("documentation:")) 721 Expect(testUI.Out).ToNot(Say("dashboard:")) 722 Expect(testUI.Out).ToNot(Say("shared with spaces")) 723 Expect(testUI.Out).ToNot(Say("last operation")) 724 Expect(testUI.Out).ToNot(Say("status:")) 725 Expect(testUI.Out).ToNot(Say("message:")) 726 Expect(testUI.Out).ToNot(Say("started:")) 727 Expect(testUI.Out).ToNot(Say("updated:")) 728 729 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 730 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 731 732 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 733 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 734 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 735 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 736 737 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 738 }) 739 740 When("the service instance has bound apps", func() { 741 When("the service bindings have binding names", func() { 742 BeforeEach(func() { 743 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 744 v2action.ServiceInstanceSummary{ 745 ServiceInstance: v2action.ServiceInstance{ 746 Name: "some-service-instance", 747 Type: constant.ServiceInstanceTypeUserProvidedService, 748 }, 749 BoundApplications: []v2action.BoundApplication{ 750 { 751 AppName: "app-1", 752 ServiceBindingName: "binding-name-1", 753 }, 754 { 755 AppName: "app-2", 756 ServiceBindingName: "binding-name-2", 757 }, 758 { 759 AppName: "app-3", 760 ServiceBindingName: "binding-name-3", 761 }, 762 }, 763 }, 764 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 765 nil, 766 ) 767 }) 768 769 It("displays the bound apps table with service binding names", func() { 770 Expect(executeErr).ToNot(HaveOccurred()) 771 772 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 773 Expect(testUI.Out).To(Say("\n\n")) 774 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 775 Expect(testUI.Out).To(Say(`service:\s+user-provided`)) 776 Expect(testUI.Out).To(Say("\n\n")) 777 Expect(testUI.Out).To(Say("bound apps:")) 778 Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`)) 779 Expect(testUI.Out).To(Say(`app-1\s+binding-name-1`)) 780 Expect(testUI.Out).To(Say(`app-2\s+binding-name-2`)) 781 Expect(testUI.Out).To(Say(`app-3\s+binding-name-3`)) 782 783 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 784 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 785 786 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 787 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 788 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 789 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 790 791 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 792 }) 793 }) 794 795 When("the service bindings do not have binding names", func() { 796 BeforeEach(func() { 797 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 798 v2action.ServiceInstanceSummary{ 799 ServiceInstance: v2action.ServiceInstance{ 800 Name: "some-service-instance", 801 Type: constant.ServiceInstanceTypeUserProvidedService, 802 }, 803 BoundApplications: []v2action.BoundApplication{ 804 {AppName: "app-1"}, 805 {AppName: "app-2"}, 806 {AppName: "app-3"}, 807 }, 808 }, 809 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 810 nil, 811 ) 812 }) 813 814 It("displays the bound apps table with NO service binding names", func() { 815 Expect(executeErr).ToNot(HaveOccurred()) 816 817 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 818 Expect(testUI.Out).To(Say("\n\n")) 819 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 820 Expect(testUI.Out).To(Say(`service:\s+user-provided`)) 821 Expect(testUI.Out).To(Say("\n\n")) 822 Expect(testUI.Out).To(Say("bound apps:")) 823 Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`)) 824 Expect(testUI.Out).To(Say("app-1")) 825 Expect(testUI.Out).To(Say("app-2")) 826 Expect(testUI.Out).To(Say("app-3")) 827 828 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1")) 829 Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2")) 830 831 Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1)) 832 serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0) 833 Expect(serviceInstanceNameArg).To(Equal("some-service-instance")) 834 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 835 836 Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0)) 837 }) 838 839 }) 840 }) 841 842 When("the service instance does not have bound apps", func() { 843 It("displays a message indicating that there are no bound apps", func() { 844 Expect(executeErr).ToNot(HaveOccurred()) 845 846 Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`)) 847 Expect(testUI.Out).To(Say("\n\n")) 848 Expect(testUI.Out).To(Say(`name:\s+some-service-instance`)) 849 Expect(testUI.Out).To(Say(`service:\s+user-provided`)) 850 Expect(testUI.Out).To(Say("\n\n")) 851 Expect(testUI.Out).To(Say("There are no bound apps for this service.")) 852 }) 853 }) 854 855 When("the service instance have tags", func() { 856 BeforeEach(func() { 857 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 858 v2action.ServiceInstanceSummary{ 859 ServiceInstance: v2action.ServiceInstance{ 860 Name: "some-service-instance", 861 Type: constant.ServiceInstanceTypeUserProvidedService, 862 Tags: []string{"tag-1", "tag-2", "tag-3"}, 863 }, 864 }, 865 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 866 nil, 867 ) 868 }) 869 870 It("displays the tags", func() { 871 Expect(executeErr).ToNot(HaveOccurred()) 872 873 Expect(testUI.Out).To(Say(`tags:\s+tag-1, tag-2, tag-3`)) 874 }) 875 }) 876 877 When("the service instance has route service url", func() { 878 BeforeEach(func() { 879 fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns( 880 v2action.ServiceInstanceSummary{ 881 ServiceInstance: v2action.ServiceInstance{ 882 Name: "some-service-instance", 883 Type: constant.ServiceInstanceTypeUserProvidedService, 884 RouteServiceURL: "some-route-service-url", 885 }, 886 }, 887 v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"}, 888 nil, 889 ) 890 }) 891 892 It("displays the route service url", func() { 893 Expect(executeErr).ToNot(HaveOccurred()) 894 895 Expect(testUI.Out).To(Say(`route service url:\s+some-route-service-url`)) 896 }) 897 }) 898 }) 899 }) 900 }) 901 }) 902 }) 903 })