github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/actor/v2action/service_access_test.go (about) 1 package v2action_test 2 3 import ( 4 "errors" 5 "fmt" 6 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 10 "code.cloudfoundry.org/cli/actor/actionerror" 11 . "code.cloudfoundry.org/cli/actor/v2action" 12 "code.cloudfoundry.org/cli/actor/v2action/v2actionfakes" 13 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 14 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 15 ) 16 17 var _ = Describe("Service Access", func() { 18 var ( 19 actor *Actor 20 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 21 ) 22 23 BeforeEach(func() { 24 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 25 actor = NewActor(fakeCloudControllerClient, nil, nil) 26 }) 27 28 Describe("EnablePlanForAllOrgs", func() { 29 var ( 30 enablePlanErr error 31 enablePlanWarnings Warnings 32 ) 33 34 BeforeEach(func() { 35 fakeCloudControllerClient.GetServicesReturns( 36 []ccv2.Service{ 37 {Label: "service-1", GUID: "service-guid-1"}, 38 }, 39 nil, nil) 40 41 fakeCloudControllerClient.GetServicePlansReturns( 42 []ccv2.ServicePlan{ 43 {Name: "plan-1", GUID: "service-plan-guid-1"}, 44 {Name: "plan-2", GUID: "service-plan-guid-2"}, 45 }, 46 nil, nil) 47 }) 48 49 JustBeforeEach(func() { 50 enablePlanWarnings, enablePlanErr = actor.EnablePlanForAllOrgs("service-1", "plan-2") 51 }) 52 53 It("updates the service plan visibility", func() { 54 Expect(enablePlanErr).NotTo(HaveOccurred()) 55 Expect(fakeCloudControllerClient.GetServicesCallCount()).To(Equal(1)) 56 Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1)) 57 Expect(fakeCloudControllerClient.UpdateServicePlanCallCount()).To(Equal(1)) 58 59 planGuid, visible := fakeCloudControllerClient.UpdateServicePlanArgsForCall(0) 60 Expect(planGuid).To(Equal("service-plan-guid-2")) 61 Expect(visible).To(BeTrue()) 62 }) 63 64 When("the plan is already visible in some orgs", func() { 65 BeforeEach(func() { 66 fakeCloudControllerClient.GetServicePlanVisibilitiesReturns( 67 []ccv2.ServicePlanVisibility{ 68 {GUID: "service-visibility-guid-1"}, 69 {GUID: "service-visibility-guid-2"}, 70 }, 71 nil, nil) 72 }) 73 74 It("first disables the plan in both orgs", func() { 75 Expect(fakeCloudControllerClient.GetServicePlanVisibilitiesCallCount()).To(Equal(1)) 76 77 filters := fakeCloudControllerClient.GetServicePlanVisibilitiesArgsForCall(0) 78 Expect(filters[0].Type).To(Equal(constant.ServicePlanGUIDFilter)) 79 Expect(filters[0].Operator).To(Equal(constant.EqualOperator)) 80 Expect(filters[0].Values).To(Equal([]string{"service-plan-guid-2"})) 81 82 Expect(fakeCloudControllerClient.DeleteServicePlanVisibilityCallCount()).To(Equal(2)) 83 }) 84 85 It("and updates the service plan visibility for all orgs", func() { 86 Expect(enablePlanErr).NotTo(HaveOccurred()) 87 Expect(fakeCloudControllerClient.GetServicesCallCount()).To(Equal(1)) 88 Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1)) 89 Expect(fakeCloudControllerClient.UpdateServicePlanCallCount()).To(Equal(1)) 90 91 planGuid, visible := fakeCloudControllerClient.UpdateServicePlanArgsForCall(0) 92 Expect(planGuid).To(Equal("service-plan-guid-2")) 93 Expect(visible).To(BeTrue()) 94 }) 95 96 When("deleting service plan visibilities fails", func() { 97 BeforeEach(func() { 98 fakeCloudControllerClient.DeleteServicePlanVisibilityReturns( 99 []string{"visibility-warning"}, errors.New("delete-visibility-error")) 100 }) 101 102 It("propagates the error", func() { 103 Expect(enablePlanErr).To(MatchError(errors.New("delete-visibility-error"))) 104 }) 105 106 It("returns the warnings", func() { 107 Expect(enablePlanWarnings).To(Equal(Warnings{"visibility-warning"})) 108 }) 109 }) 110 }) 111 112 When("getting service plan visibilities fails", func() { 113 BeforeEach(func() { 114 fakeCloudControllerClient.GetServicePlanVisibilitiesReturns( 115 []ccv2.ServicePlanVisibility{}, 116 []string{"a-warning", "another-warning"}, 117 fmt.Errorf("oh no")) 118 }) 119 120 It("returns the error", func() { 121 Expect(enablePlanErr).To(MatchError(fmt.Errorf("oh no"))) 122 }) 123 124 It("returns the warnings", func() { 125 Expect(enablePlanWarnings).To(Equal(Warnings{"a-warning", "another-warning"})) 126 }) 127 }) 128 129 When("getting service plans fails", func() { 130 BeforeEach(func() { 131 fakeCloudControllerClient.GetServicePlansReturns(nil, 132 []string{"a-warning", "another-warning"}, 133 fmt.Errorf("it didn't work!")) 134 }) 135 136 It("returns the error", func() { 137 Expect(enablePlanErr).To(MatchError(fmt.Errorf("it didn't work!"))) 138 }) 139 140 It("returns the warnings", func() { 141 Expect(enablePlanWarnings).To(Equal(Warnings{"a-warning", "another-warning"})) 142 }) 143 }) 144 145 When("getting services fails", func() { 146 BeforeEach(func() { 147 fakeCloudControllerClient.GetServicesReturns(nil, 148 []string{"a-warning", "another-warning"}, 149 fmt.Errorf("it didn't work!")) 150 }) 151 152 It("returns the error", func() { 153 Expect(enablePlanErr).To(MatchError(fmt.Errorf("it didn't work!"))) 154 }) 155 156 It("returns the warnings", func() { 157 Expect(enablePlanWarnings).To(Equal(Warnings{"a-warning", "another-warning"})) 158 }) 159 }) 160 161 When("there are no matching services", func() { 162 BeforeEach(func() { 163 fakeCloudControllerClient.GetServicesReturns([]ccv2.Service{}, []string{"warning-1", "warning-2"}, nil) 164 }) 165 166 It("returns not found error", func() { 167 Expect(enablePlanErr).To(MatchError(actionerror.ServiceNotFoundError{Name: "service-1"})) 168 }) 169 170 It("returns all warnings", func() { 171 Expect(enablePlanWarnings).To(ConsistOf([]string{"warning-1", "warning-2"})) 172 }) 173 }) 174 175 When("there are no matching plans", func() { 176 BeforeEach(func() { 177 fakeCloudControllerClient.GetServicePlansReturns([]ccv2.ServicePlan{}, []string{"warning-1", "warning-2"}, nil) 178 }) 179 180 It("returns not found error", func() { 181 Expect(enablePlanErr).To(MatchError(actionerror.ServicePlanNotFoundError{PlanName: "plan-2", ServiceName: "service-1"})) 182 }) 183 184 It("returns all warnings", func() { 185 Expect(enablePlanWarnings).To(ConsistOf([]string{"warning-1", "warning-2"})) 186 }) 187 }) 188 189 When("updating service plan fails", func() { 190 BeforeEach(func() { 191 fakeCloudControllerClient.UpdateServicePlanReturns( 192 []string{"a-warning", "another-warning"}, 193 fmt.Errorf("it didn't work!")) 194 }) 195 196 It("returns the error", func() { 197 Expect(enablePlanErr).To(MatchError(fmt.Errorf("it didn't work!"))) 198 }) 199 200 It("returns the warnings", func() { 201 Expect(enablePlanWarnings).To(Equal(Warnings{"a-warning", "another-warning"})) 202 }) 203 }) 204 205 When("there are warnings", func() { 206 BeforeEach(func() { 207 fakeCloudControllerClient.GetServicesReturns( 208 []ccv2.Service{ 209 {Label: "service-1", GUID: "service-guid-1"}, 210 }, 211 []string{"foo"}, 212 nil) 213 214 fakeCloudControllerClient.GetServicePlansReturns( 215 []ccv2.ServicePlan{ 216 {Name: "plan-1", GUID: "service-plan-guid-1"}, 217 {Name: "plan-2", GUID: "service-plan-guid-2"}, 218 }, 219 []string{"bar"}, 220 nil) 221 222 fakeCloudControllerClient.GetServicePlanVisibilitiesReturns( 223 []ccv2.ServicePlanVisibility{ 224 {GUID: "service-visibility-guid-1"}, 225 {GUID: "service-visibility-guid-2"}, 226 }, 227 []string{"baz"}, 228 nil) 229 230 fakeCloudControllerClient.UpdateServicePlanReturns( 231 []string{"qux"}, 232 nil) 233 }) 234 235 It("returns the warnings", func() { 236 Expect(enablePlanWarnings).To(ConsistOf([]string{"foo", "bar", "baz", "qux"})) 237 }) 238 }) 239 }) 240 241 Describe("EnablePlanForOrg", func() { 242 var ( 243 enablePlanWarnings Warnings 244 enablePlanErr error 245 ) 246 247 BeforeEach(func() { 248 fakeCloudControllerClient.GetServicesReturns( 249 []ccv2.Service{ 250 {Label: "service-1", GUID: "service-guid-1"}, 251 }, 252 nil, nil) 253 254 fakeCloudControllerClient.GetServicePlansReturns( 255 []ccv2.ServicePlan{ 256 {Name: "plan-1", GUID: "service-plan-guid-1"}, 257 {Name: "plan-2", GUID: "service-plan-guid-2"}, 258 }, 259 nil, nil) 260 }) 261 262 JustBeforeEach(func() { 263 enablePlanWarnings, enablePlanErr = actor.EnablePlanForOrg("service-1", "plan-2", "my-org") 264 }) 265 266 When("the specified service does not exist", func() { 267 BeforeEach(func() { 268 fakeCloudControllerClient.GetServicesReturns( 269 []ccv2.Service{}, 270 nil, nil) 271 }) 272 273 It("returns service not found error", func() { 274 Expect(fakeCloudControllerClient.GetServicesCallCount()).To(Equal(1)) 275 Expect(enablePlanErr).To(MatchError(actionerror.ServiceNotFoundError{Name: "service-1"})) 276 filters := fakeCloudControllerClient.GetServicesArgsForCall(0) 277 Expect(len(filters)).To(Equal(1)) 278 Expect(filters[0]).To(Equal(ccv2.Filter{ 279 Type: constant.LabelFilter, 280 Operator: constant.EqualOperator, 281 Values: []string{"service-1"}, 282 })) 283 }) 284 }) 285 286 When("the specified org exists", func() { 287 BeforeEach(func() { 288 fakeCloudControllerClient.GetOrganizationsReturns( 289 []ccv2.Organization{ 290 {Name: "my-org", GUID: "org-guid-1"}, 291 }, nil, nil) 292 }) 293 294 It("enables the plan", func() { 295 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 296 297 Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1)) 298 serviceFilter := fakeCloudControllerClient.GetServicePlansArgsForCall(0) 299 Expect(serviceFilter[0].Values).To(ContainElement("service-guid-1")) 300 301 Expect(fakeCloudControllerClient.CreateServicePlanVisibilityCallCount()).To(Equal(1)) 302 planGUID, orgGUID := fakeCloudControllerClient.CreateServicePlanVisibilityArgsForCall(0) 303 Expect(planGUID).To(Equal("service-plan-guid-2")) 304 Expect(orgGUID).To(Equal("org-guid-1")) 305 306 Expect(enablePlanErr).NotTo(HaveOccurred()) 307 }) 308 309 When("warnings are raised", func() { 310 BeforeEach(func() { 311 fakeCloudControllerClient.CreateServicePlanVisibilityReturns(ccv2.ServicePlanVisibility{}, []string{"foo", "bar"}, nil) 312 }) 313 314 It("returns all warnings", func() { 315 Expect(enablePlanWarnings).To(ConsistOf([]string{"foo", "bar"})) 316 }) 317 }) 318 319 When("the specified plan does exist", func() { 320 BeforeEach(func() { 321 fakeCloudControllerClient.GetServicePlansReturns( 322 []ccv2.ServicePlan{ 323 {Name: "plan-4", GUID: "service-plan-guid-4"}, 324 {Name: "plan-5", GUID: "service-plan-guid-5"}, 325 }, 326 nil, nil) 327 }) 328 329 It("returns an error", func() { 330 Expect(enablePlanErr.Error()).To(Equal("Service plan 'plan-2' not found")) 331 }) 332 }) 333 334 When("getting services fails", func() { 335 BeforeEach(func() { 336 fakeCloudControllerClient.GetServicesReturns(nil, []string{"foo", "bar"}, fmt.Errorf("it broke")) 337 }) 338 339 It("returns the error", func() { 340 Expect(enablePlanErr).To(MatchError(fmt.Errorf("it broke"))) 341 }) 342 343 It("returns all warnings", func() { 344 Expect(enablePlanWarnings).To(ConsistOf([]string{"foo", "bar"})) 345 }) 346 }) 347 348 When("getting service plans fails", func() { 349 BeforeEach(func() { 350 fakeCloudControllerClient.GetServicesReturns( 351 []ccv2.Service{ 352 {Label: "service-1", GUID: "service-guid-1"}, 353 }, 354 []string{"foo"}, 355 nil) 356 357 fakeCloudControllerClient.GetServicePlansReturns(nil, []string{"bar"}, fmt.Errorf("it broke")) 358 }) 359 360 It("returns the error", func() { 361 Expect(enablePlanErr).To(MatchError(fmt.Errorf("it broke"))) 362 }) 363 364 It("returns all warnings", func() { 365 Expect(enablePlanWarnings).To(ConsistOf([]string{"foo", "bar"})) 366 }) 367 }) 368 369 When("create service plan visibility fails", func() { 370 BeforeEach(func() { 371 fakeCloudControllerClient.GetServicesReturns( 372 []ccv2.Service{ 373 {Label: "service-1", GUID: "service-guid-1"}, 374 }, 375 []string{"foo"}, 376 nil) 377 378 fakeCloudControllerClient.GetServicePlansReturns( 379 []ccv2.ServicePlan{ 380 {Name: "plan-1", GUID: "service-plan-guid-1"}, 381 {Name: "plan-2", GUID: "service-plan-guid-2"}, 382 }, 383 []string{"bar"}, 384 nil) 385 386 fakeCloudControllerClient.CreateServicePlanVisibilityReturns(ccv2.ServicePlanVisibility{}, []string{"baz"}, fmt.Errorf("some error")) 387 }) 388 389 It("returns all warnings", func() { 390 Expect(enablePlanWarnings).To(ConsistOf([]string{"foo", "bar", "baz"})) 391 }) 392 393 It("returns the error", func() { 394 Expect(enablePlanErr).To(MatchError(fmt.Errorf("some error"))) 395 }) 396 }) 397 }) 398 399 When("the specified org does not exist", func() { 400 BeforeEach(func() { 401 fakeCloudControllerClient.GetOrganizationsReturns([]ccv2.Organization{}, nil, nil) 402 }) 403 404 It("returns an organization not found error", func() { 405 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 406 Expect(enablePlanErr).To(MatchError(actionerror.OrganizationNotFoundError{Name: "my-org"})) 407 filters := fakeCloudControllerClient.GetOrganizationsArgsForCall(0) 408 Expect(len(filters)).To(Equal(1)) 409 Expect(filters[0]).To(Equal(ccv2.Filter{ 410 Type: constant.NameFilter, 411 Operator: constant.EqualOperator, 412 Values: []string{"my-org"}, 413 })) 414 }) 415 }) 416 }) 417 418 Describe("EnableServiceForOrg", func() { 419 var enableServiceForOrgErr error 420 var enableServiceForOrgWarnings Warnings 421 422 JustBeforeEach(func() { 423 enableServiceForOrgWarnings, enableServiceForOrgErr = actor.EnableServiceForOrg("service-1", "my-org") 424 }) 425 426 When("the service does not exist", func() { 427 BeforeEach(func() { 428 fakeCloudControllerClient.GetServicesReturns( 429 []ccv2.Service{}, 430 nil, nil) 431 }) 432 433 It("returns service not found error", func() { 434 Expect(fakeCloudControllerClient.GetServicesCallCount()).To(Equal(1)) 435 Expect(enableServiceForOrgErr).To(MatchError(actionerror.ServiceNotFoundError{Name: "service-1"})) 436 437 filters := fakeCloudControllerClient.GetServicesArgsForCall(0) 438 Expect(len(filters)).To(Equal(1)) 439 Expect(filters[0]).To(Equal(ccv2.Filter{ 440 Type: constant.LabelFilter, 441 Operator: constant.EqualOperator, 442 Values: []string{"service-1"}, 443 })) 444 }) 445 }) 446 447 When("the specified org does not exist", func() { 448 BeforeEach(func() { 449 fakeCloudControllerClient.GetServicesReturns( 450 []ccv2.Service{{Label: "service-1", GUID: "service-guid-1"}}, 451 nil, nil) 452 fakeCloudControllerClient.GetOrganizationsReturns([]ccv2.Organization{}, nil, nil) 453 }) 454 455 It("returns an organization not found error", func() { 456 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 457 Expect(enableServiceForOrgErr).To(MatchError(actionerror.OrganizationNotFoundError{Name: "my-org"})) 458 filters := fakeCloudControllerClient.GetOrganizationsArgsForCall(0) 459 Expect(len(filters)).To(Equal(1)) 460 Expect(filters[0]).To(Equal(ccv2.Filter{ 461 Type: constant.NameFilter, 462 Operator: constant.EqualOperator, 463 Values: []string{"my-org"}, 464 })) 465 }) 466 }) 467 468 When("the service and org exist", func() { 469 BeforeEach(func() { 470 fakeCloudControllerClient.GetServicesReturns( 471 []ccv2.Service{{Label: "service-1", GUID: "service-guid-1"}}, 472 nil, nil) 473 fakeCloudControllerClient.GetOrganizationsReturns( 474 []ccv2.Organization{{Name: "my-org", GUID: "org-guid-1"}}, 475 nil, nil) 476 fakeCloudControllerClient.GetServicePlansReturns( 477 []ccv2.ServicePlan{ 478 {Name: "plan-1", GUID: "service-plan-guid-1"}, 479 {Name: "plan-2", GUID: "service-plan-guid-2"}, 480 }, 481 nil, 482 nil) 483 }) 484 485 It("enables all the plans for that org", func() { 486 Expect(enableServiceForOrgErr).NotTo(HaveOccurred()) 487 Expect(fakeCloudControllerClient.GetServicesCallCount()).To(Equal(1)) 488 Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1)) 489 490 Expect(fakeCloudControllerClient.CreateServicePlanVisibilityCallCount()).To(Equal(2)) 491 planGUID1, orgGUID1 := fakeCloudControllerClient.CreateServicePlanVisibilityArgsForCall(0) 492 planGUID2, orgGUID2 := fakeCloudControllerClient.CreateServicePlanVisibilityArgsForCall(1) 493 494 Expect(orgGUID1).To(Equal("org-guid-1")) 495 Expect(orgGUID2).To(Equal("org-guid-1")) 496 Expect([]string{planGUID1, planGUID2}).To(ConsistOf([]string{"service-plan-guid-1", "service-plan-guid-2"})) 497 }) 498 }) 499 500 When("getting services fails", func() { 501 BeforeEach(func() { 502 fakeCloudControllerClient.GetServicesReturns( 503 []ccv2.Service{}, 504 ccv2.Warnings{"foo", "bar"}, 505 fmt.Errorf("this is very bad")) 506 }) 507 508 It("returns the error", func() { 509 Expect(enableServiceForOrgErr).To(MatchError(fmt.Errorf("this is very bad"))) 510 }) 511 512 It("returns all warnings", func() { 513 Expect(enableServiceForOrgWarnings).To(ConsistOf("foo", "bar")) 514 }) 515 }) 516 517 When("getting organizations fails", func() { 518 BeforeEach(func() { 519 fakeCloudControllerClient.GetServicesReturns( 520 []ccv2.Service{{Label: "service-1", GUID: "service-guid-1"}}, 521 ccv2.Warnings{"foo"}, 522 nil) 523 fakeCloudControllerClient.GetOrganizationsReturns( 524 []ccv2.Organization{{Name: "my-org", GUID: "org-guid-1"}}, 525 ccv2.Warnings{"bar"}, 526 fmt.Errorf("this is very bad")) 527 }) 528 529 It("returns the error", func() { 530 Expect(enableServiceForOrgErr).To(MatchError(fmt.Errorf("this is very bad"))) 531 }) 532 533 It("returns all warnings", func() { 534 Expect(enableServiceForOrgWarnings).To(ConsistOf("foo", "bar")) 535 }) 536 }) 537 538 When("getting service plans fails", func() { 539 BeforeEach(func() { 540 fakeCloudControllerClient.GetServicesReturns( 541 []ccv2.Service{{Label: "service-1", GUID: "service-guid-1"}}, 542 ccv2.Warnings{"foo"}, 543 nil) 544 fakeCloudControllerClient.GetServicePlansReturns( 545 []ccv2.ServicePlan{}, 546 ccv2.Warnings{"bar"}, 547 fmt.Errorf("this is very bad")) 548 }) 549 550 It("returns the error", func() { 551 Expect(enableServiceForOrgErr).To(MatchError(fmt.Errorf("this is very bad"))) 552 }) 553 554 It("returns all warnings", func() { 555 Expect(enableServiceForOrgWarnings).To(ConsistOf("foo", "bar")) 556 }) 557 }) 558 559 When("creating service plan visibility fails", func() { 560 BeforeEach(func() { 561 fakeCloudControllerClient.GetServicesReturns( 562 []ccv2.Service{{Label: "service-1", GUID: "service-guid-1"}}, 563 ccv2.Warnings{"foo"}, 564 nil) 565 fakeCloudControllerClient.GetOrganizationsReturns( 566 []ccv2.Organization{{Name: "my-org", GUID: "org-guid-1"}}, 567 ccv2.Warnings{"bar"}, 568 nil) 569 fakeCloudControllerClient.GetServicePlansReturns( 570 []ccv2.ServicePlan{ 571 {Name: "service-plan-1", GUID: "service-plan-guid-1"}}, 572 ccv2.Warnings{"baz"}, 573 nil) 574 fakeCloudControllerClient.CreateServicePlanVisibilityReturns( 575 ccv2.ServicePlanVisibility{}, 576 ccv2.Warnings{"qux"}, 577 fmt.Errorf("this is very bad")) 578 }) 579 580 It("returns the error", func() { 581 Expect(enableServiceForOrgErr).To(MatchError(fmt.Errorf("this is very bad"))) 582 }) 583 584 It("returns all warnings", func() { 585 Expect(enableServiceForOrgWarnings).To(ConsistOf("foo", "bar", "baz", "qux")) 586 }) 587 }) 588 }) 589 590 Describe("EnableServiceForAllOrgs", func() { 591 var ( 592 enableServiceErr error 593 enableServiceWarnings Warnings 594 ) 595 596 BeforeEach(func() { 597 fakeCloudControllerClient.GetServicesReturns( 598 []ccv2.Service{ 599 {Label: "service-1", GUID: "service-guid-1"}, 600 }, 601 nil, nil) 602 603 fakeCloudControllerClient.GetServicePlansReturns( 604 []ccv2.ServicePlan{ 605 {Name: "plan-1", GUID: "service-plan-guid-1"}, 606 {Name: "plan-2", GUID: "service-plan-guid-2"}, 607 }, 608 nil, nil) 609 }) 610 611 JustBeforeEach(func() { 612 enableServiceWarnings, enableServiceErr = actor.EnableServiceForAllOrgs("service-1") 613 }) 614 615 It("should update all plans to public", func() { 616 Expect(enableServiceErr).NotTo(HaveOccurred()) 617 Expect(fakeCloudControllerClient.GetServicesCallCount()).To(Equal(1)) 618 Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1)) 619 Expect(fakeCloudControllerClient.UpdateServicePlanCallCount()).To(Equal(2)) 620 planGuid, public := fakeCloudControllerClient.UpdateServicePlanArgsForCall(0) 621 Expect(planGuid).To(Equal("service-plan-guid-1")) 622 Expect(public).To(BeTrue()) 623 planGuid, public = fakeCloudControllerClient.UpdateServicePlanArgsForCall(1) 624 Expect(planGuid).To(Equal("service-plan-guid-2")) 625 Expect(public).To(BeTrue()) 626 }) 627 628 When("the service does not exist", func() { 629 BeforeEach(func() { 630 fakeCloudControllerClient.GetServicesReturns( 631 []ccv2.Service{}, 632 nil, nil) 633 }) 634 635 It("returns service not found error", func() { 636 Expect(fakeCloudControllerClient.GetServicesCallCount()).To(Equal(1)) 637 Expect(enableServiceErr).To(MatchError(actionerror.ServiceNotFoundError{Name: "service-1"})) 638 639 filters := fakeCloudControllerClient.GetServicesArgsForCall(0) 640 Expect(len(filters)).To(Equal(1)) 641 Expect(filters[0]).To(Equal(ccv2.Filter{ 642 Type: constant.LabelFilter, 643 Operator: constant.EqualOperator, 644 Values: []string{"service-1"}, 645 })) 646 }) 647 }) 648 649 When("getting services fails", func() { 650 BeforeEach(func() { 651 fakeCloudControllerClient.GetServicesReturns(nil, []string{"foo", "bar"}, fmt.Errorf("it broke")) 652 }) 653 654 It("returns the error", func() { 655 Expect(enableServiceErr).To(MatchError(fmt.Errorf("it broke"))) 656 }) 657 658 It("returns all warnings", func() { 659 Expect(enableServiceWarnings).To(ConsistOf([]string{"foo", "bar"})) 660 }) 661 }) 662 663 When("getting service plans fails", func() { 664 BeforeEach(func() { 665 fakeCloudControllerClient.GetServicesReturns( 666 []ccv2.Service{ 667 {Label: "service-1", GUID: "service-guid-1"}, 668 }, 669 []string{"foo", "bar"}, 670 nil) 671 672 fakeCloudControllerClient.GetServicePlansReturns(nil, []string{"baz"}, fmt.Errorf("it broke")) 673 }) 674 675 It("returns all warnings", func() { 676 Expect(enableServiceWarnings).To(ConsistOf([]string{"foo", "bar", "baz"})) 677 }) 678 679 It("returns the error", func() { 680 Expect(enableServiceErr).To(MatchError(fmt.Errorf("it broke"))) 681 }) 682 }) 683 684 When("update service plan fails", func() { 685 BeforeEach(func() { 686 fakeCloudControllerClient.GetServicesReturns( 687 []ccv2.Service{ 688 {Label: "service-1", GUID: "service-guid-1"}, 689 }, 690 []string{"foo"}, 691 nil) 692 693 fakeCloudControllerClient.GetServicePlansReturns( 694 []ccv2.ServicePlan{ 695 {Name: "plan-1", GUID: "service-plan-guid-1"}, 696 {Name: "plan-2", GUID: "service-plan-guid-2"}, 697 }, 698 []string{"bar"}, 699 nil) 700 701 fakeCloudControllerClient.UpdateServicePlanReturns([]string{"baz", "quux"}, fmt.Errorf("some error")) 702 }) 703 704 It("returns all warnings", func() { 705 Expect(enableServiceWarnings).To(ConsistOf([]string{"foo", "bar", "baz", "quux"})) 706 }) 707 708 It("returns the error", func() { 709 Expect(enableServiceErr).To(MatchError(fmt.Errorf("some error"))) 710 }) 711 }) 712 }) 713 })