github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7action/label_test.go (about) 1 package v7action_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 . "code.cloudfoundry.org/cli/actor/v7action" 8 "code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 11 "code.cloudfoundry.org/cli/resources" 12 "code.cloudfoundry.org/cli/types" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("labels", func() { 18 var ( 19 actor *Actor 20 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 21 fakeSharedActor *v7actionfakes.FakeSharedActor 22 fakeConfig *v7actionfakes.FakeConfig 23 warnings Warnings 24 executeErr error 25 resourceName string 26 spaceGUID string 27 orgGUID string 28 labels map[string]types.NullString 29 ) 30 31 BeforeEach(func() { 32 fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient) 33 fakeSharedActor = new(v7actionfakes.FakeSharedActor) 34 fakeConfig = new(v7actionfakes.FakeConfig) 35 actor = NewActor(fakeCloudControllerClient, fakeConfig, fakeSharedActor, nil, nil, nil) 36 resourceName = "some-resource" 37 orgGUID = "some-org-guid" 38 spaceGUID = "some-space-guid" 39 }) 40 41 Describe("UpdateApplicationLabelsByApplicationName", func() { 42 JustBeforeEach(func() { 43 warnings, executeErr = actor.UpdateApplicationLabelsByApplicationName(resourceName, spaceGUID, labels) 44 }) 45 46 When("there are no client errors", func() { 47 BeforeEach(func() { 48 fakeCloudControllerClient.GetApplicationsReturns( 49 []resources.Application{{GUID: "some-guid"}}, 50 ccv3.Warnings([]string{"warning-1", "warning-2"}), 51 nil, 52 ) 53 fakeCloudControllerClient.UpdateResourceMetadataReturns( 54 "", 55 ccv3.Warnings{"set-app-labels-warnings"}, 56 nil, 57 ) 58 }) 59 60 It("gets the application", func() { 61 Expect(fakeCloudControllerClient.GetApplicationsCallCount()).To(Equal(1)) 62 Expect(fakeCloudControllerClient.GetApplicationsArgsForCall(0)).To(ConsistOf( 63 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 64 ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{spaceGUID}}, 65 )) 66 }) 67 68 It("sets the app labels", func() { 69 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 70 resourceType, appGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 71 Expect(executeErr).ToNot(HaveOccurred()) 72 Expect(resourceType).To(BeEquivalentTo("app")) 73 Expect(appGUID).To(BeEquivalentTo("some-guid")) 74 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 75 }) 76 77 It("aggregates warnings", func() { 78 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-app-labels-warnings")) 79 }) 80 }) 81 82 When("there are client errors", func() { 83 When("GetApplications fails", func() { 84 BeforeEach(func() { 85 fakeCloudControllerClient.GetApplicationsReturns( 86 []resources.Application{{GUID: "some-guid"}}, 87 ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}), 88 errors.New("get-apps-error"), 89 ) 90 }) 91 92 It("returns the error and all warnings", func() { 93 Expect(executeErr).To(HaveOccurred()) 94 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 95 Expect(executeErr).To(MatchError("get-apps-error")) 96 }) 97 }) 98 99 When("UpdateApplication fails", func() { 100 BeforeEach(func() { 101 fakeCloudControllerClient.GetApplicationsReturns( 102 []resources.Application{{GUID: "some-guid"}}, 103 ccv3.Warnings([]string{"warning-1", "warning-2"}), 104 nil, 105 ) 106 fakeCloudControllerClient.UpdateResourceMetadataReturns( 107 "", 108 ccv3.Warnings{"set-app-labels-warnings"}, 109 errors.New("update-application-error"), 110 ) 111 }) 112 113 It("returns the error and all warnings", func() { 114 Expect(executeErr).To(HaveOccurred()) 115 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-app-labels-warnings")) 116 Expect(executeErr).To(MatchError("update-application-error")) 117 }) 118 }) 119 }) 120 }) 121 122 Describe("UpdateDomainLabelsByDomainName", func() { 123 JustBeforeEach(func() { 124 warnings, executeErr = actor.UpdateDomainLabelsByDomainName(resourceName, labels) 125 }) 126 127 When("there are no client errors", func() { 128 BeforeEach(func() { 129 fakeCloudControllerClient.GetDomainsReturns( 130 []resources.Domain{{GUID: "some-guid"}}, 131 ccv3.Warnings([]string{"warning-1", "warning-2"}), 132 nil, 133 ) 134 fakeCloudControllerClient.UpdateResourceMetadataReturns( 135 "", 136 ccv3.Warnings{"warning-updating-metadata"}, 137 nil, 138 ) 139 }) 140 141 It("gets the domain", func() { 142 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 143 Expect(fakeCloudControllerClient.GetDomainsArgsForCall(0)).To(ConsistOf( 144 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 145 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 146 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 147 )) 148 }) 149 150 It("sets the domain labels", func() { 151 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 152 resourceType, domainGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 153 Expect(executeErr).ToNot(HaveOccurred()) 154 Expect(resourceType).To(BeEquivalentTo("domain")) 155 Expect(domainGUID).To(BeEquivalentTo("some-guid")) 156 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 157 }) 158 159 It("aggregates warnings", func() { 160 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-updating-metadata")) 161 }) 162 }) 163 164 When("there are client errors", func() { 165 When("fetching the domain fails", func() { 166 BeforeEach(func() { 167 fakeCloudControllerClient.GetDomainsReturns( 168 []resources.Domain{{GUID: "some-guid"}}, 169 ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}), 170 errors.New("get-domains-error"), 171 ) 172 }) 173 174 It("returns the error and all warnings", func() { 175 Expect(executeErr).To(HaveOccurred()) 176 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 177 Expect(executeErr).To(MatchError("get-domains-error")) 178 }) 179 }) 180 181 When("updating the domain fails", func() { 182 BeforeEach(func() { 183 fakeCloudControllerClient.GetDomainsReturns( 184 []resources.Domain{{GUID: "some-guid"}}, 185 ccv3.Warnings([]string{"warning-1", "warning-2"}), 186 nil, 187 ) 188 fakeCloudControllerClient.UpdateResourceMetadataReturns( 189 "", 190 ccv3.Warnings{"warning-updating-metadata"}, 191 errors.New("update-domain-error"), 192 ) 193 }) 194 It("returns the error and all warnings", func() { 195 Expect(executeErr).To(HaveOccurred()) 196 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-updating-metadata")) 197 Expect(executeErr).To(MatchError("update-domain-error")) 198 }) 199 }) 200 }) 201 }) 202 203 Describe("UpdateOrganizationLabelsByOrganizationName", func() { 204 JustBeforeEach(func() { 205 warnings, executeErr = actor.UpdateOrganizationLabelsByOrganizationName(resourceName, labels) 206 }) 207 208 When("there are no client errors", func() { 209 BeforeEach(func() { 210 fakeCloudControllerClient.GetOrganizationsReturns( 211 []resources.Organization{{GUID: "some-guid"}}, 212 ccv3.Warnings([]string{"warning-1", "warning-2"}), 213 nil, 214 ) 215 fakeCloudControllerClient.UpdateResourceMetadataReturns( 216 "", 217 ccv3.Warnings{"set-org"}, 218 nil, 219 ) 220 }) 221 222 It("gets the organization", func() { 223 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 224 Expect(fakeCloudControllerClient.GetOrganizationsArgsForCall(0)).To(ConsistOf( 225 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 226 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 227 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 228 )) 229 }) 230 231 It("sets the org labels", func() { 232 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 233 resourceType, orgGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 234 Expect(executeErr).ToNot(HaveOccurred()) 235 Expect(resourceType).To(BeEquivalentTo("org")) 236 Expect(orgGUID).To(BeEquivalentTo("some-guid")) 237 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 238 }) 239 240 It("aggregates warnings", func() { 241 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-org")) 242 }) 243 }) 244 245 When("there are client errors", func() { 246 When("fetching the organization fails", func() { 247 BeforeEach(func() { 248 fakeCloudControllerClient.GetOrganizationsReturns( 249 []resources.Organization{{GUID: "some-guid"}}, 250 ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}), 251 errors.New("get-orgs-error"), 252 ) 253 }) 254 255 It("returns the error and all warnings", func() { 256 Expect(executeErr).To(HaveOccurred()) 257 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 258 Expect(executeErr).To(MatchError("get-orgs-error")) 259 }) 260 }) 261 262 When("updating the organization fails", func() { 263 BeforeEach(func() { 264 fakeCloudControllerClient.GetOrganizationsReturns( 265 []resources.Organization{{GUID: "some-guid"}}, 266 ccv3.Warnings([]string{"warning-1", "warning-2"}), 267 nil, 268 ) 269 fakeCloudControllerClient.UpdateResourceMetadataReturns( 270 "", 271 ccv3.Warnings{"set-org"}, 272 errors.New("update-orgs-error"), 273 ) 274 }) 275 It("returns the error and all warnings", func() { 276 Expect(executeErr).To(HaveOccurred()) 277 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-org")) 278 Expect(executeErr).To(MatchError("update-orgs-error")) 279 }) 280 }) 281 }) 282 }) 283 284 Describe("UpdateRouteLabels", func() { 285 JustBeforeEach(func() { 286 warnings, executeErr = actor.UpdateRouteLabels("sub.example.com/my-route/path", "space-guid", labels) 287 }) 288 289 When("there are no client errors", func() { 290 BeforeEach(func() { 291 fakeCloudControllerClient.GetDomainsReturns( 292 []resources.Domain{ 293 {Name: "domain-name", GUID: "domain-guid"}, 294 }, 295 ccv3.Warnings{"get-domains-warning"}, 296 nil, 297 ) 298 299 fakeCloudControllerClient.GetRoutesReturns( 300 []resources.Route{ 301 {GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", URL: "hostname.domain-name", Path: "/the-path"}, 302 }, 303 ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"}, 304 nil, 305 ) 306 307 fakeCloudControllerClient.UpdateResourceMetadataReturns( 308 "", 309 ccv3.Warnings{"set-route-warning"}, 310 nil, 311 ) 312 }) 313 314 It("gets the domain", func() { 315 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 316 Expect(fakeCloudControllerClient.GetDomainsArgsForCall(0)).To(ConsistOf( 317 ccv3.Query{Key: ccv3.NameFilter, Values: []string{"sub.example.com"}}, 318 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 319 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 320 )) 321 }) 322 323 It("gets the route", func() { 324 Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1)) 325 Expect(fakeCloudControllerClient.GetRoutesArgsForCall(0)).To(ConsistOf( 326 ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{"space-guid"}}, 327 ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{"domain-guid"}}, 328 ccv3.Query{Key: ccv3.HostsFilter, Values: []string{""}}, 329 ccv3.Query{Key: ccv3.PathsFilter, Values: []string{"/my-route/path"}}, 330 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 331 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 332 )) 333 }) 334 335 It("sets the route labels", func() { 336 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 337 resourceType, routeGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 338 Expect(executeErr).ToNot(HaveOccurred()) 339 Expect(resourceType).To(BeEquivalentTo("route")) 340 Expect(routeGUID).To(BeEquivalentTo("route-guid")) 341 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 342 }) 343 344 It("aggregates warnings", func() { 345 Expect(warnings).To(ConsistOf("get-domains-warning", "get-route-warning-1", "get-route-warning-2", "set-route-warning")) 346 }) 347 }) 348 349 When("there are client errors", func() { 350 When("fetching the route fails", func() { 351 BeforeEach(func() { 352 fakeCloudControllerClient.GetDomainsReturns( 353 nil, 354 ccv3.Warnings{"get-domains-warning"}, 355 errors.New("get-domain-error"), 356 ) 357 }) 358 359 It("returns the error and all warnings", func() { 360 Expect(executeErr).To(HaveOccurred()) 361 Expect(warnings).To(ConsistOf("get-domains-warning")) 362 Expect(executeErr).To(MatchError("get-domain-error")) 363 }) 364 }) 365 366 When("updating the route fails", func() { 367 BeforeEach(func() { 368 fakeCloudControllerClient.GetDomainsReturns( 369 []resources.Domain{ 370 {Name: "domain-name", GUID: "domain-guid"}, 371 }, 372 ccv3.Warnings{"get-domains-warning"}, 373 nil, 374 ) 375 376 fakeCloudControllerClient.GetRoutesReturns( 377 []resources.Route{ 378 {GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", URL: "hostname.domain-name", Path: "/the-path"}, 379 }, 380 ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"}, 381 nil, 382 ) 383 384 fakeCloudControllerClient.UpdateResourceMetadataReturns( 385 "", 386 ccv3.Warnings{"set-route-warning"}, 387 errors.New("update-route-error"), 388 ) 389 }) 390 391 It("returns the error and all warnings", func() { 392 Expect(executeErr).To(HaveOccurred()) 393 Expect(warnings).To(ConsistOf("get-domains-warning", "get-route-warning-1", "get-route-warning-2", "set-route-warning")) 394 }) 395 }) 396 }) 397 }) 398 399 Describe("UpdateSpaceLabelsBySpaceName", func() { 400 JustBeforeEach(func() { 401 warnings, executeErr = actor.UpdateSpaceLabelsBySpaceName(resourceName, orgGUID, labels) 402 }) 403 404 When("there are no client errors", func() { 405 BeforeEach(func() { 406 fakeCloudControllerClient.GetSpacesReturns( 407 []resources.Space{resources.Space{GUID: "some-guid"}}, 408 ccv3.IncludedResources{}, 409 ccv3.Warnings([]string{"warning-1", "warning-2"}), 410 nil, 411 ) 412 fakeCloudControllerClient.UpdateResourceMetadataReturns( 413 "", 414 ccv3.Warnings{"set-space-metadata"}, 415 nil, 416 ) 417 }) 418 419 It("gets the space", func() { 420 Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1)) 421 Expect(fakeCloudControllerClient.GetSpacesArgsForCall(0)).To(ConsistOf( 422 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 423 ccv3.Query{Key: ccv3.OrganizationGUIDFilter, Values: []string{orgGUID}}, 424 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 425 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 426 )) 427 }) 428 429 It("sets the space labels", func() { 430 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 431 resourceType, spaceGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 432 Expect(executeErr).ToNot(HaveOccurred()) 433 Expect(resourceType).To(BeEquivalentTo("space")) 434 Expect(spaceGUID).To(BeEquivalentTo("some-guid")) 435 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 436 }) 437 438 It("aggregates warnings", func() { 439 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-space-metadata")) 440 }) 441 }) 442 443 When("there are client errors", func() { 444 When("fetching the space fails", func() { 445 BeforeEach(func() { 446 fakeCloudControllerClient.GetSpacesReturns( 447 []resources.Space{resources.Space{GUID: "some-guid"}}, 448 ccv3.IncludedResources{}, 449 ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}), 450 errors.New("get-spaces-error"), 451 ) 452 }) 453 454 It("returns the error and all warnings", func() { 455 Expect(executeErr).To(HaveOccurred()) 456 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 457 Expect(executeErr).To(MatchError("get-spaces-error")) 458 }) 459 }) 460 461 When("updating the space fails", func() { 462 BeforeEach(func() { 463 fakeCloudControllerClient.GetSpacesReturns( 464 []resources.Space{resources.Space{GUID: "some-guid"}}, 465 ccv3.IncludedResources{}, 466 ccv3.Warnings([]string{"warning-1", "warning-2"}), 467 nil, 468 ) 469 fakeCloudControllerClient.UpdateResourceMetadataReturns( 470 "", 471 ccv3.Warnings{"set-space"}, 472 errors.New("update-space-error"), 473 ) 474 }) 475 It("returns the error and all warnings", func() { 476 Expect(executeErr).To(HaveOccurred()) 477 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-space")) 478 Expect(executeErr).To(MatchError("update-space-error")) 479 }) 480 }) 481 }) 482 }) 483 484 Describe("UpdateStackLabelsByStackName", func() { 485 JustBeforeEach(func() { 486 warnings, executeErr = actor.UpdateStackLabelsByStackName(resourceName, labels) 487 }) 488 489 When("there are no client errors", func() { 490 BeforeEach(func() { 491 fakeCloudControllerClient.GetStacksReturns( 492 []resources.Stack{resources.Stack{GUID: "some-guid"}}, 493 ccv3.Warnings([]string{"warning-1", "warning-2"}), 494 nil, 495 ) 496 fakeCloudControllerClient.UpdateResourceMetadataReturns( 497 "", 498 ccv3.Warnings{"set-stack-metadata"}, 499 nil, 500 ) 501 }) 502 503 It("gets the stack", func() { 504 Expect(fakeCloudControllerClient.GetStacksCallCount()).To(Equal(1)) 505 Expect(fakeCloudControllerClient.GetStacksArgsForCall(0)).To(ConsistOf( 506 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 507 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 508 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 509 )) 510 }) 511 512 It("sets the stack labels", func() { 513 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 514 resourceType, stackGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 515 Expect(executeErr).ToNot(HaveOccurred()) 516 Expect(resourceType).To(BeEquivalentTo("stack")) 517 Expect(stackGUID).To(BeEquivalentTo("some-guid")) 518 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 519 }) 520 521 It("aggregates warnings", func() { 522 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-stack-metadata")) 523 }) 524 }) 525 526 When("there are client errors", func() { 527 When("fetching the stack fails", func() { 528 BeforeEach(func() { 529 fakeCloudControllerClient.GetStacksReturns( 530 []resources.Stack{resources.Stack{GUID: "some-guid"}}, 531 ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}), 532 errors.New("get-stacks-error"), 533 ) 534 }) 535 536 It("returns the error and all warnings", func() { 537 Expect(executeErr).To(HaveOccurred()) 538 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 539 Expect(executeErr).To(MatchError("get-stacks-error")) 540 }) 541 }) 542 543 When("updating the stack fails", func() { 544 BeforeEach(func() { 545 fakeCloudControllerClient.GetStacksReturns( 546 []resources.Stack{resources.Stack{GUID: "some-guid"}}, 547 ccv3.Warnings([]string{"warning-1", "warning-2"}), 548 nil, 549 ) 550 fakeCloudControllerClient.UpdateResourceMetadataReturns( 551 "", 552 ccv3.Warnings{"set-stack"}, 553 errors.New("update-stack-error"), 554 ) 555 }) 556 It("returns the error and all warnings", func() { 557 Expect(executeErr).To(HaveOccurred()) 558 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-stack")) 559 Expect(executeErr).To(MatchError("update-stack-error")) 560 }) 561 }) 562 }) 563 }) 564 565 Describe("UpdateServiceBrokerLabelsByServiceBrokerName", func() { 566 JustBeforeEach(func() { 567 warnings, executeErr = actor.UpdateServiceBrokerLabelsByServiceBrokerName(resourceName, labels) 568 }) 569 570 When("there are no client errors", func() { 571 BeforeEach(func() { 572 fakeCloudControllerClient.GetServiceBrokersReturns( 573 []resources.ServiceBroker{{GUID: "some-broker-guid", Name: resourceName}}, 574 []string{"warning-1", "warning-2"}, 575 nil, 576 ) 577 578 fakeCloudControllerClient.UpdateResourceMetadataReturns( 579 ccv3.JobURL("fake-job-url"), 580 ccv3.Warnings{"set-service-broker-metadata"}, 581 nil, 582 ) 583 584 fakeCloudControllerClient.PollJobReturns(ccv3.Warnings{"poll-job-warning"}, nil) 585 }) 586 587 It("gets the service broker", func() { 588 Expect(executeErr).ToNot(HaveOccurred()) 589 Expect(fakeCloudControllerClient.GetServiceBrokersCallCount()).To(Equal(1)) 590 }) 591 592 It("sets the service-broker labels", func() { 593 Expect(executeErr).ToNot(HaveOccurred()) 594 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 595 resourceType, serviceBrokerGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 596 Expect(resourceType).To(BeEquivalentTo("service-broker")) 597 Expect(serviceBrokerGUID).To(BeEquivalentTo("some-broker-guid")) 598 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 599 }) 600 601 It("polls the job", func() { 602 Expect(executeErr).ToNot(HaveOccurred()) 603 Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1)) 604 Expect(fakeCloudControllerClient.PollJobArgsForCall(0)).To(BeEquivalentTo("fake-job-url")) 605 }) 606 607 It("aggregates warnings", func() { 608 Expect(executeErr).ToNot(HaveOccurred()) 609 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-broker-metadata", "poll-job-warning")) 610 }) 611 }) 612 613 When("there are client errors", func() { 614 When("fetching the service-broker fails", func() { 615 BeforeEach(func() { 616 fakeCloudControllerClient.GetServiceBrokersReturns( 617 []resources.ServiceBroker{}, 618 ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}), 619 errors.New("get-service-broker-error"), 620 ) 621 }) 622 623 It("returns the error and all warnings", func() { 624 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 625 Expect(executeErr).To(MatchError("get-service-broker-error")) 626 }) 627 }) 628 629 When("updating the service-broker fails", func() { 630 BeforeEach(func() { 631 fakeCloudControllerClient.GetServiceBrokersReturns( 632 []resources.ServiceBroker{{GUID: "some-guid", Name: resourceName}}, 633 ccv3.Warnings([]string{"warning-1", "warning-2"}), 634 nil, 635 ) 636 fakeCloudControllerClient.UpdateResourceMetadataReturns( 637 ccv3.JobURL(""), 638 ccv3.Warnings{"set-service-broker"}, 639 errors.New("update-service-broker-error"), 640 ) 641 }) 642 643 It("returns the error and all warnings", func() { 644 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-broker")) 645 Expect(executeErr).To(MatchError("update-service-broker-error")) 646 }) 647 }) 648 649 When("polling the job fails", func() { 650 BeforeEach(func() { 651 fakeCloudControllerClient.GetServiceBrokersReturns( 652 []resources.ServiceBroker{{GUID: "some-guid", Name: resourceName}}, 653 ccv3.Warnings([]string{"warning-1", "warning-2"}), 654 nil, 655 ) 656 fakeCloudControllerClient.UpdateResourceMetadataReturns( 657 ccv3.JobURL("fake-job-url"), 658 ccv3.Warnings{"set-service-broker-metadata"}, 659 nil, 660 ) 661 662 fakeCloudControllerClient.PollJobReturns( 663 ccv3.Warnings{"another-poll-job-warning"}, 664 errors.New("polling-error"), 665 ) 666 }) 667 668 It("returns the error and all warnings", func() { 669 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-broker-metadata", "another-poll-job-warning")) 670 Expect(executeErr).To(MatchError("polling-error")) 671 }) 672 }) 673 }) 674 }) 675 676 Describe("UpdateServiceInstanceLabels", func() { 677 JustBeforeEach(func() { 678 warnings, executeErr = actor.UpdateServiceInstanceLabels(resourceName, spaceGUID, labels) 679 }) 680 681 When("there are no client errors", func() { 682 BeforeEach(func() { 683 fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( 684 resources.ServiceInstance{ 685 GUID: "fake-si-guid", 686 Name: resourceName, 687 }, 688 ccv3.IncludedResources{}, 689 []string{"warning-1", "warning-2"}, 690 nil, 691 ) 692 fakeCloudControllerClient.UpdateResourceMetadataReturns( 693 "", 694 ccv3.Warnings{"set-si-labels-warnings"}, 695 nil, 696 ) 697 }) 698 699 It("gets the service instance", func() { 700 Expect(fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1)) 701 actualName, actualSpaceGUID, actualQuery := fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceArgsForCall(0) 702 Expect(actualName).To(Equal(resourceName)) 703 Expect(actualSpaceGUID).To(Equal(spaceGUID)) 704 Expect(actualQuery).To(BeEmpty()) 705 }) 706 707 It("sets the service instance labels", func() { 708 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 709 resourceType, siGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 710 Expect(executeErr).ToNot(HaveOccurred()) 711 Expect(resourceType).To(BeEquivalentTo("service-instance")) 712 Expect(siGUID).To(BeEquivalentTo("fake-si-guid")) 713 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 714 }) 715 716 It("aggregates warnings", func() { 717 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-si-labels-warnings")) 718 }) 719 }) 720 721 When("there are client errors", func() { 722 When("GetServiceInstanceByNameAndSpace fails", func() { 723 BeforeEach(func() { 724 fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( 725 resources.ServiceInstance{}, 726 ccv3.IncludedResources{}, 727 []string{"warning-failure-1", "warning-failure-2"}, 728 errors.New("get-si-error"), 729 ) 730 }) 731 732 It("returns the error and all warnings", func() { 733 Expect(executeErr).To(HaveOccurred()) 734 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 735 Expect(executeErr).To(MatchError("get-si-error")) 736 }) 737 }) 738 739 When("UpdateResourceMetadata fails", func() { 740 BeforeEach(func() { 741 fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( 742 resources.ServiceInstance{ 743 GUID: "fake-si-guid", 744 Name: resourceName, 745 }, 746 ccv3.IncludedResources{}, 747 []string{"warning-1", "warning-2"}, 748 nil, 749 ) 750 fakeCloudControllerClient.UpdateResourceMetadataReturns( 751 "", 752 ccv3.Warnings{"set-app-labels-warnings"}, 753 errors.New("update-si-error"), 754 ) 755 }) 756 757 It("returns the error and all warnings", func() { 758 Expect(executeErr).To(HaveOccurred()) 759 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-app-labels-warnings")) 760 Expect(executeErr).To(MatchError("update-si-error")) 761 }) 762 }) 763 }) 764 }) 765 766 Describe("UpdateServiceOfferingLabels", func() { 767 const serviceBrokerName = "fake-service-broker" 768 769 JustBeforeEach(func() { 770 warnings, executeErr = actor.UpdateServiceOfferingLabels(resourceName, serviceBrokerName, labels) 771 }) 772 773 When("there are no client errors", func() { 774 BeforeEach(func() { 775 fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns( 776 resources.ServiceOffering{GUID: "some-service-offering-guid", Name: resourceName}, 777 []string{"warning-1", "warning-2"}, 778 nil, 779 ) 780 781 fakeCloudControllerClient.UpdateResourceMetadataReturns( 782 "", 783 ccv3.Warnings{"set-service-offering-metadata"}, 784 nil, 785 ) 786 }) 787 788 It("gets the service offering", func() { 789 Expect(executeErr).ToNot(HaveOccurred()) 790 Expect(fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerCallCount()).To(Equal(1)) 791 requestedServiceName, requestedBrokerName := fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerArgsForCall(0) 792 Expect(requestedServiceName).To(Equal(resourceName)) 793 Expect(requestedBrokerName).To(Equal(serviceBrokerName)) 794 }) 795 796 It("sets the service offering labels", func() { 797 Expect(executeErr).ToNot(HaveOccurred()) 798 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 799 resourceType, serviceBrokerGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 800 Expect(resourceType).To(BeEquivalentTo("service-offering")) 801 Expect(serviceBrokerGUID).To(BeEquivalentTo("some-service-offering-guid")) 802 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 803 }) 804 805 It("aggregates warnings", func() { 806 Expect(executeErr).ToNot(HaveOccurred()) 807 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-offering-metadata")) 808 }) 809 }) 810 811 When("there are client errors", func() { 812 When("fetching the service offering fails", func() { 813 BeforeEach(func() { 814 fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns( 815 resources.ServiceOffering{}, 816 ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}), 817 errors.New("get-service-offerings-error"), 818 ) 819 }) 820 821 It("returns the error and all warnings", func() { 822 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 823 Expect(executeErr).To(MatchError("get-service-offerings-error")) 824 }) 825 }) 826 827 When("updating the service offering fails", func() { 828 BeforeEach(func() { 829 fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns( 830 resources.ServiceOffering{GUID: "some-guid"}, 831 ccv3.Warnings([]string{"warning-1", "warning-2"}), 832 nil, 833 ) 834 fakeCloudControllerClient.UpdateResourceMetadataReturns( 835 "", 836 ccv3.Warnings{"set-service-offering"}, 837 errors.New("update-service-offering-error"), 838 ) 839 }) 840 841 It("returns the error and all warnings", func() { 842 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-offering")) 843 Expect(executeErr).To(MatchError("update-service-offering-error")) 844 }) 845 }) 846 }) 847 }) 848 849 Describe("UpdateServicePlanLabels", func() { 850 const serviceBrokerName = "fake-service-broker" 851 const serviceOfferingName = "fake-service-offering" 852 853 JustBeforeEach(func() { 854 warnings, executeErr = actor.UpdateServicePlanLabels(resourceName, serviceOfferingName, serviceBrokerName, labels) 855 }) 856 857 When("there are no client errors", func() { 858 BeforeEach(func() { 859 fakeCloudControllerClient.GetServicePlansReturns( 860 []resources.ServicePlan{{GUID: "some-service-plan-guid", Name: resourceName}}, 861 []string{"warning-1", "warning-2"}, 862 nil, 863 ) 864 865 fakeCloudControllerClient.UpdateResourceMetadataReturns( 866 "", 867 ccv3.Warnings{"set-service-plan-metadata"}, 868 nil, 869 ) 870 }) 871 872 It("gets the service plan", func() { 873 Expect(executeErr).ToNot(HaveOccurred()) 874 Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1)) 875 Expect(fakeCloudControllerClient.GetServicePlansArgsForCall(0)).To(ConsistOf( 876 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 877 ccv3.Query{Key: ccv3.ServiceBrokerNamesFilter, Values: []string{serviceBrokerName}}, 878 ccv3.Query{Key: ccv3.ServiceOfferingNamesFilter, Values: []string{serviceOfferingName}}, 879 )) 880 }) 881 882 It("sets the service plan labels", func() { 883 Expect(executeErr).ToNot(HaveOccurred()) 884 Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1)) 885 resourceType, servicePlanGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0) 886 Expect(resourceType).To(BeEquivalentTo("service-plan")) 887 Expect(servicePlanGUID).To(BeEquivalentTo("some-service-plan-guid")) 888 Expect(sentMetadata.Labels).To(BeEquivalentTo(labels)) 889 }) 890 891 It("aggregates warnings", func() { 892 Expect(executeErr).ToNot(HaveOccurred()) 893 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-plan-metadata")) 894 }) 895 }) 896 897 When("there are client errors", func() { 898 When("fetching the service plan fails", func() { 899 BeforeEach(func() { 900 fakeCloudControllerClient.GetServicePlansReturns( 901 []resources.ServicePlan{}, 902 ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}), 903 errors.New("get-service-plan-error"), 904 ) 905 }) 906 907 It("returns the error and all warnings", func() { 908 Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2")) 909 Expect(executeErr).To(MatchError("get-service-plan-error")) 910 }) 911 }) 912 913 When("updating the service plan fails", func() { 914 BeforeEach(func() { 915 fakeCloudControllerClient.GetServicePlansReturns( 916 []resources.ServicePlan{{GUID: "some-guid"}}, 917 []string{"warning-1", "warning-2"}, 918 nil, 919 ) 920 fakeCloudControllerClient.UpdateResourceMetadataReturns( 921 "", 922 ccv3.Warnings{"set-service-plan"}, 923 errors.New("update-service-plan-error"), 924 ) 925 }) 926 927 It("returns the error and all warnings", func() { 928 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-plan")) 929 Expect(executeErr).To(MatchError("update-service-plan-error")) 930 }) 931 }) 932 }) 933 }) 934 935 Describe("GetDomainLabels", func() { 936 JustBeforeEach(func() { 937 labels, warnings, executeErr = actor.GetDomainLabels(resourceName) 938 }) 939 940 When("there are no client errors", func() { 941 BeforeEach(func() { 942 fakeCloudControllerClient.GetDomainsReturns( 943 []resources.Domain{{GUID: "some-guid"}}, 944 ccv3.Warnings([]string{"warning-1", "warning-2"}), 945 nil, 946 ) 947 }) 948 949 It("gets the domain", func() { 950 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 951 Expect(fakeCloudControllerClient.GetDomainsArgsForCall(0)).To(ConsistOf( 952 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 953 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 954 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 955 )) 956 }) 957 958 When("there are no labels on a domain", func() { 959 It("returns an empty map", func() { 960 Expect(executeErr).NotTo(HaveOccurred()) 961 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 962 Expect(labels).To(BeEmpty()) 963 }) 964 }) 965 966 When("there are labels", func() { 967 var expectedLabels map[string]types.NullString 968 969 BeforeEach(func() { 970 expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")} 971 fakeCloudControllerClient.GetDomainsReturns( 972 []resources.Domain{{ 973 GUID: "some-guid", 974 Metadata: &resources.Metadata{ 975 Labels: expectedLabels, 976 }, 977 }}, 978 ccv3.Warnings([]string{"warning-1", "warning-2"}), 979 nil, 980 ) 981 }) 982 It("returns the labels", func() { 983 Expect(executeErr).NotTo(HaveOccurred()) 984 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 985 Expect(labels).To(Equal(expectedLabels)) 986 }) 987 }) 988 }) 989 990 When("there is a client error", func() { 991 BeforeEach(func() { 992 fakeCloudControllerClient.GetDomainsReturns( 993 []resources.Domain{{GUID: "some-guid"}}, 994 ccv3.Warnings([]string{"warning-1", "warning-2"}), 995 errors.New("get-domains-error"), 996 ) 997 }) 998 When("GetDomainByName fails", func() { 999 It("returns the error and all warnings", func() { 1000 Expect(executeErr).To(HaveOccurred()) 1001 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1002 Expect(executeErr).To(MatchError("get-domains-error")) 1003 }) 1004 }) 1005 }) 1006 }) 1007 1008 Describe("GetRouteLabels", func() { 1009 JustBeforeEach(func() { 1010 labels, warnings, executeErr = actor.GetRouteLabels("sub.example.com/my-route/path", spaceGUID) 1011 }) 1012 1013 When("there are no client errors", func() { 1014 BeforeEach(func() { 1015 fakeCloudControllerClient.GetDomainsReturns( 1016 []resources.Domain{ 1017 {Name: "domain-name", GUID: "domain-guid"}, 1018 }, 1019 ccv3.Warnings{"get-domains-warning"}, 1020 nil, 1021 ) 1022 1023 fakeCloudControllerClient.GetRoutesReturns( 1024 []resources.Route{ 1025 {GUID: "route-guid", SpaceGUID: "some-space-guid", DomainGUID: "domain-guid", Host: "hostname", URL: "hostname.domain-name", Path: "/the-path"}, 1026 }, 1027 ccv3.Warnings([]string{"warning-1", "warning-2"}), 1028 nil, 1029 ) 1030 }) 1031 1032 It("gets the route", func() { 1033 Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1)) 1034 Expect(fakeCloudControllerClient.GetRoutesArgsForCall(0)).To(ConsistOf( 1035 ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{spaceGUID}}, 1036 ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{"domain-guid"}}, 1037 ccv3.Query{Key: ccv3.HostsFilter, Values: []string{""}}, 1038 ccv3.Query{Key: ccv3.PathsFilter, Values: []string{"/my-route/path"}}, 1039 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 1040 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 1041 )) 1042 }) 1043 1044 When("there are no labels on a route", func() { 1045 It("returns an empty map", func() { 1046 Expect(executeErr).NotTo(HaveOccurred()) 1047 Expect(warnings).To(ConsistOf("get-domains-warning", "warning-1", "warning-2")) 1048 Expect(labels).To(BeEmpty()) 1049 }) 1050 }) 1051 1052 When("there are labels", func() { 1053 var expectedLabels map[string]types.NullString 1054 1055 BeforeEach(func() { 1056 expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")} 1057 fakeCloudControllerClient.GetRoutesReturns( 1058 []resources.Route{ 1059 { 1060 GUID: "some-guid", 1061 Metadata: &resources.Metadata{ 1062 Labels: expectedLabels, 1063 }, 1064 }, 1065 }, 1066 ccv3.Warnings([]string{"warning-1", "warning-2"}), 1067 nil, 1068 ) 1069 }) 1070 It("returns the labels", func() { 1071 Expect(executeErr).NotTo(HaveOccurred()) 1072 Expect(warnings).To(ConsistOf("get-domains-warning", "warning-1", "warning-2")) 1073 Expect(labels).To(Equal(expectedLabels)) 1074 }) 1075 }) 1076 }) 1077 1078 When("there is a client error", func() { 1079 BeforeEach(func() { 1080 fakeCloudControllerClient.GetDomainsReturns( 1081 []resources.Domain{ 1082 {Name: "domain-name", GUID: "domain-guid"}, 1083 }, 1084 ccv3.Warnings{"get-domains-warning"}, 1085 nil, 1086 ) 1087 1088 fakeCloudControllerClient.GetRoutesReturns( 1089 []resources.Route{{GUID: "some-guid"}}, 1090 ccv3.Warnings([]string{"warning-1", "warning-2"}), 1091 errors.New("get-routes-error"), 1092 ) 1093 }) 1094 1095 It("returns the error and all warnings", func() { 1096 Expect(executeErr).To(HaveOccurred()) 1097 Expect(warnings).To(ConsistOf("get-domains-warning", "warning-1", "warning-2")) 1098 Expect(executeErr).To(MatchError("get-routes-error")) 1099 }) 1100 }) 1101 }) 1102 1103 Describe("GetStackLabels", func() { 1104 JustBeforeEach(func() { 1105 labels, warnings, executeErr = actor.GetStackLabels(resourceName) 1106 }) 1107 1108 When("there are no client errors", func() { 1109 BeforeEach(func() { 1110 fakeCloudControllerClient.GetStacksReturns( 1111 []resources.Stack{resources.Stack{GUID: "some-guid"}}, 1112 ccv3.Warnings([]string{"warning-1", "warning-2"}), 1113 nil, 1114 ) 1115 }) 1116 1117 It("gets the stack", func() { 1118 Expect(fakeCloudControllerClient.GetStacksCallCount()).To(Equal(1)) 1119 Expect(fakeCloudControllerClient.GetStacksArgsForCall(0)).To(ConsistOf( 1120 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 1121 ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}}, 1122 ccv3.Query{Key: ccv3.Page, Values: []string{"1"}}, 1123 )) 1124 }) 1125 1126 When("there are no labels on a stack", func() { 1127 It("returns an empty map", func() { 1128 Expect(executeErr).NotTo(HaveOccurred()) 1129 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1130 Expect(labels).To(BeEmpty()) 1131 }) 1132 }) 1133 1134 When("there are labels", func() { 1135 var expectedLabels map[string]types.NullString 1136 1137 BeforeEach(func() { 1138 expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")} 1139 fakeCloudControllerClient.GetStacksReturns( 1140 []resources.Stack{resources.Stack{ 1141 GUID: "some-guid", 1142 Metadata: &resources.Metadata{ 1143 Labels: expectedLabels, 1144 }, 1145 }}, 1146 ccv3.Warnings([]string{"warning-1", "warning-2"}), 1147 nil, 1148 ) 1149 }) 1150 It("returns the labels", func() { 1151 Expect(executeErr).NotTo(HaveOccurred()) 1152 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1153 Expect(labels).To(Equal(expectedLabels)) 1154 }) 1155 }) 1156 }) 1157 1158 When("there is a client error", func() { 1159 BeforeEach(func() { 1160 fakeCloudControllerClient.GetStacksReturns( 1161 []resources.Stack{resources.Stack{GUID: "some-guid"}}, 1162 ccv3.Warnings([]string{"warning-1", "warning-2"}), 1163 errors.New("get-stacks-error"), 1164 ) 1165 }) 1166 When("GetStackByName fails", func() { 1167 It("returns the error and all warnings", func() { 1168 Expect(executeErr).To(HaveOccurred()) 1169 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1170 Expect(executeErr).To(MatchError("get-stacks-error")) 1171 }) 1172 }) 1173 }) 1174 }) 1175 1176 Describe("GetServiceBrokerLabels", func() { 1177 When("service broker does not exist", func() { 1178 BeforeEach(func() { 1179 fakeCloudControllerClient.GetServiceBrokersReturns( 1180 []resources.ServiceBroker{}, 1181 []string{"warning-1", "warning-2"}, 1182 nil, 1183 ) 1184 }) 1185 1186 JustBeforeEach(func() { 1187 labels, warnings, executeErr = actor.GetServiceBrokerLabels(resourceName) 1188 }) 1189 1190 It("returns a service broker not found error and warnings", func() { 1191 Expect(executeErr).To(HaveOccurred()) 1192 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1193 Expect(executeErr.Error()).To(ContainSubstring("Service broker 'some-resource' not found")) 1194 }) 1195 }) 1196 1197 When("client returns an error", func() { 1198 BeforeEach(func() { 1199 fakeCloudControllerClient.GetServiceBrokersReturns( 1200 []resources.ServiceBroker{}, 1201 []string{"warning"}, 1202 errors.New("some random error"), 1203 ) 1204 }) 1205 1206 JustBeforeEach(func() { 1207 labels, warnings, executeErr = actor.GetServiceBrokerLabels(resourceName) 1208 }) 1209 1210 It("returns error and prints warnings", func() { 1211 Expect(executeErr).To(HaveOccurred()) 1212 Expect(warnings).To(ConsistOf("warning")) 1213 Expect(executeErr).To(MatchError("some random error")) 1214 }) 1215 }) 1216 When("service broker has labels", func() { 1217 var expectedLabels map[string]types.NullString 1218 1219 BeforeEach(func() { 1220 expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")} 1221 fakeCloudControllerClient.GetServiceBrokersReturns( 1222 []resources.ServiceBroker{resources.ServiceBroker{ 1223 GUID: "some-guid", 1224 Name: resourceName, 1225 Metadata: &resources.Metadata{ 1226 Labels: expectedLabels, 1227 }, 1228 }}, 1229 []string{"warning-1", "warning-2"}, 1230 nil, 1231 ) 1232 }) 1233 1234 JustBeforeEach(func() { 1235 labels, warnings, executeErr = actor.GetServiceBrokerLabels(resourceName) 1236 }) 1237 1238 It("returns labels associated with the service broker as well as warnings", func() { 1239 Expect(executeErr).ToNot(HaveOccurred()) 1240 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1241 Expect(labels).To(Equal(expectedLabels)) 1242 }) 1243 }) 1244 1245 }) 1246 1247 Describe("GetServiceInstanceLabels", func() { 1248 JustBeforeEach(func() { 1249 labels, warnings, executeErr = actor.GetServiceInstanceLabels(resourceName, spaceGUID) 1250 }) 1251 1252 When("does not exist", func() { 1253 BeforeEach(func() { 1254 fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( 1255 resources.ServiceInstance{}, 1256 ccv3.IncludedResources{}, 1257 []string{"warning-1", "warning-2"}, 1258 ccerror.ServiceInstanceNotFoundError{}, 1259 ) 1260 }) 1261 1262 It("returns a service instance not found error and warnings", func() { 1263 Expect(executeErr).To(MatchError(actionerror.ServiceInstanceNotFoundError{})) 1264 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1265 }) 1266 }) 1267 1268 When("client returns an error", func() { 1269 BeforeEach(func() { 1270 fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( 1271 resources.ServiceInstance{}, 1272 ccv3.IncludedResources{}, 1273 []string{"warning"}, 1274 errors.New("some random error"), 1275 ) 1276 }) 1277 1278 It("returns error and warnings", func() { 1279 Expect(executeErr).To(MatchError("some random error")) 1280 Expect(warnings).To(ConsistOf("warning")) 1281 }) 1282 }) 1283 1284 When("service instance has labels", func() { 1285 var expectedLabels map[string]types.NullString 1286 1287 BeforeEach(func() { 1288 expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")} 1289 fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( 1290 resources.ServiceInstance{ 1291 GUID: "some-guid", 1292 Name: resourceName, 1293 Metadata: &resources.Metadata{ 1294 Labels: expectedLabels, 1295 }, 1296 }, 1297 ccv3.IncludedResources{}, 1298 []string{"warning-1", "warning-2"}, 1299 nil, 1300 ) 1301 }) 1302 1303 It("returns labels associated with the service broker as well as warnings", func() { 1304 Expect(executeErr).ToNot(HaveOccurred()) 1305 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1306 Expect(labels).To(Equal(expectedLabels)) 1307 }) 1308 }) 1309 }) 1310 1311 Describe("GetServiceOfferingLabels", func() { 1312 const serviceBrokerName = "my-service-broker" 1313 1314 When("service offering does not exist", func() { 1315 BeforeEach(func() { 1316 fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns( 1317 resources.ServiceOffering{}, 1318 []string{"warning-1", "warning-2"}, 1319 ccerror.ServiceOfferingNotFoundError{ 1320 ServiceOfferingName: resourceName, 1321 ServiceBrokerName: serviceBrokerName, 1322 }, 1323 ) 1324 }) 1325 1326 JustBeforeEach(func() { 1327 labels, warnings, executeErr = actor.GetServiceOfferingLabels(resourceName, serviceBrokerName) 1328 }) 1329 1330 It("returns a service offering not found error and warnings", func() { 1331 Expect(executeErr).To(HaveOccurred()) 1332 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1333 Expect(executeErr.Error()).To(ContainSubstring("Service offering '%s' for service broker '%s' not found", resourceName, serviceBrokerName)) 1334 }) 1335 }) 1336 1337 When("client returns an error", func() { 1338 BeforeEach(func() { 1339 fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns( 1340 resources.ServiceOffering{}, 1341 []string{"warning"}, 1342 errors.New("some random error"), 1343 ) 1344 }) 1345 1346 JustBeforeEach(func() { 1347 labels, warnings, executeErr = actor.GetServiceOfferingLabels(resourceName, serviceBrokerName) 1348 }) 1349 1350 It("returns error and prints warnings", func() { 1351 Expect(executeErr).To(HaveOccurred()) 1352 Expect(warnings).To(ConsistOf("warning")) 1353 Expect(executeErr).To(MatchError("some random error")) 1354 }) 1355 }) 1356 1357 When("service offering has labels", func() { 1358 var expectedLabels map[string]types.NullString 1359 1360 BeforeEach(func() { 1361 expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")} 1362 fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns( 1363 resources.ServiceOffering{ 1364 GUID: "some-guid", 1365 Name: resourceName, 1366 Metadata: &resources.Metadata{ 1367 Labels: expectedLabels, 1368 }, 1369 }, 1370 []string{"warning-1", "warning-2"}, 1371 nil, 1372 ) 1373 }) 1374 1375 JustBeforeEach(func() { 1376 labels, warnings, executeErr = actor.GetServiceOfferingLabels(resourceName, serviceBrokerName) 1377 }) 1378 1379 It("queries the right names", func() { 1380 Expect(fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerCallCount()).To(Equal(1)) 1381 requestedServiceOffering, requestedServiceBroker := fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerArgsForCall(0) 1382 Expect(requestedServiceOffering).To(Equal(resourceName)) 1383 Expect(requestedServiceBroker).To(Equal(serviceBrokerName)) 1384 }) 1385 1386 It("returns labels associated with the service offering as well as warnings", func() { 1387 Expect(executeErr).ToNot(HaveOccurred()) 1388 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1389 Expect(labels).To(Equal(expectedLabels)) 1390 }) 1391 }) 1392 }) 1393 1394 Describe("GetServicePlanLabels", func() { 1395 When("service plan does not exist", func() { 1396 BeforeEach(func() { 1397 fakeCloudControllerClient.GetServicePlansReturns( 1398 []resources.ServicePlan{}, 1399 []string{"warning-1", "warning-2"}, 1400 nil, 1401 ) 1402 }) 1403 1404 JustBeforeEach(func() { 1405 labels, warnings, executeErr = actor.GetServicePlanLabels(resourceName, "", "") 1406 }) 1407 1408 It("returns a service plan not found error and warnings", func() { 1409 Expect(executeErr).To(HaveOccurred()) 1410 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1411 Expect(executeErr.Error()).To(ContainSubstring("Service plan '%s' not found", resourceName)) 1412 }) 1413 }) 1414 1415 When("client returns an error", func() { 1416 BeforeEach(func() { 1417 fakeCloudControllerClient.GetServicePlansReturns( 1418 []resources.ServicePlan{}, 1419 []string{"warning"}, 1420 errors.New("some random error"), 1421 ) 1422 }) 1423 1424 JustBeforeEach(func() { 1425 labels, warnings, executeErr = actor.GetServicePlanLabels(resourceName, "", "") 1426 }) 1427 1428 It("returns error and prints warnings", func() { 1429 Expect(executeErr).To(HaveOccurred()) 1430 Expect(warnings).To(ConsistOf("warning")) 1431 Expect(executeErr).To(MatchError("some random error")) 1432 }) 1433 }) 1434 1435 When("service plan has labels", func() { 1436 var expectedLabels map[string]types.NullString 1437 1438 BeforeEach(func() { 1439 expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")} 1440 fakeCloudControllerClient.GetServicePlansReturns( 1441 []resources.ServicePlan{{ 1442 GUID: "some-guid", 1443 Name: resourceName, 1444 Metadata: &resources.Metadata{ 1445 Labels: expectedLabels, 1446 }, 1447 }}, 1448 []string{"warning-1", "warning-2"}, 1449 nil, 1450 ) 1451 }) 1452 1453 JustBeforeEach(func() { 1454 labels, warnings, executeErr = actor.GetServicePlanLabels(resourceName, "serviceOfferingName", "serviceBrokerName") 1455 }) 1456 1457 It("queries the right names", func() { 1458 Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1)) 1459 Expect(fakeCloudControllerClient.GetServicePlansArgsForCall(0)).To(ConsistOf( 1460 ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}}, 1461 ccv3.Query{Key: ccv3.ServiceOfferingNamesFilter, Values: []string{"serviceOfferingName"}}, 1462 ccv3.Query{Key: ccv3.ServiceBrokerNamesFilter, Values: []string{"serviceBrokerName"}}, 1463 )) 1464 }) 1465 1466 It("returns labels associated with the service plan as well as warnings", func() { 1467 Expect(executeErr).ToNot(HaveOccurred()) 1468 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 1469 Expect(labels).To(Equal(expectedLabels)) 1470 }) 1471 }) 1472 }) 1473 })