github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/label_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v7action"
     7  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
    10  	"code.cloudfoundry.org/cli/resources"
    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  					[]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  						[]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  						[]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  					[]Domain{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  				))
   146  			})
   147  
   148  			It("sets the domain labels", func() {
   149  				Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1))
   150  				resourceType, domainGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0)
   151  				Expect(executeErr).ToNot(HaveOccurred())
   152  				Expect(resourceType).To(BeEquivalentTo("domain"))
   153  				Expect(domainGUID).To(BeEquivalentTo("some-guid"))
   154  				Expect(sentMetadata.Labels).To(BeEquivalentTo(labels))
   155  			})
   156  
   157  			It("aggregates warnings", func() {
   158  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-updating-metadata"))
   159  			})
   160  		})
   161  
   162  		When("there are client errors", func() {
   163  			When("fetching the domain fails", func() {
   164  				BeforeEach(func() {
   165  					fakeCloudControllerClient.GetDomainsReturns(
   166  						[]Domain{Domain{GUID: "some-guid"}},
   167  						ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}),
   168  						errors.New("get-domains-error"),
   169  					)
   170  				})
   171  
   172  				It("returns the error and all warnings", func() {
   173  					Expect(executeErr).To(HaveOccurred())
   174  					Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2"))
   175  					Expect(executeErr).To(MatchError("get-domains-error"))
   176  				})
   177  			})
   178  
   179  			When("updating the domain fails", func() {
   180  				BeforeEach(func() {
   181  					fakeCloudControllerClient.GetDomainsReturns(
   182  						[]Domain{Domain{GUID: "some-guid"}},
   183  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   184  						nil,
   185  					)
   186  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   187  						"",
   188  						ccv3.Warnings{"warning-updating-metadata"},
   189  						errors.New("update-domain-error"),
   190  					)
   191  				})
   192  				It("returns the error and all warnings", func() {
   193  					Expect(executeErr).To(HaveOccurred())
   194  					Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-updating-metadata"))
   195  					Expect(executeErr).To(MatchError("update-domain-error"))
   196  				})
   197  			})
   198  		})
   199  	})
   200  
   201  	Describe("UpdateOrganizationLabelsByOrganizationName", func() {
   202  		JustBeforeEach(func() {
   203  			warnings, executeErr = actor.UpdateOrganizationLabelsByOrganizationName(resourceName, labels)
   204  		})
   205  
   206  		When("there are no client errors", func() {
   207  			BeforeEach(func() {
   208  				fakeCloudControllerClient.GetOrganizationsReturns(
   209  					[]Organization{Organization{GUID: "some-guid"}},
   210  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
   211  					nil,
   212  				)
   213  				fakeCloudControllerClient.UpdateResourceMetadataReturns(
   214  					"",
   215  					ccv3.Warnings{"set-org"},
   216  					nil,
   217  				)
   218  			})
   219  
   220  			It("gets the organization", func() {
   221  				Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1))
   222  				Expect(fakeCloudControllerClient.GetOrganizationsArgsForCall(0)).To(ConsistOf(
   223  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}},
   224  				))
   225  			})
   226  
   227  			It("sets the org labels", func() {
   228  				Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1))
   229  				resourceType, orgGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0)
   230  				Expect(executeErr).ToNot(HaveOccurred())
   231  				Expect(resourceType).To(BeEquivalentTo("org"))
   232  				Expect(orgGUID).To(BeEquivalentTo("some-guid"))
   233  				Expect(sentMetadata.Labels).To(BeEquivalentTo(labels))
   234  			})
   235  
   236  			It("aggregates warnings", func() {
   237  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-org"))
   238  			})
   239  		})
   240  
   241  		When("there are client errors", func() {
   242  			When("fetching the organization fails", func() {
   243  				BeforeEach(func() {
   244  					fakeCloudControllerClient.GetOrganizationsReturns(
   245  						[]Organization{Organization{GUID: "some-guid"}},
   246  						ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}),
   247  						errors.New("get-orgs-error"),
   248  					)
   249  				})
   250  
   251  				It("returns the error and all warnings", func() {
   252  					Expect(executeErr).To(HaveOccurred())
   253  					Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2"))
   254  					Expect(executeErr).To(MatchError("get-orgs-error"))
   255  				})
   256  			})
   257  
   258  			When("updating the organization fails", func() {
   259  				BeforeEach(func() {
   260  					fakeCloudControllerClient.GetOrganizationsReturns(
   261  						[]Organization{Organization{GUID: "some-guid"}},
   262  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   263  						nil,
   264  					)
   265  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   266  						"",
   267  						ccv3.Warnings{"set-org"},
   268  						errors.New("update-orgs-error"),
   269  					)
   270  				})
   271  				It("returns the error and all warnings", func() {
   272  					Expect(executeErr).To(HaveOccurred())
   273  					Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-org"))
   274  					Expect(executeErr).To(MatchError("update-orgs-error"))
   275  				})
   276  			})
   277  		})
   278  	})
   279  
   280  	Describe("UpdateRouteLabels", func() {
   281  		JustBeforeEach(func() {
   282  			warnings, executeErr = actor.UpdateRouteLabels("sub.example.com/my-route/path", "space-guid", labels)
   283  		})
   284  
   285  		When("there are no client errors", func() {
   286  			BeforeEach(func() {
   287  				fakeCloudControllerClient.GetDomainsReturns(
   288  					[]Domain{
   289  						{Name: "domain-name", GUID: "domain-guid"},
   290  					},
   291  					ccv3.Warnings{"get-domains-warning"},
   292  					nil,
   293  				)
   294  
   295  				fakeCloudControllerClient.GetRoutesReturns(
   296  					[]Route{
   297  						{GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", URL: "hostname.domain-name", Path: "/the-path"},
   298  					},
   299  					ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   300  					nil,
   301  				)
   302  
   303  				fakeCloudControllerClient.UpdateResourceMetadataReturns(
   304  					"",
   305  					ccv3.Warnings{"set-route-warning"},
   306  					nil,
   307  				)
   308  			})
   309  
   310  			It("gets the domain", func() {
   311  				Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1))
   312  				Expect(fakeCloudControllerClient.GetDomainsArgsForCall(0)).To(ConsistOf(
   313  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{"sub.example.com"}},
   314  				))
   315  			})
   316  
   317  			It("gets the route", func() {
   318  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   319  				Expect(fakeCloudControllerClient.GetRoutesArgsForCall(0)).To(ConsistOf(
   320  					ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{"space-guid"}},
   321  					ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{"domain-guid"}},
   322  					ccv3.Query{Key: ccv3.HostsFilter, Values: []string{""}},
   323  					ccv3.Query{Key: ccv3.PathsFilter, Values: []string{"/my-route/path"}},
   324  				))
   325  			})
   326  
   327  			It("sets the route labels", func() {
   328  				Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1))
   329  				resourceType, routeGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0)
   330  				Expect(executeErr).ToNot(HaveOccurred())
   331  				Expect(resourceType).To(BeEquivalentTo("route"))
   332  				Expect(routeGUID).To(BeEquivalentTo("route-guid"))
   333  				Expect(sentMetadata.Labels).To(BeEquivalentTo(labels))
   334  			})
   335  
   336  			It("aggregates warnings", func() {
   337  				Expect(warnings).To(ConsistOf("get-domains-warning", "get-route-warning-1", "get-route-warning-2", "set-route-warning"))
   338  			})
   339  		})
   340  
   341  		When("there are client errors", func() {
   342  			When("fetching the route fails", func() {
   343  				BeforeEach(func() {
   344  					fakeCloudControllerClient.GetDomainsReturns(
   345  						nil,
   346  						ccv3.Warnings{"get-domains-warning"},
   347  						errors.New("get-domain-error"),
   348  					)
   349  				})
   350  
   351  				It("returns the error and all warnings", func() {
   352  					Expect(executeErr).To(HaveOccurred())
   353  					Expect(warnings).To(ConsistOf("get-domains-warning"))
   354  					Expect(executeErr).To(MatchError("get-domain-error"))
   355  				})
   356  			})
   357  
   358  			When("updating the route fails", func() {
   359  				BeforeEach(func() {
   360  					fakeCloudControllerClient.GetDomainsReturns(
   361  						[]Domain{
   362  							{Name: "domain-name", GUID: "domain-guid"},
   363  						},
   364  						ccv3.Warnings{"get-domains-warning"},
   365  						nil,
   366  					)
   367  
   368  					fakeCloudControllerClient.GetRoutesReturns(
   369  						[]Route{
   370  							{GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", URL: "hostname.domain-name", Path: "/the-path"},
   371  						},
   372  						ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   373  						nil,
   374  					)
   375  
   376  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   377  						"",
   378  						ccv3.Warnings{"set-route-warning"},
   379  						errors.New("update-route-error"),
   380  					)
   381  				})
   382  
   383  				It("returns the error and all warnings", func() {
   384  					Expect(executeErr).To(HaveOccurred())
   385  					Expect(warnings).To(ConsistOf("get-domains-warning", "get-route-warning-1", "get-route-warning-2", "set-route-warning"))
   386  				})
   387  			})
   388  		})
   389  	})
   390  
   391  	Describe("UpdateSpaceLabelsBySpaceName", func() {
   392  		JustBeforeEach(func() {
   393  			warnings, executeErr = actor.UpdateSpaceLabelsBySpaceName(resourceName, orgGUID, labels)
   394  		})
   395  
   396  		When("there are no client errors", func() {
   397  			BeforeEach(func() {
   398  				fakeCloudControllerClient.GetSpacesReturns(
   399  					[]resources.Space{resources.Space{GUID: "some-guid"}},
   400  					ccv3.IncludedResources{},
   401  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
   402  					nil,
   403  				)
   404  				fakeCloudControllerClient.UpdateResourceMetadataReturns(
   405  					"",
   406  					ccv3.Warnings{"set-space-metadata"},
   407  					nil,
   408  				)
   409  			})
   410  
   411  			It("gets the space", func() {
   412  				Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1))
   413  				Expect(fakeCloudControllerClient.GetSpacesArgsForCall(0)).To(ConsistOf(
   414  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}},
   415  					ccv3.Query{Key: ccv3.OrganizationGUIDFilter, Values: []string{orgGUID}},
   416  				))
   417  			})
   418  
   419  			It("sets the space labels", func() {
   420  				Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1))
   421  				resourceType, spaceGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0)
   422  				Expect(executeErr).ToNot(HaveOccurred())
   423  				Expect(resourceType).To(BeEquivalentTo("space"))
   424  				Expect(spaceGUID).To(BeEquivalentTo("some-guid"))
   425  				Expect(sentMetadata.Labels).To(BeEquivalentTo(labels))
   426  			})
   427  
   428  			It("aggregates warnings", func() {
   429  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-space-metadata"))
   430  			})
   431  		})
   432  
   433  		When("there are client errors", func() {
   434  			When("fetching the space fails", func() {
   435  				BeforeEach(func() {
   436  					fakeCloudControllerClient.GetSpacesReturns(
   437  						[]resources.Space{resources.Space{GUID: "some-guid"}},
   438  						ccv3.IncludedResources{},
   439  						ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}),
   440  						errors.New("get-spaces-error"),
   441  					)
   442  				})
   443  
   444  				It("returns the error and all warnings", func() {
   445  					Expect(executeErr).To(HaveOccurred())
   446  					Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2"))
   447  					Expect(executeErr).To(MatchError("get-spaces-error"))
   448  				})
   449  			})
   450  
   451  			When("updating the space fails", func() {
   452  				BeforeEach(func() {
   453  					fakeCloudControllerClient.GetSpacesReturns(
   454  						[]resources.Space{resources.Space{GUID: "some-guid"}},
   455  						ccv3.IncludedResources{},
   456  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   457  						nil,
   458  					)
   459  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   460  						"",
   461  						ccv3.Warnings{"set-space"},
   462  						errors.New("update-space-error"),
   463  					)
   464  				})
   465  				It("returns the error and all warnings", func() {
   466  					Expect(executeErr).To(HaveOccurred())
   467  					Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-space"))
   468  					Expect(executeErr).To(MatchError("update-space-error"))
   469  				})
   470  			})
   471  		})
   472  	})
   473  
   474  	Describe("UpdateStackLabelsByStackName", func() {
   475  		JustBeforeEach(func() {
   476  			warnings, executeErr = actor.UpdateStackLabelsByStackName(resourceName, labels)
   477  		})
   478  
   479  		When("there are no client errors", func() {
   480  			BeforeEach(func() {
   481  				fakeCloudControllerClient.GetStacksReturns(
   482  					[]ccv3.Stack{ccv3.Stack{GUID: "some-guid"}},
   483  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
   484  					nil,
   485  				)
   486  				fakeCloudControllerClient.UpdateResourceMetadataReturns(
   487  					"",
   488  					ccv3.Warnings{"set-stack-metadata"},
   489  					nil,
   490  				)
   491  			})
   492  
   493  			It("gets the stack", func() {
   494  				Expect(fakeCloudControllerClient.GetStacksCallCount()).To(Equal(1))
   495  				Expect(fakeCloudControllerClient.GetStacksArgsForCall(0)).To(ConsistOf(
   496  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}},
   497  				))
   498  			})
   499  
   500  			It("sets the stack labels", func() {
   501  				Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1))
   502  				resourceType, stackGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0)
   503  				Expect(executeErr).ToNot(HaveOccurred())
   504  				Expect(resourceType).To(BeEquivalentTo("stack"))
   505  				Expect(stackGUID).To(BeEquivalentTo("some-guid"))
   506  				Expect(sentMetadata.Labels).To(BeEquivalentTo(labels))
   507  			})
   508  
   509  			It("aggregates warnings", func() {
   510  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-stack-metadata"))
   511  			})
   512  		})
   513  
   514  		When("there are client errors", func() {
   515  			When("fetching the stack fails", func() {
   516  				BeforeEach(func() {
   517  					fakeCloudControllerClient.GetStacksReturns(
   518  						[]ccv3.Stack{ccv3.Stack{GUID: "some-guid"}},
   519  						ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}),
   520  						errors.New("get-stacks-error"),
   521  					)
   522  				})
   523  
   524  				It("returns the error and all warnings", func() {
   525  					Expect(executeErr).To(HaveOccurred())
   526  					Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2"))
   527  					Expect(executeErr).To(MatchError("get-stacks-error"))
   528  				})
   529  			})
   530  
   531  			When("updating the stack fails", func() {
   532  				BeforeEach(func() {
   533  					fakeCloudControllerClient.GetStacksReturns(
   534  						[]ccv3.Stack{ccv3.Stack{GUID: "some-guid"}},
   535  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   536  						nil,
   537  					)
   538  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   539  						"",
   540  						ccv3.Warnings{"set-stack"},
   541  						errors.New("update-stack-error"),
   542  					)
   543  				})
   544  				It("returns the error and all warnings", func() {
   545  					Expect(executeErr).To(HaveOccurred())
   546  					Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-stack"))
   547  					Expect(executeErr).To(MatchError("update-stack-error"))
   548  				})
   549  			})
   550  		})
   551  	})
   552  
   553  	Describe("UpdateServiceBrokerLabelsByServiceBrokerName", func() {
   554  		JustBeforeEach(func() {
   555  			warnings, executeErr = actor.UpdateServiceBrokerLabelsByServiceBrokerName(resourceName, labels)
   556  		})
   557  
   558  		When("there are no client errors", func() {
   559  			BeforeEach(func() {
   560  				fakeCloudControllerClient.GetServiceBrokersReturns(
   561  					[]resources.ServiceBroker{{GUID: "some-broker-guid", Name: resourceName}},
   562  					[]string{"warning-1", "warning-2"},
   563  					nil,
   564  				)
   565  
   566  				fakeCloudControllerClient.UpdateResourceMetadataReturns(
   567  					ccv3.JobURL("fake-job-url"),
   568  					ccv3.Warnings{"set-service-broker-metadata"},
   569  					nil,
   570  				)
   571  
   572  				fakeCloudControllerClient.PollJobReturns(ccv3.Warnings{"poll-job-warning"}, nil)
   573  			})
   574  
   575  			It("gets the service broker", func() {
   576  				Expect(executeErr).ToNot(HaveOccurred())
   577  				Expect(fakeCloudControllerClient.GetServiceBrokersCallCount()).To(Equal(1))
   578  			})
   579  
   580  			It("sets the service-broker labels", func() {
   581  				Expect(executeErr).ToNot(HaveOccurred())
   582  				Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1))
   583  				resourceType, serviceBrokerGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0)
   584  				Expect(resourceType).To(BeEquivalentTo("service-broker"))
   585  				Expect(serviceBrokerGUID).To(BeEquivalentTo("some-broker-guid"))
   586  				Expect(sentMetadata.Labels).To(BeEquivalentTo(labels))
   587  			})
   588  
   589  			It("polls the job", func() {
   590  				Expect(executeErr).ToNot(HaveOccurred())
   591  				Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1))
   592  				Expect(fakeCloudControllerClient.PollJobArgsForCall(0)).To(BeEquivalentTo("fake-job-url"))
   593  			})
   594  
   595  			It("aggregates warnings", func() {
   596  				Expect(executeErr).ToNot(HaveOccurred())
   597  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-broker-metadata", "poll-job-warning"))
   598  			})
   599  		})
   600  
   601  		When("there are client errors", func() {
   602  			When("fetching the service-broker fails", func() {
   603  				BeforeEach(func() {
   604  					fakeCloudControllerClient.GetServiceBrokersReturns(
   605  						[]resources.ServiceBroker{},
   606  						ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}),
   607  						errors.New("get-service-broker-error"),
   608  					)
   609  				})
   610  
   611  				It("returns the error and all warnings", func() {
   612  					Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2"))
   613  					Expect(executeErr).To(MatchError("get-service-broker-error"))
   614  				})
   615  			})
   616  
   617  			When("updating the service-broker fails", func() {
   618  				BeforeEach(func() {
   619  					fakeCloudControllerClient.GetServiceBrokersReturns(
   620  						[]resources.ServiceBroker{{GUID: "some-guid", Name: resourceName}},
   621  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   622  						nil,
   623  					)
   624  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   625  						ccv3.JobURL(""),
   626  						ccv3.Warnings{"set-service-broker"},
   627  						errors.New("update-service-broker-error"),
   628  					)
   629  				})
   630  
   631  				It("returns the error and all warnings", func() {
   632  					Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-broker"))
   633  					Expect(executeErr).To(MatchError("update-service-broker-error"))
   634  				})
   635  			})
   636  
   637  			When("polling the job fails", func() {
   638  				BeforeEach(func() {
   639  					fakeCloudControllerClient.GetServiceBrokersReturns(
   640  						[]resources.ServiceBroker{{GUID: "some-guid", Name: resourceName}},
   641  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   642  						nil,
   643  					)
   644  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   645  						ccv3.JobURL("fake-job-url"),
   646  						ccv3.Warnings{"set-service-broker-metadata"},
   647  						nil,
   648  					)
   649  
   650  					fakeCloudControllerClient.PollJobReturns(
   651  						ccv3.Warnings{"another-poll-job-warning"},
   652  						errors.New("polling-error"),
   653  					)
   654  				})
   655  
   656  				It("returns the error and all warnings", func() {
   657  					Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-broker-metadata", "another-poll-job-warning"))
   658  					Expect(executeErr).To(MatchError("polling-error"))
   659  				})
   660  			})
   661  		})
   662  	})
   663  
   664  	Describe("UpdateServiceOfferingLabels", func() {
   665  		const serviceBrokerName = "fake-service-broker"
   666  
   667  		JustBeforeEach(func() {
   668  			warnings, executeErr = actor.UpdateServiceOfferingLabels(resourceName, serviceBrokerName, labels)
   669  		})
   670  
   671  		When("there are no client errors", func() {
   672  			BeforeEach(func() {
   673  				fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(
   674  					resources.ServiceOffering{GUID: "some-service-offering-guid", Name: resourceName},
   675  					[]string{"warning-1", "warning-2"},
   676  					nil,
   677  				)
   678  
   679  				fakeCloudControllerClient.UpdateResourceMetadataReturns(
   680  					"",
   681  					ccv3.Warnings{"set-service-offering-metadata"},
   682  					nil,
   683  				)
   684  			})
   685  
   686  			It("gets the service offering", func() {
   687  				Expect(executeErr).ToNot(HaveOccurred())
   688  				Expect(fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerCallCount()).To(Equal(1))
   689  				requestedServiceName, requestedBrokerName := fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerArgsForCall(0)
   690  				Expect(requestedServiceName).To(Equal(resourceName))
   691  				Expect(requestedBrokerName).To(Equal(serviceBrokerName))
   692  			})
   693  
   694  			It("sets the service offering labels", func() {
   695  				Expect(executeErr).ToNot(HaveOccurred())
   696  				Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1))
   697  				resourceType, serviceBrokerGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0)
   698  				Expect(resourceType).To(BeEquivalentTo("service-offering"))
   699  				Expect(serviceBrokerGUID).To(BeEquivalentTo("some-service-offering-guid"))
   700  				Expect(sentMetadata.Labels).To(BeEquivalentTo(labels))
   701  			})
   702  
   703  			It("aggregates warnings", func() {
   704  				Expect(executeErr).ToNot(HaveOccurred())
   705  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-offering-metadata"))
   706  			})
   707  		})
   708  
   709  		When("there are client errors", func() {
   710  			When("fetching the service offering fails", func() {
   711  				BeforeEach(func() {
   712  					fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(
   713  						resources.ServiceOffering{},
   714  						ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}),
   715  						errors.New("get-service-offerings-error"),
   716  					)
   717  				})
   718  
   719  				It("returns the error and all warnings", func() {
   720  					Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2"))
   721  					Expect(executeErr).To(MatchError("get-service-offerings-error"))
   722  				})
   723  			})
   724  
   725  			When("updating the service offering fails", func() {
   726  				BeforeEach(func() {
   727  					fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(
   728  						resources.ServiceOffering{GUID: "some-guid"},
   729  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   730  						nil,
   731  					)
   732  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   733  						"",
   734  						ccv3.Warnings{"set-service-offering"},
   735  						errors.New("update-service-offering-error"),
   736  					)
   737  				})
   738  
   739  				It("returns the error and all warnings", func() {
   740  					Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-offering"))
   741  					Expect(executeErr).To(MatchError("update-service-offering-error"))
   742  				})
   743  			})
   744  		})
   745  	})
   746  
   747  	Describe("UpdateServicePlanLabels", func() {
   748  		const serviceBrokerName = "fake-service-broker"
   749  		const serviceOfferingName = "fake-service-offering"
   750  
   751  		JustBeforeEach(func() {
   752  			warnings, executeErr = actor.UpdateServicePlanLabels(resourceName, serviceOfferingName, serviceBrokerName, labels)
   753  		})
   754  
   755  		When("there are no client errors", func() {
   756  			BeforeEach(func() {
   757  				fakeCloudControllerClient.GetServicePlansReturns(
   758  					[]resources.ServicePlan{{GUID: "some-service-plan-guid", Name: resourceName}},
   759  					[]string{"warning-1", "warning-2"},
   760  					nil,
   761  				)
   762  
   763  				fakeCloudControllerClient.UpdateResourceMetadataReturns(
   764  					"",
   765  					ccv3.Warnings{"set-service-plan-metadata"},
   766  					nil,
   767  				)
   768  			})
   769  
   770  			It("gets the service plan", func() {
   771  				Expect(executeErr).ToNot(HaveOccurred())
   772  				Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1))
   773  				Expect(fakeCloudControllerClient.GetServicePlansArgsForCall(0)).To(ConsistOf(
   774  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}},
   775  					ccv3.Query{Key: ccv3.ServiceBrokerNamesFilter, Values: []string{serviceBrokerName}},
   776  					ccv3.Query{Key: ccv3.ServiceOfferingNamesFilter, Values: []string{serviceOfferingName}},
   777  				))
   778  			})
   779  
   780  			It("sets the service plan labels", func() {
   781  				Expect(executeErr).ToNot(HaveOccurred())
   782  				Expect(fakeCloudControllerClient.UpdateResourceMetadataCallCount()).To(Equal(1))
   783  				resourceType, servicePlanGUID, sentMetadata := fakeCloudControllerClient.UpdateResourceMetadataArgsForCall(0)
   784  				Expect(resourceType).To(BeEquivalentTo("service-plan"))
   785  				Expect(servicePlanGUID).To(BeEquivalentTo("some-service-plan-guid"))
   786  				Expect(sentMetadata.Labels).To(BeEquivalentTo(labels))
   787  			})
   788  
   789  			It("aggregates warnings", func() {
   790  				Expect(executeErr).ToNot(HaveOccurred())
   791  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-plan-metadata"))
   792  			})
   793  		})
   794  
   795  		When("there are client errors", func() {
   796  			When("fetching the service plan fails", func() {
   797  				BeforeEach(func() {
   798  					fakeCloudControllerClient.GetServicePlansReturns(
   799  						[]resources.ServicePlan{},
   800  						ccv3.Warnings([]string{"warning-failure-1", "warning-failure-2"}),
   801  						errors.New("get-service-plan-error"),
   802  					)
   803  				})
   804  
   805  				It("returns the error and all warnings", func() {
   806  					Expect(warnings).To(ConsistOf("warning-failure-1", "warning-failure-2"))
   807  					Expect(executeErr).To(MatchError("get-service-plan-error"))
   808  				})
   809  			})
   810  
   811  			When("updating the service plan fails", func() {
   812  				BeforeEach(func() {
   813  					fakeCloudControllerClient.GetServicePlansReturns(
   814  						[]resources.ServicePlan{{GUID: "some-guid"}},
   815  						[]string{"warning-1", "warning-2"},
   816  						nil,
   817  					)
   818  					fakeCloudControllerClient.UpdateResourceMetadataReturns(
   819  						"",
   820  						ccv3.Warnings{"set-service-plan"},
   821  						errors.New("update-service-plan-error"),
   822  					)
   823  				})
   824  
   825  				It("returns the error and all warnings", func() {
   826  					Expect(warnings).To(ConsistOf("warning-1", "warning-2", "set-service-plan"))
   827  					Expect(executeErr).To(MatchError("update-service-plan-error"))
   828  				})
   829  			})
   830  		})
   831  	})
   832  
   833  	Describe("GetDomainLabels", func() {
   834  		JustBeforeEach(func() {
   835  			labels, warnings, executeErr = actor.GetDomainLabels(resourceName)
   836  		})
   837  
   838  		When("there are no client errors", func() {
   839  			BeforeEach(func() {
   840  				fakeCloudControllerClient.GetDomainsReturns(
   841  					[]Domain{Domain{GUID: "some-guid"}},
   842  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
   843  					nil,
   844  				)
   845  			})
   846  
   847  			It("gets the domain", func() {
   848  				Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1))
   849  				Expect(fakeCloudControllerClient.GetDomainsArgsForCall(0)).To(ConsistOf(
   850  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}},
   851  				))
   852  			})
   853  
   854  			When("there are no labels on a domain", func() {
   855  				It("returns an empty map", func() {
   856  					Expect(executeErr).NotTo(HaveOccurred())
   857  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   858  					Expect(labels).To(BeEmpty())
   859  				})
   860  			})
   861  
   862  			When("there are labels", func() {
   863  				var expectedLabels map[string]types.NullString
   864  
   865  				BeforeEach(func() {
   866  					expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")}
   867  					fakeCloudControllerClient.GetDomainsReturns(
   868  						[]Domain{Domain{
   869  							GUID: "some-guid",
   870  							Metadata: &Metadata{
   871  								Labels: expectedLabels,
   872  							}}},
   873  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   874  						nil,
   875  					)
   876  				})
   877  				It("returns the labels", func() {
   878  					Expect(executeErr).NotTo(HaveOccurred())
   879  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   880  					Expect(labels).To(Equal(expectedLabels))
   881  				})
   882  			})
   883  		})
   884  
   885  		When("there is a client error", func() {
   886  			BeforeEach(func() {
   887  				fakeCloudControllerClient.GetDomainsReturns(
   888  					[]Domain{Domain{GUID: "some-guid"}},
   889  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
   890  					errors.New("get-domains-error"),
   891  				)
   892  			})
   893  			When("GetDomainByName fails", func() {
   894  				It("returns the error and all warnings", func() {
   895  					Expect(executeErr).To(HaveOccurred())
   896  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   897  					Expect(executeErr).To(MatchError("get-domains-error"))
   898  				})
   899  			})
   900  		})
   901  	})
   902  
   903  	Describe("GetRouteLabels", func() {
   904  		JustBeforeEach(func() {
   905  			labels, warnings, executeErr = actor.GetRouteLabels("sub.example.com/my-route/path", spaceGUID)
   906  		})
   907  
   908  		When("there are no client errors", func() {
   909  			BeforeEach(func() {
   910  				fakeCloudControllerClient.GetDomainsReturns(
   911  					[]Domain{
   912  						{Name: "domain-name", GUID: "domain-guid"},
   913  					},
   914  					ccv3.Warnings{"get-domains-warning"},
   915  					nil,
   916  				)
   917  
   918  				fakeCloudControllerClient.GetRoutesReturns(
   919  					[]Route{
   920  						{GUID: "route-guid", SpaceGUID: "some-space-guid", DomainGUID: "domain-guid", Host: "hostname", URL: "hostname.domain-name", Path: "/the-path"},
   921  					},
   922  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
   923  					nil,
   924  				)
   925  			})
   926  
   927  			It("gets the route", func() {
   928  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   929  				Expect(fakeCloudControllerClient.GetRoutesArgsForCall(0)).To(ConsistOf(
   930  					ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{spaceGUID}},
   931  					ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{"domain-guid"}},
   932  					ccv3.Query{Key: ccv3.HostsFilter, Values: []string{""}},
   933  					ccv3.Query{Key: ccv3.PathsFilter, Values: []string{"/my-route/path"}},
   934  				))
   935  			})
   936  
   937  			When("there are no labels on a route", func() {
   938  				It("returns an empty map", func() {
   939  					Expect(executeErr).NotTo(HaveOccurred())
   940  					Expect(warnings).To(ConsistOf("get-domains-warning", "warning-1", "warning-2"))
   941  					Expect(labels).To(BeEmpty())
   942  				})
   943  			})
   944  
   945  			When("there are labels", func() {
   946  				var expectedLabels map[string]types.NullString
   947  
   948  				BeforeEach(func() {
   949  					expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")}
   950  					fakeCloudControllerClient.GetRoutesReturns(
   951  						[]Route{
   952  							{
   953  								GUID: "some-guid",
   954  								Metadata: &Metadata{
   955  									Labels: expectedLabels,
   956  								},
   957  							},
   958  						},
   959  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
   960  						nil,
   961  					)
   962  				})
   963  				It("returns the labels", func() {
   964  					Expect(executeErr).NotTo(HaveOccurred())
   965  					Expect(warnings).To(ConsistOf("get-domains-warning", "warning-1", "warning-2"))
   966  					Expect(labels).To(Equal(expectedLabels))
   967  				})
   968  			})
   969  		})
   970  
   971  		When("there is a client error", func() {
   972  			BeforeEach(func() {
   973  				fakeCloudControllerClient.GetDomainsReturns(
   974  					[]Domain{
   975  						{Name: "domain-name", GUID: "domain-guid"},
   976  					},
   977  					ccv3.Warnings{"get-domains-warning"},
   978  					nil,
   979  				)
   980  
   981  				fakeCloudControllerClient.GetRoutesReturns(
   982  					[]Route{Route{GUID: "some-guid"}},
   983  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
   984  					errors.New("get-routes-error"),
   985  				)
   986  			})
   987  
   988  			It("returns the error and all warnings", func() {
   989  				Expect(executeErr).To(HaveOccurred())
   990  				Expect(warnings).To(ConsistOf("get-domains-warning", "warning-1", "warning-2"))
   991  				Expect(executeErr).To(MatchError("get-routes-error"))
   992  			})
   993  		})
   994  	})
   995  
   996  	Describe("GetStackLabels", func() {
   997  		JustBeforeEach(func() {
   998  			labels, warnings, executeErr = actor.GetStackLabels(resourceName)
   999  		})
  1000  
  1001  		When("there are no client errors", func() {
  1002  			BeforeEach(func() {
  1003  				fakeCloudControllerClient.GetStacksReturns(
  1004  					[]ccv3.Stack{ccv3.Stack{GUID: "some-guid"}},
  1005  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
  1006  					nil,
  1007  				)
  1008  			})
  1009  
  1010  			It("gets the stack", func() {
  1011  				Expect(fakeCloudControllerClient.GetStacksCallCount()).To(Equal(1))
  1012  				Expect(fakeCloudControllerClient.GetStacksArgsForCall(0)).To(ConsistOf(
  1013  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}},
  1014  				))
  1015  			})
  1016  
  1017  			When("there are no labels on a stack", func() {
  1018  				It("returns an empty map", func() {
  1019  					Expect(executeErr).NotTo(HaveOccurred())
  1020  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1021  					Expect(labels).To(BeEmpty())
  1022  				})
  1023  			})
  1024  
  1025  			When("there are labels", func() {
  1026  				var expectedLabels map[string]types.NullString
  1027  
  1028  				BeforeEach(func() {
  1029  					expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")}
  1030  					fakeCloudControllerClient.GetStacksReturns(
  1031  						[]ccv3.Stack{ccv3.Stack{
  1032  							GUID: "some-guid",
  1033  							Metadata: &Metadata{
  1034  								Labels: expectedLabels,
  1035  							}}},
  1036  						ccv3.Warnings([]string{"warning-1", "warning-2"}),
  1037  						nil,
  1038  					)
  1039  				})
  1040  				It("returns the labels", func() {
  1041  					Expect(executeErr).NotTo(HaveOccurred())
  1042  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1043  					Expect(labels).To(Equal(expectedLabels))
  1044  				})
  1045  			})
  1046  		})
  1047  
  1048  		When("there is a client error", func() {
  1049  			BeforeEach(func() {
  1050  				fakeCloudControllerClient.GetStacksReturns(
  1051  					[]ccv3.Stack{ccv3.Stack{GUID: "some-guid"}},
  1052  					ccv3.Warnings([]string{"warning-1", "warning-2"}),
  1053  					errors.New("get-stacks-error"),
  1054  				)
  1055  			})
  1056  			When("GetStackByName fails", func() {
  1057  				It("returns the error and all warnings", func() {
  1058  					Expect(executeErr).To(HaveOccurred())
  1059  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1060  					Expect(executeErr).To(MatchError("get-stacks-error"))
  1061  				})
  1062  			})
  1063  		})
  1064  	})
  1065  
  1066  	Describe("GetServiceBrokerLabels", func() {
  1067  		When("service broker does not exist", func() {
  1068  			BeforeEach(func() {
  1069  				fakeCloudControllerClient.GetServiceBrokersReturns(
  1070  					[]resources.ServiceBroker{},
  1071  					[]string{"warning-1", "warning-2"},
  1072  					nil,
  1073  				)
  1074  			})
  1075  
  1076  			JustBeforeEach(func() {
  1077  				labels, warnings, executeErr = actor.GetServiceBrokerLabels(resourceName)
  1078  			})
  1079  
  1080  			It("returns a service broker not found error and warnings", func() {
  1081  				Expect(executeErr).To(HaveOccurred())
  1082  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1083  				Expect(executeErr.Error()).To(ContainSubstring("Service broker 'some-resource' not found"))
  1084  			})
  1085  		})
  1086  
  1087  		When("client returns an error", func() {
  1088  			BeforeEach(func() {
  1089  				fakeCloudControllerClient.GetServiceBrokersReturns(
  1090  					[]resources.ServiceBroker{},
  1091  					[]string{"warning"},
  1092  					errors.New("some random error"),
  1093  				)
  1094  			})
  1095  
  1096  			JustBeforeEach(func() {
  1097  				labels, warnings, executeErr = actor.GetServiceBrokerLabels(resourceName)
  1098  			})
  1099  
  1100  			It("returns error and prints warnings", func() {
  1101  				Expect(executeErr).To(HaveOccurred())
  1102  				Expect(warnings).To(ConsistOf("warning"))
  1103  				Expect(executeErr).To(MatchError("some random error"))
  1104  			})
  1105  		})
  1106  		When("service broker has labels", func() {
  1107  			var expectedLabels map[string]types.NullString
  1108  
  1109  			BeforeEach(func() {
  1110  				expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")}
  1111  				fakeCloudControllerClient.GetServiceBrokersReturns(
  1112  					[]resources.ServiceBroker{resources.ServiceBroker{
  1113  						GUID: "some-guid",
  1114  						Name: resourceName,
  1115  						Metadata: &Metadata{
  1116  							Labels: expectedLabels,
  1117  						}}},
  1118  					[]string{"warning-1", "warning-2"},
  1119  					nil,
  1120  				)
  1121  			})
  1122  
  1123  			JustBeforeEach(func() {
  1124  				labels, warnings, executeErr = actor.GetServiceBrokerLabels(resourceName)
  1125  			})
  1126  
  1127  			It("returns labels associated with the service broker as well as warnings", func() {
  1128  				Expect(executeErr).ToNot(HaveOccurred())
  1129  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1130  				Expect(labels).To(Equal(expectedLabels))
  1131  			})
  1132  		})
  1133  
  1134  	})
  1135  
  1136  	Describe("GetServiceOfferingLabels", func() {
  1137  		const serviceBrokerName = "my-service-broker"
  1138  
  1139  		When("service offering does not exist", func() {
  1140  			BeforeEach(func() {
  1141  				fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(
  1142  					resources.ServiceOffering{},
  1143  					[]string{"warning-1", "warning-2"},
  1144  					ccerror.ServiceOfferingNotFoundError{
  1145  						ServiceOfferingName: resourceName,
  1146  						ServiceBrokerName:   serviceBrokerName,
  1147  					},
  1148  				)
  1149  			})
  1150  
  1151  			JustBeforeEach(func() {
  1152  				labels, warnings, executeErr = actor.GetServiceOfferingLabels(resourceName, serviceBrokerName)
  1153  			})
  1154  
  1155  			It("returns a service offering not found error and warnings", func() {
  1156  				Expect(executeErr).To(HaveOccurred())
  1157  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1158  				Expect(executeErr.Error()).To(ContainSubstring("Service offering '%s' for service broker '%s' not found", resourceName, serviceBrokerName))
  1159  			})
  1160  		})
  1161  
  1162  		When("client returns an error", func() {
  1163  			BeforeEach(func() {
  1164  				fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(
  1165  					resources.ServiceOffering{},
  1166  					[]string{"warning"},
  1167  					errors.New("some random error"),
  1168  				)
  1169  			})
  1170  
  1171  			JustBeforeEach(func() {
  1172  				labels, warnings, executeErr = actor.GetServiceOfferingLabels(resourceName, serviceBrokerName)
  1173  			})
  1174  
  1175  			It("returns error and prints warnings", func() {
  1176  				Expect(executeErr).To(HaveOccurred())
  1177  				Expect(warnings).To(ConsistOf("warning"))
  1178  				Expect(executeErr).To(MatchError("some random error"))
  1179  			})
  1180  		})
  1181  
  1182  		When("service offering has labels", func() {
  1183  			var expectedLabels map[string]types.NullString
  1184  
  1185  			BeforeEach(func() {
  1186  				expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")}
  1187  				fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(
  1188  					resources.ServiceOffering{
  1189  						GUID: "some-guid",
  1190  						Name: resourceName,
  1191  						Metadata: &Metadata{
  1192  							Labels: expectedLabels,
  1193  						},
  1194  					},
  1195  					[]string{"warning-1", "warning-2"},
  1196  					nil,
  1197  				)
  1198  			})
  1199  
  1200  			JustBeforeEach(func() {
  1201  				labels, warnings, executeErr = actor.GetServiceOfferingLabels(resourceName, serviceBrokerName)
  1202  			})
  1203  
  1204  			It("queries the right names", func() {
  1205  				Expect(fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerCallCount()).To(Equal(1))
  1206  				requestedServiceOffering, requestedServiceBroker := fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerArgsForCall(0)
  1207  				Expect(requestedServiceOffering).To(Equal(resourceName))
  1208  				Expect(requestedServiceBroker).To(Equal(serviceBrokerName))
  1209  			})
  1210  
  1211  			It("returns labels associated with the service offering as well as warnings", func() {
  1212  				Expect(executeErr).ToNot(HaveOccurred())
  1213  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1214  				Expect(labels).To(Equal(expectedLabels))
  1215  			})
  1216  		})
  1217  	})
  1218  
  1219  	Describe("GetServicePlanLabels", func() {
  1220  		When("service plan does not exist", func() {
  1221  			BeforeEach(func() {
  1222  				fakeCloudControllerClient.GetServicePlansReturns(
  1223  					[]resources.ServicePlan{},
  1224  					[]string{"warning-1", "warning-2"},
  1225  					nil,
  1226  				)
  1227  			})
  1228  
  1229  			JustBeforeEach(func() {
  1230  				labels, warnings, executeErr = actor.GetServicePlanLabels(resourceName, "", "")
  1231  			})
  1232  
  1233  			It("returns a service plan not found error and warnings", func() {
  1234  				Expect(executeErr).To(HaveOccurred())
  1235  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1236  				Expect(executeErr.Error()).To(ContainSubstring("Service plan '%s' not found", resourceName))
  1237  			})
  1238  		})
  1239  
  1240  		When("client returns an error", func() {
  1241  			BeforeEach(func() {
  1242  				fakeCloudControllerClient.GetServicePlansReturns(
  1243  					[]resources.ServicePlan{},
  1244  					[]string{"warning"},
  1245  					errors.New("some random error"),
  1246  				)
  1247  			})
  1248  
  1249  			JustBeforeEach(func() {
  1250  				labels, warnings, executeErr = actor.GetServicePlanLabels(resourceName, "", "")
  1251  			})
  1252  
  1253  			It("returns error and prints warnings", func() {
  1254  				Expect(executeErr).To(HaveOccurred())
  1255  				Expect(warnings).To(ConsistOf("warning"))
  1256  				Expect(executeErr).To(MatchError("some random error"))
  1257  			})
  1258  		})
  1259  
  1260  		When("service plan has labels", func() {
  1261  			var expectedLabels map[string]types.NullString
  1262  
  1263  			BeforeEach(func() {
  1264  				expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")}
  1265  				fakeCloudControllerClient.GetServicePlansReturns(
  1266  					[]resources.ServicePlan{{
  1267  						GUID: "some-guid",
  1268  						Name: resourceName,
  1269  						Metadata: &Metadata{
  1270  							Labels: expectedLabels,
  1271  						}}},
  1272  					[]string{"warning-1", "warning-2"},
  1273  					nil,
  1274  				)
  1275  			})
  1276  
  1277  			JustBeforeEach(func() {
  1278  				labels, warnings, executeErr = actor.GetServicePlanLabels(resourceName, "serviceOfferingName", "serviceBrokerName")
  1279  			})
  1280  
  1281  			It("queries the right names", func() {
  1282  				Expect(fakeCloudControllerClient.GetServicePlansCallCount()).To(Equal(1))
  1283  				Expect(fakeCloudControllerClient.GetServicePlansArgsForCall(0)).To(ConsistOf(
  1284  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{resourceName}},
  1285  					ccv3.Query{Key: ccv3.ServiceOfferingNamesFilter, Values: []string{"serviceOfferingName"}},
  1286  					ccv3.Query{Key: ccv3.ServiceBrokerNamesFilter, Values: []string{"serviceBrokerName"}},
  1287  				))
  1288  			})
  1289  
  1290  			It("returns labels associated with the service plan as well as warnings", func() {
  1291  				Expect(executeErr).ToNot(HaveOccurred())
  1292  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
  1293  				Expect(labels).To(Equal(expectedLabels))
  1294  			})
  1295  		})
  1296  	})
  1297  })