github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/actor/v2action/composite/service_broker_summary_test.go (about) 1 package composite_test 2 3 import ( 4 "errors" 5 "fmt" 6 7 "code.cloudfoundry.org/cli/actor/actionerror" 8 "code.cloudfoundry.org/cli/actor/v2action" 9 . "code.cloudfoundry.org/cli/actor/v2action/composite" 10 "code.cloudfoundry.org/cli/actor/v2action/composite/compositefakes" 11 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("Service Broker Summary Actions", func() { 18 var ( 19 fakeServiceActor *compositefakes.FakeServiceActor 20 fakeBrokerActor *compositefakes.FakeBrokerActor 21 fakeOrgActor *compositefakes.FakeOrganizationActor 22 fakeVisibilityActor *compositefakes.FakeVisibilityActor 23 actor *ServiceBrokerSummaryCompositeActor 24 ) 25 26 BeforeEach(func() { 27 fakeOrgActor = new(compositefakes.FakeOrganizationActor) 28 fakeServiceActor = new(compositefakes.FakeServiceActor) 29 fakeBrokerActor = new(compositefakes.FakeBrokerActor) 30 fakeVisibilityActor = new(compositefakes.FakeVisibilityActor) 31 actor = &ServiceBrokerSummaryCompositeActor{ 32 ServiceActor: fakeServiceActor, 33 BrokerActor: fakeBrokerActor, 34 OrgActor: fakeOrgActor, 35 VisibilityActor: fakeVisibilityActor, 36 } 37 }) 38 39 Describe("GetServiceBrokerSummaries", func() { 40 var ( 41 broker string 42 service string 43 organization string 44 45 summaries []v2action.ServiceBrokerSummary 46 warnings v2action.Warnings 47 executeErr error 48 ) 49 50 JustBeforeEach(func() { 51 summaries, warnings, executeErr = actor.GetServiceBrokerSummaries(broker, service, organization) 52 }) 53 54 When("no broker, service, organization is specified", func() { 55 BeforeEach(func() { 56 broker = "" 57 service = "" 58 organization = "" 59 }) 60 61 When("fetching the service broker is successful", func() { 62 BeforeEach(func() { 63 fakeBrokerActor.GetServiceBrokersReturns( 64 []v2action.ServiceBroker{ 65 {Name: "broker-1", GUID: "broker-guid-1"}, 66 {Name: "broker-2", GUID: "broker-guid-2"}, 67 }, 68 v2action.Warnings{"get-brokers-warning"}, nil) 69 }) 70 71 When("the brokers contain no services", func() { 72 It("returns expected Service Brokers", func() { 73 Expect(executeErr).ToNot(HaveOccurred()) 74 Expect(warnings).To(ConsistOf("get-brokers-warning")) 75 Expect(summaries).To(ConsistOf( 76 v2action.ServiceBrokerSummary{ 77 ServiceBroker: v2action.ServiceBroker{ 78 Name: "broker-1", 79 GUID: "broker-guid-1", 80 }, 81 }, 82 v2action.ServiceBrokerSummary{ 83 ServiceBroker: v2action.ServiceBroker{ 84 Name: "broker-2", 85 GUID: "broker-guid-2", 86 }, 87 }, 88 )) 89 90 Expect(fakeBrokerActor.GetServiceBrokersCallCount()).To(Equal(1)) 91 }) 92 }) 93 94 When("the brokers contain services", func() { 95 When("fetching the services is successful", func() { 96 When("the services contain no plans", func() { 97 BeforeEach(func() { 98 fakeServiceActor.GetServicesWithPlansReturnsOnCall(0, 99 v2action.ServicesWithPlans{ 100 v2action.Service{Label: "service-1", GUID: "service-guid-1"}: nil, 101 v2action.Service{Label: "service-2", GUID: "service-guid-2"}: nil, 102 }, v2action.Warnings{"service-warning-1"}, nil) 103 fakeServiceActor.GetServicesWithPlansReturnsOnCall(1, 104 v2action.ServicesWithPlans{ 105 v2action.Service{Label: "service-3", GUID: "service-guid-3"}: nil, 106 v2action.Service{Label: "service-4", GUID: "service-guid-4"}: nil, 107 }, v2action.Warnings{"service-warning-2"}, nil) 108 }) 109 110 It("returns expected Services for their given brokers", func() { 111 Expect(executeErr).ToNot(HaveOccurred()) 112 Expect(warnings).To(ConsistOf("get-brokers-warning", "service-warning-1", "service-warning-2")) 113 Expect(summaries[0].Services).To(ConsistOf( 114 []v2action.ServiceSummary{ 115 { 116 Service: v2action.Service{Label: "service-1", GUID: "service-guid-1"}, 117 }, 118 { 119 Service: v2action.Service{Label: "service-2", GUID: "service-guid-2"}, 120 }, 121 }, 122 )) 123 Expect(summaries[1].Services).To(ConsistOf( 124 []v2action.ServiceSummary{ 125 { 126 Service: v2action.Service{Label: "service-3", GUID: "service-guid-3"}, 127 }, 128 { 129 Service: v2action.Service{Label: "service-4", GUID: "service-guid-4"}, 130 }, 131 }, 132 )) 133 134 Expect(fakeServiceActor.GetServicesWithPlansCallCount()).To(Equal(2)) 135 Expect(fakeServiceActor.GetServicesWithPlansArgsForCall(0)).To(ConsistOf( 136 v2action.Filter{ 137 Type: constant.ServiceBrokerGUIDFilter, 138 Operator: constant.EqualOperator, 139 Values: []string{"broker-guid-1"}, 140 }, 141 )) 142 Expect(fakeServiceActor.GetServicesWithPlansArgsForCall(1)).To(ConsistOf( 143 v2action.Filter{ 144 Type: constant.ServiceBrokerGUIDFilter, 145 Operator: constant.EqualOperator, 146 Values: []string{"broker-guid-2"}, 147 }, 148 )) 149 }) 150 }) 151 152 When("the services contain plans", func() { 153 When("fetching service plans is successful", func() { 154 When("all plans are public", func() { 155 BeforeEach(func() { 156 fakeServiceActor.GetServicesWithPlansReturnsOnCall(0, v2action.ServicesWithPlans{ 157 v2action.Service{Label: "service-1", GUID: "service-guid-1"}: []v2action.ServicePlan{ 158 {GUID: "service-plan-guid-1", Name: "service-plan-1", Public: true}, 159 {GUID: "service-plan-guid-2", Name: "service-plan-2", Public: true}, 160 }, 161 v2action.Service{Label: "service-2", GUID: "service-guid-2"}: nil, 162 }, v2action.Warnings{"service-warning-1"}, nil) 163 164 fakeServiceActor.GetServicesWithPlansReturnsOnCall(1, v2action.ServicesWithPlans{ 165 v2action.Service{Label: "service-3", GUID: "service-guid-3"}: []v2action.ServicePlan{ 166 {GUID: "service-plan-guid-3", Name: "service-plan-3", Public: true}, 167 {GUID: "service-plan-guid-4", Name: "service-plan-4", Public: true}, 168 }, 169 v2action.Service{Label: "service-4", GUID: "service-guid-4"}: nil, 170 }, v2action.Warnings{"service-warning-2"}, nil) 171 }) 172 173 It("returns the expected Service with Plans without visibilities", func() { 174 Expect(executeErr).ToNot(HaveOccurred()) 175 Expect(warnings).To(ConsistOf( 176 "get-brokers-warning", "service-warning-1", "service-warning-2")) 177 178 Expect(summaries[0].Services).To(ConsistOf( 179 v2action.ServiceSummary{ 180 Service: v2action.Service{Label: "service-1", GUID: "service-guid-1"}, 181 Plans: []v2action.ServicePlanSummary{ 182 { 183 ServicePlan: v2action.ServicePlan{GUID: "service-plan-guid-1", Name: "service-plan-1", Public: true}, 184 }, 185 { 186 ServicePlan: v2action.ServicePlan{GUID: "service-plan-guid-2", Name: "service-plan-2", Public: true}, 187 }, 188 }, 189 }, 190 v2action.ServiceSummary{ 191 Service: v2action.Service{Label: "service-2", GUID: "service-guid-2"}, 192 }, 193 )) 194 Expect(summaries[1].Services).To(ConsistOf( 195 v2action.ServiceSummary{ 196 Service: v2action.Service{Label: "service-3", GUID: "service-guid-3"}, 197 Plans: []v2action.ServicePlanSummary{ 198 { 199 ServicePlan: v2action.ServicePlan{GUID: "service-plan-guid-3", Name: "service-plan-3", Public: true}, 200 }, 201 { 202 ServicePlan: v2action.ServicePlan{GUID: "service-plan-guid-4", Name: "service-plan-4", Public: true}, 203 }, 204 }, 205 }, 206 v2action.ServiceSummary{ 207 Service: v2action.Service{Label: "service-4", GUID: "service-guid-4"}, 208 }, 209 )) 210 211 Expect(fakeServiceActor.GetServicesWithPlansCallCount()).To(Equal(2)) 212 Expect(fakeServiceActor.GetServicesWithPlansArgsForCall(0)).To(ConsistOf( 213 v2action.Filter{ 214 Type: constant.ServiceBrokerGUIDFilter, 215 Operator: constant.EqualOperator, 216 Values: []string{"broker-guid-1"}, 217 }, 218 )) 219 Expect(fakeServiceActor.GetServicesWithPlansArgsForCall(1)).To(ConsistOf( 220 v2action.Filter{ 221 Type: constant.ServiceBrokerGUIDFilter, 222 Operator: constant.EqualOperator, 223 Values: []string{"broker-guid-2"}, 224 }, 225 )) 226 227 Expect(fakeVisibilityActor.GetServicePlanVisibilitiesCallCount()).To(Equal(0)) 228 }) 229 }) 230 231 When("there are non-public plans", func() { 232 BeforeEach(func() { 233 fakeServiceActor.GetServicesWithPlansReturnsOnCall(0, v2action.ServicesWithPlans{ 234 v2action.Service{Label: "service-1", GUID: "service-guid-1"}: []v2action.ServicePlan{ 235 {GUID: "service-plan-guid-1", Name: "service-plan-1", Public: false}, 236 {GUID: "service-plan-guid-2", Name: "service-plan-2", Public: false}, 237 }, 238 v2action.Service{Label: "service-2", GUID: "service-guid-2"}: nil, 239 }, v2action.Warnings{"service-warning-1"}, nil) 240 fakeServiceActor.GetServicesWithPlansReturnsOnCall(1, v2action.ServicesWithPlans{}, 241 v2action.Warnings{"service-warning-2"}, nil) 242 }) 243 244 When("fetching orgs and service plan visibilities is successful", func() { 245 BeforeEach(func() { 246 fakeVisibilityActor.GetServicePlanVisibilitiesReturnsOnCall(0, 247 []v2action.ServicePlanVisibility{ 248 {OrganizationGUID: "org-guid-1"}, 249 {OrganizationGUID: "org-guid-2"}, 250 }, 251 v2action.Warnings{"service-plan-visibility-1"}, 252 nil) 253 fakeVisibilityActor.GetServicePlanVisibilitiesReturnsOnCall(1, 254 []v2action.ServicePlanVisibility{ 255 {OrganizationGUID: "org-guid-3"}, 256 {OrganizationGUID: "org-guid-4"}, 257 }, 258 v2action.Warnings{"service-plan-visibility-2"}, 259 nil) 260 261 fakeOrgActor.GetOrganizationReturnsOnCall(0, 262 v2action.Organization{Name: "org-1"}, 263 v2action.Warnings{"org-warning-1"}, 264 nil) 265 fakeOrgActor.GetOrganizationReturnsOnCall(1, 266 v2action.Organization{Name: "org-2"}, 267 v2action.Warnings{"org-warning-2"}, 268 nil) 269 fakeOrgActor.GetOrganizationReturnsOnCall(2, 270 v2action.Organization{Name: "org-3"}, 271 v2action.Warnings{"org-warning-3"}, 272 nil) 273 fakeOrgActor.GetOrganizationReturnsOnCall(3, 274 v2action.Organization{Name: "org-4"}, 275 v2action.Warnings{"org-warning-4"}, 276 nil) 277 }) 278 279 It("returns the expected Service Plans", func() { 280 Expect(executeErr).ToNot(HaveOccurred()) 281 Expect(warnings).To(ConsistOf( 282 "get-brokers-warning", 283 "service-warning-1", "service-warning-2", 284 "service-plan-visibility-1", "service-plan-visibility-2", 285 "org-warning-1", "org-warning-2", "org-warning-3", "org-warning-4", 286 )) 287 288 Expect(summaries[0].Services).To(ConsistOf( 289 v2action.ServiceSummary{ 290 Service: v2action.Service{Label: "service-1", GUID: "service-guid-1"}, 291 Plans: []v2action.ServicePlanSummary{ 292 { 293 ServicePlan: v2action.ServicePlan{GUID: "service-plan-guid-1", Name: "service-plan-1", Public: false}, 294 VisibleTo: []string{"org-1", "org-2"}, 295 }, 296 { 297 ServicePlan: v2action.ServicePlan{GUID: "service-plan-guid-2", Name: "service-plan-2", Public: false}, 298 VisibleTo: []string{"org-3", "org-4"}, 299 }, 300 }, 301 }, 302 v2action.ServiceSummary{ 303 Service: v2action.Service{Label: "service-2", GUID: "service-guid-2"}, 304 }, 305 )) 306 307 Expect(fakeVisibilityActor.GetServicePlanVisibilitiesCallCount()).To(Equal(2)) 308 Expect(fakeVisibilityActor.GetServicePlanVisibilitiesArgsForCall(0)).To(Equal("service-plan-guid-1")) 309 Expect(fakeVisibilityActor.GetServicePlanVisibilitiesArgsForCall(1)).To(Equal("service-plan-guid-2")) 310 }) 311 }) 312 313 When("fetching the service plan visibilities fails", func() { 314 BeforeEach(func() { 315 fakeVisibilityActor.GetServicePlanVisibilitiesReturns( 316 nil, 317 v2action.Warnings{"service-plan-visibility-1"}, 318 errors.New("boom")) 319 }) 320 321 It("returns the error and warnings", func() { 322 Expect(executeErr).To(MatchError("boom")) 323 Expect(warnings).To(ConsistOf( 324 "get-brokers-warning", 325 "service-warning-1", 326 "service-plan-visibility-1", 327 )) 328 }) 329 }) 330 }) 331 332 When("fetching the organizations fails", func() { 333 BeforeEach(func() { 334 fakeServiceActor.GetServicesWithPlansReturns(v2action.ServicesWithPlans{ 335 v2action.Service{Label: "service-1", GUID: "service-guid-1"}: []v2action.ServicePlan{ 336 {GUID: "service-plan-guid-1", Name: "service-plan-1", Public: false}, 337 }, 338 v2action.Service{Label: "service-2", GUID: "service-guid-2"}: nil, 339 }, v2action.Warnings{"service-warning-1"}, nil) 340 fakeVisibilityActor.GetServicePlanVisibilitiesReturns( 341 []v2action.ServicePlanVisibility{ 342 {OrganizationGUID: "org-guid-1"}, 343 {OrganizationGUID: "org-guid-2"}, 344 }, 345 v2action.Warnings{"service-plan-visibility-1"}, 346 nil) 347 348 fakeOrgActor.GetOrganizationReturnsOnCall(0, 349 v2action.Organization{}, 350 v2action.Warnings{"org-warning-1"}, 351 errors.New("boom")) 352 }) 353 354 It("returns the error and warnings", func() { 355 Expect(executeErr).To(MatchError("boom")) 356 Expect(warnings).To(ConsistOf( 357 "get-brokers-warning", 358 "service-warning-1", 359 "service-plan-visibility-1", 360 "org-warning-1", 361 )) 362 }) 363 }) 364 }) 365 }) 366 }) 367 }) 368 369 When("fetching services with plans fails", func() { 370 BeforeEach(func() { 371 fakeServiceActor.GetServicesWithPlansReturns( 372 nil, 373 v2action.Warnings{"service-warning-1"}, 374 errors.New("boom"), 375 ) 376 }) 377 378 It("returns the error and warnings", func() { 379 Expect(executeErr).To(MatchError("boom")) 380 Expect(warnings).To(ConsistOf("get-brokers-warning", "service-warning-1")) 381 }) 382 }) 383 }) 384 385 When("fetching service brokers fails", func() { 386 BeforeEach(func() { 387 fakeBrokerActor.GetServiceBrokersReturns(nil, v2action.Warnings{"test-warning"}, errors.New("explode")) 388 }) 389 390 It("returns the warnings and propagates the error", func() { 391 Expect(warnings).To(ConsistOf("test-warning")) 392 Expect(executeErr).To(MatchError("explode")) 393 }) 394 }) 395 }) 396 397 When("service broker is specified", func() { 398 BeforeEach(func() { 399 broker = "broker-1" 400 service = "" 401 organization = "" 402 403 fakeBrokerActor.GetServiceBrokerByNameReturns( 404 v2action.ServiceBroker{Name: "broker-1", GUID: "broker-guid-1"}, 405 v2action.Warnings{"get-broker-warning"}, 406 nil) 407 }) 408 409 It("returns expected Service Brokers", func() { 410 Expect(executeErr).ToNot(HaveOccurred()) 411 Expect(warnings).To(ConsistOf("get-broker-warning")) 412 Expect(summaries).To(ConsistOf( 413 v2action.ServiceBrokerSummary{ 414 ServiceBroker: v2action.ServiceBroker{ 415 Name: "broker-1", 416 GUID: "broker-guid-1", 417 }, 418 })) 419 420 Expect(fakeBrokerActor.GetServiceBrokerByNameCallCount()).To(Equal(1)) 421 Expect(fakeBrokerActor.GetServiceBrokerByNameArgsForCall(0)).To(Equal("broker-1")) 422 }) 423 424 When("fetching the service broker fails", func() { 425 BeforeEach(func() { 426 fakeBrokerActor.GetServiceBrokerByNameReturns( 427 v2action.ServiceBroker{}, 428 v2action.Warnings{"get-broker-warning"}, 429 fmt.Errorf("it broke")) 430 }) 431 432 It("returns the error and warnings", func() { 433 Expect(executeErr).To(MatchError("it broke")) 434 Expect(warnings).To(ConsistOf("get-broker-warning")) 435 }) 436 }) 437 }) 438 439 When("a service name is specified", func() { 440 BeforeEach(func() { 441 broker = "" 442 service = "service-1" 443 organization = "" 444 445 fakeBrokerActor.GetServiceBrokersReturns( 446 []v2action.ServiceBroker{ 447 {Name: "broker-1", GUID: "broker-guid-1"}, 448 }, 449 v2action.Warnings{"get-brokers-warning"}, nil) 450 }) 451 452 When("the specified service exists", func() { 453 BeforeEach(func() { 454 fakeServiceActor.ServiceExistsWithNameReturns(true, 455 v2action.Warnings{"service-exists-with-name-warning"}, nil) 456 }) 457 458 It("fetches services on brokers filtered by name", func() { 459 Expect(executeErr).ToNot(HaveOccurred()) 460 Expect(warnings).To(ConsistOf("get-brokers-warning", "service-exists-with-name-warning")) 461 462 Expect(fakeServiceActor.GetServicesWithPlansCallCount()).To(Equal(1)) 463 Expect(fakeServiceActor.GetServicesWithPlansArgsForCall(0)).To(ConsistOf( 464 v2action.Filter{ 465 Type: constant.ServiceBrokerGUIDFilter, 466 Operator: constant.EqualOperator, 467 Values: []string{"broker-guid-1"}, 468 }, 469 v2action.Filter{ 470 Type: constant.LabelFilter, 471 Operator: constant.EqualOperator, 472 Values: []string{"service-1"}, 473 }, 474 )) 475 }) 476 477 When("a particular broker has no services with that name", func() { 478 BeforeEach(func() { 479 fakeServiceActor.GetServicesWithPlansReturns(v2action.ServicesWithPlans{}, nil, nil) 480 }) 481 482 It("does not return a summary for that broker", func() { 483 Expect(executeErr).ToNot(HaveOccurred()) 484 Expect(summaries).To(HaveLen(0)) 485 }) 486 }) 487 }) 488 489 When("checking whether the service exists returns an error", func() { 490 BeforeEach(func() { 491 fakeServiceActor.ServiceExistsWithNameReturns(false, 492 v2action.Warnings{"service-exists-with-name-warning"}, errors.New("boom")) 493 }) 494 495 It("propagates the error with warnings", func() { 496 Expect(executeErr).To(MatchError("boom")) 497 Expect(warnings).To(ConsistOf("service-exists-with-name-warning")) 498 }) 499 }) 500 501 When("a service with the specified name does not exist", func() { 502 BeforeEach(func() { 503 fakeServiceActor.ServiceExistsWithNameReturns(false, 504 v2action.Warnings{"service-exists-with-name-warning"}, nil) 505 }) 506 507 It("returns an appropriate error message", func() { 508 Expect(executeErr).To(MatchError(actionerror.ServiceNotFoundError{Name: "service-1"})) 509 Expect(warnings).To(ConsistOf("service-exists-with-name-warning")) 510 }) 511 }) 512 }) 513 514 When("an org is specified", func() { 515 BeforeEach(func() { 516 broker = "" 517 service = "" 518 organization = "my-org" 519 520 fakeBrokerActor.GetServiceBrokersReturns( 521 []v2action.ServiceBroker{ 522 {Name: "broker-1", GUID: "broker-guid-1"}, 523 }, 524 v2action.Warnings{"get-brokers-warning"}, nil) 525 }) 526 527 When("the specified org exists", func() { 528 BeforeEach(func() { 529 fakeOrgActor.OrganizationExistsWithNameReturns( 530 true, 531 v2action.Warnings{"org-warning-1"}, 532 nil) 533 }) 534 535 When("plans are public", func() { 536 BeforeEach(func() { 537 fakeServiceActor.GetServicesWithPlansReturns(v2action.ServicesWithPlans{ 538 v2action.Service{Label: "service-1", GUID: "service-guid-1"}: []v2action.ServicePlan{ 539 {GUID: "service-plan-guid-1", Name: "service-plan-1", Public: true}, 540 }, 541 }, v2action.Warnings{"get-service-plans-warning"}, nil) 542 543 }) 544 545 It("returns those plans", func() { 546 Expect(executeErr).ToNot(HaveOccurred()) 547 Expect(warnings).To(ConsistOf("org-warning-1", "get-brokers-warning", "get-service-plans-warning")) 548 Expect(summaries[0].Services).To(ConsistOf( 549 v2action.ServiceSummary{ 550 Service: v2action.Service{Label: "service-1", GUID: "service-guid-1"}, 551 Plans: []v2action.ServicePlanSummary{ 552 { 553 ServicePlan: v2action.ServicePlan{GUID: "service-plan-guid-1", Name: "service-plan-1", Public: true}, 554 }, 555 }, 556 }, 557 )) 558 }) 559 }) 560 561 When("all plans for all services for all brokers are private with no visibilities", func() { 562 BeforeEach(func() { 563 fakeServiceActor.GetServicesWithPlansReturns(v2action.ServicesWithPlans{ 564 v2action.Service{Label: "service-1", GUID: "service-guid-1"}: []v2action.ServicePlan{ 565 {GUID: "service-plan-guid-1", Name: "service-plan-1", Public: false}, 566 }, 567 }, v2action.Warnings{"get-service-plans-warning"}, nil) 568 }) 569 570 It("returns no broker summaries", func() { 571 Expect(executeErr).ToNot(HaveOccurred()) 572 Expect(warnings).To(ConsistOf("org-warning-1", "get-brokers-warning", "get-service-plans-warning")) 573 Expect(len(summaries)).To(Equal(0)) 574 }) 575 }) 576 577 When("a plan is visible in the provided org", func() { 578 BeforeEach(func() { 579 fakeServiceActor.GetServicesWithPlansReturns(v2action.ServicesWithPlans{ 580 v2action.Service{Label: "service-1", GUID: "service-guid-1"}: []v2action.ServicePlan{ 581 {GUID: "service-plan-guid-1", Name: "service-plan-1", Public: false}, 582 }, 583 }, v2action.Warnings{"get-service-plans-warning"}, nil) 584 585 fakeVisibilityActor.GetServicePlanVisibilitiesReturns([]v2action.ServicePlanVisibility{ 586 {OrganizationGUID: "my-org-guid"}, 587 }, v2action.Warnings{"get-service-plan-visibility-warning"}, nil) 588 589 fakeOrgActor.GetOrganizationReturns(v2action.Organization{Name: "my-org"}, 590 v2action.Warnings{"org-warning-2"}, nil) 591 }) 592 593 It("should return that plan", func() { 594 Expect(executeErr).ToNot(HaveOccurred()) 595 Expect(warnings).To(ConsistOf("org-warning-1", "get-brokers-warning", "get-service-plans-warning", "get-service-plan-visibility-warning", "org-warning-2")) 596 Expect(summaries[0].Services).To(ConsistOf( 597 v2action.ServiceSummary{ 598 Service: v2action.Service{Label: "service-1", GUID: "service-guid-1"}, 599 Plans: []v2action.ServicePlanSummary{ 600 { 601 ServicePlan: v2action.ServicePlan{GUID: "service-plan-guid-1", Name: "service-plan-1", Public: false}, 602 VisibleTo: []string{"my-org"}, 603 }, 604 }, 605 }, 606 )) 607 }) 608 }) 609 }) 610 611 When("checking if the org exists returns an error", func() { 612 BeforeEach(func() { 613 fakeOrgActor.OrganizationExistsWithNameReturns( 614 false, 615 v2action.Warnings{"org-warning-1"}, 616 errors.New("boom")) 617 }) 618 619 It("propagtes the error and warnings", func() { 620 Expect(executeErr).To(MatchError("boom")) 621 Expect(warnings).To(ConsistOf("org-warning-1")) 622 }) 623 }) 624 625 When("the specified org does not exist", func() { 626 BeforeEach(func() { 627 fakeOrgActor.OrganizationExistsWithNameReturns( 628 false, 629 v2action.Warnings{"org-warning-1"}, 630 nil) 631 }) 632 633 It("returns the warnings and propogates the error", func() { 634 Expect(executeErr).To(MatchError(actionerror.OrganizationNotFoundError{Name: "my-org"})) 635 Expect(warnings).To(ConsistOf("org-warning-1")) 636 637 Expect(fakeBrokerActor.GetServiceBrokersCallCount()).To(Equal(0)) 638 Expect(fakeOrgActor.OrganizationExistsWithNameCallCount()).To(Equal(1)) 639 Expect(fakeOrgActor.OrganizationExistsWithNameArgsForCall(0)).To(Equal("my-org")) 640 }) 641 }) 642 }) 643 644 When("an org, broker and service are specified", func() { 645 BeforeEach(func() { 646 broker = "broker-1" 647 service = "service-1" 648 organization = "my-org" 649 650 fakeOrgActor.OrganizationExistsWithNameReturns( 651 true, 652 v2action.Warnings{"org-warning"}, 653 nil) 654 fakeServiceActor.ServiceExistsWithNameReturns( 655 true, 656 v2action.Warnings{"service-exists-with-name-warning"}, 657 nil) 658 fakeBrokerActor.GetServiceBrokerByNameReturns( 659 v2action.ServiceBroker{Name: "broker-1", GUID: "broker-guid-1"}, 660 v2action.Warnings{"get-broker-warning"}, 661 nil) 662 }) 663 664 It("returns all warnings", func() { 665 Expect(warnings).To(ConsistOf("org-warning", "service-exists-with-name-warning", "get-broker-warning")) 666 }) 667 }) 668 }) 669 })