github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/label_updater_test.go (about)

     1  package v7_test
     2  
     3  import (
     4  	"errors"
     5  	"regexp"
     6  	"strings"
     7  
     8  	"github.com/LukasHeimann/cloudfoundrycli/v8/actor/v7action"
     9  	"github.com/LukasHeimann/cloudfoundrycli/v8/command/commandfakes"
    10  	"github.com/LukasHeimann/cloudfoundrycli/v8/command/translatableerror"
    11  	. "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7"
    12  	"github.com/LukasHeimann/cloudfoundrycli/v8/command/v7/v7fakes"
    13  	"github.com/LukasHeimann/cloudfoundrycli/v8/types"
    14  	"github.com/LukasHeimann/cloudfoundrycli/v8/util/configv3"
    15  	"github.com/LukasHeimann/cloudfoundrycli/v8/util/ui"
    16  	. "github.com/onsi/ginkgo"
    17  	. "github.com/onsi/ginkgo/extensions/table"
    18  	. "github.com/onsi/gomega"
    19  	. "github.com/onsi/gomega/gbytes"
    20  )
    21  
    22  func labelSubcommands(subcommandsToRemove ...string) []TableEntry {
    23  	all := []string{
    24  		"app",
    25  		"buildpack",
    26  		"domain",
    27  		"org",
    28  		"route",
    29  		"space",
    30  		"stack",
    31  		"service-broker",
    32  		"service-instance",
    33  		"service-offering",
    34  		"service-plan",
    35  	}
    36  	var entries []TableEntry
    37  	for _, labelSubcommand := range all {
    38  		remove := false
    39  		for _, subCommand := range subcommandsToRemove {
    40  			if labelSubcommand == subCommand {
    41  				remove = true
    42  				break
    43  			}
    44  		}
    45  		if !remove {
    46  			entries = append(entries, Entry(labelSubcommand, labelSubcommand))
    47  		}
    48  	}
    49  	return entries
    50  }
    51  
    52  var _ = Describe("LabelUpdater", func() {
    53  	var (
    54  		cmd             LabelUpdater
    55  		fakeActor       *v7fakes.FakeActor
    56  		fakeConfig      *commandfakes.FakeConfig
    57  		fakeSharedActor *commandfakes.FakeSharedActor
    58  		testUI          *ui.UI
    59  		targetResource  TargetResource
    60  		labels          map[string]types.NullString
    61  	)
    62  
    63  	BeforeEach(func() {
    64  		testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
    65  		fakeConfig = new(commandfakes.FakeConfig)
    66  		fakeSharedActor = new(commandfakes.FakeSharedActor)
    67  		fakeActor = new(v7fakes.FakeActor)
    68  		cmd = LabelUpdater{
    69  			UI:          testUI,
    70  			Config:      fakeConfig,
    71  			SharedActor: fakeSharedActor,
    72  			Actor:       fakeActor,
    73  		}
    74  	})
    75  
    76  	Context("shared validations", func() {
    77  		var resourceName string
    78  
    79  		BeforeEach(func() {
    80  			testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
    81  			fakeActor = new(v7fakes.FakeActor)
    82  			fakeConfig = new(commandfakes.FakeConfig)
    83  			fakeSharedActor = new(commandfakes.FakeSharedActor)
    84  			cmd = LabelUpdater{
    85  				Actor:       fakeActor,
    86  				UI:          testUI,
    87  				Config:      fakeConfig,
    88  				SharedActor: fakeSharedActor,
    89  			}
    90  		})
    91  
    92  		When("fetching the current user's name fails", func() {
    93  			BeforeEach(func() {
    94  				targetResource = TargetResource{
    95  					ResourceType: "anything",
    96  					ResourceName: resourceName,
    97  				}
    98  				fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, errors.New("boom"))
    99  			})
   100  
   101  			It("returns an error", func() {
   102  				err := cmd.Execute(targetResource, labels)
   103  				Expect(err).To(MatchError("boom"))
   104  			})
   105  		})
   106  
   107  		When("an unrecognized resource type is specified", func() {
   108  			BeforeEach(func() {
   109  				resourceName = "some-unrecognized-resource"
   110  				cmd = LabelUpdater{
   111  					Actor:       fakeActor,
   112  					UI:          testUI,
   113  					Config:      fakeConfig,
   114  					SharedActor: fakeSharedActor,
   115  				}
   116  				targetResource = TargetResource{
   117  					ResourceType: "unrecognized-resource",
   118  					ResourceName: resourceName,
   119  				}
   120  			})
   121  
   122  			It("errors", func() {
   123  				executeErr := cmd.Execute(targetResource, labels)
   124  
   125  				Expect(executeErr).To(MatchError("Unsupported resource type of 'unrecognized-resource'"))
   126  			})
   127  		})
   128  
   129  		DescribeTable(
   130  			"Failure when --stack is combined with anything other than 'buildpack'",
   131  			func(resourceType string) {
   132  				targetResource = TargetResource{
   133  					ResourceType:   resourceType,
   134  					BuildpackStack: "cflinuxfs3",
   135  				}
   136  
   137  				err := cmd.Execute(targetResource, nil)
   138  
   139  				argumentCombinationError := translatableerror.ArgumentCombinationError{
   140  					Args: []string{strings.ToLower(resourceType), "--stack, -s"},
   141  				}
   142  				Expect(err).To(MatchError(argumentCombinationError))
   143  			},
   144  			labelSubcommands("buildpack")...,
   145  		)
   146  
   147  		DescribeTable(
   148  			"Failure when --broker is combined with anything other than 'service-offering' or 'service-plan'",
   149  			func(resourceType string) {
   150  				targetResource = TargetResource{
   151  					ResourceType:  resourceType,
   152  					ServiceBroker: "my-broker",
   153  				}
   154  
   155  				err := cmd.Execute(targetResource, nil)
   156  
   157  				argumentCombinationError := translatableerror.ArgumentCombinationError{
   158  					Args: []string{strings.ToLower(resourceType), "--broker, -b"},
   159  				}
   160  				Expect(err).To(MatchError(argumentCombinationError))
   161  			},
   162  			labelSubcommands("service-offering", "service-plan")...,
   163  		)
   164  
   165  		DescribeTable(
   166  			"Failure when --offering is combined with anything other than 'service-plan'",
   167  			func(resourceType string) {
   168  				targetResource = TargetResource{
   169  					ResourceType:    resourceType,
   170  					ServiceOffering: "my-service-offering",
   171  				}
   172  
   173  				err := cmd.Execute(targetResource, nil)
   174  
   175  				argumentCombinationError := translatableerror.ArgumentCombinationError{
   176  					Args: []string{strings.ToLower(resourceType), "--offering, -o"},
   177  				}
   178  				Expect(err).To(MatchError(argumentCombinationError))
   179  			},
   180  			labelSubcommands("service-plan")...,
   181  		)
   182  
   183  		DescribeTable(
   184  			"when checking the target fails",
   185  			func(resourceType string) {
   186  				fakeSharedActor.CheckTargetReturns(errors.New("Target not found"))
   187  				targetResource = TargetResource{
   188  					ResourceType: resourceType,
   189  				}
   190  
   191  				err := cmd.Execute(targetResource, nil)
   192  				Expect(err).To(MatchError("Target not found"))
   193  			},
   194  			labelSubcommands()...,
   195  		)
   196  
   197  		DescribeTable(
   198  			"checking that the user is logged in",
   199  			func(resourceType string) {
   200  				targetResource = TargetResource{
   201  					ResourceType: resourceType,
   202  				}
   203  				err := cmd.Execute(targetResource, nil)
   204  
   205  				Expect(err).NotTo(HaveOccurred())
   206  				Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1))
   207  				checkOrg, checkSpace := fakeSharedActor.CheckTargetArgsForCall(0)
   208  
   209  				switch resourceType {
   210  				case "app", "route", "service-instance":
   211  					Expect(checkOrg).To(BeTrue())
   212  					Expect(checkSpace).To(BeTrue())
   213  				case "space":
   214  					Expect(checkOrg).To(BeTrue())
   215  					Expect(checkSpace).To(BeFalse())
   216  				default:
   217  					Expect(checkOrg).To(BeFalse())
   218  					Expect(checkSpace).To(BeFalse())
   219  				}
   220  			},
   221  			labelSubcommands()...,
   222  		)
   223  	})
   224  
   225  	When("updating labels on apps", func() {
   226  		var (
   227  			appName     string
   228  			executeErr  error
   229  			expectedMap map[string]types.NullString
   230  		)
   231  
   232  		BeforeEach(func() {
   233  			appName = "some-app"
   234  			targetResource = TargetResource{
   235  				ResourceType: "app",
   236  				ResourceName: appName,
   237  			}
   238  
   239  			fakeConfig.TargetedOrganizationReturns(configv3.Organization{Name: "fake-org"})
   240  			fakeConfig.TargetedSpaceReturns(configv3.Space{Name: "fake-space", GUID: "some-space-guid"})
   241  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
   242  
   243  			expectedMap = map[string]types.NullString{
   244  				"some-label":     types.NewNullString("some-value"),
   245  				"some-other-key": types.NewNullString(),
   246  			}
   247  			labels = expectedMap
   248  		})
   249  
   250  		JustBeforeEach(func() {
   251  			executeErr = cmd.Execute(targetResource, labels)
   252  		})
   253  
   254  		When("updating the app labels succeeds", func() {
   255  			BeforeEach(func() {
   256  				fakeActor.UpdateApplicationLabelsByApplicationNameReturns(v7action.Warnings{"some-warning-1", "some-warning-2"}, nil)
   257  			})
   258  
   259  			It("prints all warnings and does not return an error ", func() {
   260  				Expect(executeErr).ToNot(HaveOccurred())
   261  				Expect(testUI.Err).To(Say("some-warning-1"))
   262  				Expect(testUI.Err).To(Say("some-warning-2"))
   263  			})
   264  
   265  			It("passes the correct parameters into the actor", func() {
   266  				Expect(fakeActor.UpdateApplicationLabelsByApplicationNameCallCount()).To(Equal(1))
   267  				actualAppName, spaceGUID, labelsMap := fakeActor.UpdateApplicationLabelsByApplicationNameArgsForCall(0)
   268  				Expect(actualAppName).To(Equal(appName))
   269  				Expect(spaceGUID).To(Equal("some-space-guid"))
   270  				Expect(labelsMap).To(Equal(expectedMap))
   271  			})
   272  		})
   273  
   274  		When("the resource type argument is not lowercase", func() {
   275  			BeforeEach(func() {
   276  				targetResource.ResourceType = "aPp"
   277  			})
   278  
   279  			It("calls the right actor", func() {
   280  				Expect(executeErr).ToNot(HaveOccurred())
   281  				Expect(fakeActor.UpdateApplicationLabelsByApplicationNameCallCount()).To(Equal(1))
   282  			})
   283  
   284  			It("displays a message in the right case", func() {
   285  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for app (.*)"))
   286  				Expect(testUI.Out).To(Say("OK"))
   287  			})
   288  		})
   289  
   290  		When("updating the app labels fails", func() {
   291  			BeforeEach(func() {
   292  				fakeActor.UpdateApplicationLabelsByApplicationNameReturns(v7action.Warnings{"some-warning-1", "some-warning-2"},
   293  					errors.New("api call failed"))
   294  			})
   295  
   296  			It("prints all warnings", func() {
   297  				Expect(testUI.Err).To(Say("some-warning-1"))
   298  				Expect(testUI.Err).To(Say("some-warning-2"))
   299  			})
   300  
   301  			It("returns the error", func() {
   302  				Expect(executeErr).To(MatchError("api call failed"))
   303  			})
   304  		})
   305  
   306  		Context("shows the right update message with org and space", func() {
   307  			When("Unsetting labels", func() {
   308  				BeforeEach(func() {
   309  					cmd.Action = Unset
   310  					// FIXME do we want to change the labels to all have nil values?
   311  				})
   312  				It("shows 'Removing' as action", func() {
   313  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for app %s in org fake-org / space fake-space as some-user...`), appName))
   314  				})
   315  			})
   316  
   317  			When("Setting labels", func() {
   318  				BeforeEach(func() {
   319  					cmd.Action = Set
   320  					// FIXME do we want to change the labels to all have not nil values?
   321  				})
   322  
   323  				It("shows 'Setting' as action", func() {
   324  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for app %s in org fake-org / space fake-space as some-user...`), appName))
   325  				})
   326  			})
   327  		})
   328  	})
   329  
   330  	When("updating labels on buildpacks", func() {
   331  		var resourceName string
   332  		var expectedMap map[string]types.NullString
   333  		var executeErr error
   334  
   335  		BeforeEach(func() {
   336  			resourceName = "buildpack-name"
   337  			targetResource = TargetResource{
   338  				ResourceType: "buildpack",
   339  				ResourceName: resourceName,
   340  			}
   341  
   342  			fakeSharedActor.CheckTargetReturns(nil)
   343  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
   344  
   345  			expectedMap = map[string]types.NullString{
   346  				"some-label":     types.NewNullString("some-value"),
   347  				"some-other-key": types.NewNullString(),
   348  			}
   349  			labels = expectedMap
   350  
   351  			fakeActor.UpdateBuildpackLabelsByBuildpackNameAndStackReturns(
   352  				v7action.Warnings([]string{"some-warning-1", "some-warning-2"}),
   353  				nil,
   354  			)
   355  		})
   356  
   357  		JustBeforeEach(func() {
   358  			executeErr = cmd.Execute(targetResource, labels)
   359  		})
   360  
   361  		When("updating the buildpack labels succeeds", func() {
   362  			When("the stack is specified", func() {
   363  				BeforeEach(func() {
   364  					targetResource.BuildpackStack = "globinski"
   365  				})
   366  
   367  				It("passes the right parameters", func() {
   368  					Expect(fakeActor.UpdateBuildpackLabelsByBuildpackNameAndStackCallCount()).To(Equal(1))
   369  					name, stack, labels := fakeActor.UpdateBuildpackLabelsByBuildpackNameAndStackArgsForCall(0)
   370  					Expect(name).To(Equal(resourceName), "failed to pass buildpack name")
   371  					Expect(stack).To(Equal("globinski"), "failed to pass stack name")
   372  					Expect(labels).To(BeEquivalentTo(expectedMap))
   373  				})
   374  
   375  				It("prints all warnings and does not error ", func() {
   376  					Expect(executeErr).ToNot(HaveOccurred())
   377  					Expect(testUI.Err).To(Say("some-warning-1"))
   378  					Expect(testUI.Err).To(Say("some-warning-2"))
   379  				})
   380  			})
   381  
   382  			When("the stack is not specified", func() {
   383  				It("passes the right parameters", func() {
   384  					Expect(fakeActor.UpdateBuildpackLabelsByBuildpackNameAndStackCallCount()).To(Equal(1))
   385  					name, stack, labels := fakeActor.UpdateBuildpackLabelsByBuildpackNameAndStackArgsForCall(0)
   386  					Expect(name).To(Equal(resourceName), "failed to pass buildpack name")
   387  					Expect(stack).To(Equal(""), "failed to pass stack name")
   388  					Expect(labels).To(BeEquivalentTo(expectedMap))
   389  				})
   390  
   391  				It("prints all warnings and does not error ", func() {
   392  					Expect(executeErr).ToNot(HaveOccurred())
   393  					Expect(testUI.Err).To(Say("some-warning-1"))
   394  					Expect(testUI.Err).To(Say("some-warning-2"))
   395  				})
   396  			})
   397  		})
   398  
   399  		When("the resource type is not lowercase", func() {
   400  			BeforeEach(func() {
   401  				targetResource = TargetResource{
   402  					ResourceType:   "bUiLdPaCk",
   403  					ResourceName:   resourceName,
   404  					BuildpackStack: "globinski",
   405  				}
   406  				expectedMap = map[string]types.NullString{
   407  					"some-label":     types.NewNullString("some-value"),
   408  					"some-other-key": types.NewNullString(),
   409  				}
   410  			})
   411  
   412  			It("calls the right actor", func() {
   413  				Expect(executeErr).ToNot(HaveOccurred())
   414  				Expect(fakeActor.UpdateBuildpackLabelsByBuildpackNameAndStackCallCount()).To(Equal(1))
   415  			})
   416  
   417  			It("displays a message in the right case", func() {
   418  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for buildpack (.*)"))
   419  				Expect(testUI.Out).To(Say("OK"))
   420  			})
   421  		})
   422  
   423  		When("updating the buildpack labels fails", func() {
   424  			BeforeEach(func() {
   425  				fakeActor.UpdateBuildpackLabelsByBuildpackNameAndStackReturns(v7action.Warnings{"some-warning-1", "some-warning-2"},
   426  					errors.New("api call failed"))
   427  			})
   428  
   429  			It("returns the error and prints all warnings", func() {
   430  				Expect(executeErr).To(MatchError("api call failed"))
   431  				Expect(testUI.Err).To(Say("some-warning-1"))
   432  				Expect(testUI.Err).To(Say("some-warning-2"))
   433  			})
   434  		})
   435  
   436  		Context("shows the right update message with correct stack and action", func() {
   437  			When("Unsetting labels", func() {
   438  				BeforeEach(func() {
   439  					cmd.Action = Unset
   440  				})
   441  
   442  				When("stack is passed", func() {
   443  					BeforeEach(func() {
   444  						targetResource.BuildpackStack = "globinski"
   445  					})
   446  					It("shows 'Removing' as action", func() {
   447  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for buildpack %s with stack %s as some-user...`), resourceName, targetResource.BuildpackStack))
   448  					})
   449  				})
   450  
   451  				When("stack is not passed", func() {
   452  					It("shows 'Removing' as action", func() {
   453  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for buildpack %s as some-user...`), resourceName))
   454  					})
   455  				})
   456  			})
   457  
   458  			When("Setting labels", func() {
   459  				BeforeEach(func() {
   460  					cmd.Action = Set
   461  					// FIXME do we want to change the labels to all have not nil values?
   462  				})
   463  
   464  				When("stack is passed", func() {
   465  					BeforeEach(func() {
   466  						targetResource.BuildpackStack = "globinski"
   467  					})
   468  					It("shows 'Setting' as action", func() {
   469  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for buildpack %s with stack %s as some-user...`), resourceName, targetResource.BuildpackStack))
   470  					})
   471  				})
   472  
   473  				When("stack is not passed", func() {
   474  					It("shows 'Setting' as action", func() {
   475  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for buildpack %s as some-user...`), resourceName))
   476  					})
   477  				})
   478  			})
   479  		})
   480  	})
   481  
   482  	When("updating labels in domains", func() {
   483  		var (
   484  			domainName  string
   485  			executeErr  error
   486  			expectedMap map[string]types.NullString
   487  		)
   488  
   489  		BeforeEach(func() {
   490  			domainName = "example.com"
   491  			targetResource = TargetResource{
   492  				ResourceType: "domain",
   493  				ResourceName: domainName,
   494  			}
   495  			expectedMap = map[string]types.NullString{
   496  				"some-label":     types.NewNullString("some-value"),
   497  				"some-other-key": types.NewNullString(),
   498  			}
   499  			labels = expectedMap
   500  
   501  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
   502  			fakeActor.UpdateDomainLabelsByDomainNameReturns(
   503  				v7action.Warnings{"some-warning-1", "some-warning-2"},
   504  				nil,
   505  			)
   506  		})
   507  
   508  		JustBeforeEach(func() {
   509  			executeErr = cmd.Execute(targetResource, labels)
   510  		})
   511  
   512  		When("updating the labels succeeds", func() {
   513  			It("prints all warnings and does not return an error ", func() {
   514  				Expect(executeErr).ToNot(HaveOccurred())
   515  				Expect(testUI.Err).To(Say("some-warning-1"))
   516  				Expect(testUI.Err).To(Say("some-warning-2"))
   517  			})
   518  
   519  			It("passes the correct parameters into the actor", func() {
   520  				Expect(fakeActor.UpdateDomainLabelsByDomainNameCallCount()).To(Equal(1))
   521  				name, labels := fakeActor.UpdateDomainLabelsByDomainNameArgsForCall(0)
   522  				Expect(name).To(Equal(domainName), "failed to pass domain name")
   523  				Expect(labels).To(BeEquivalentTo(expectedMap))
   524  			})
   525  		})
   526  
   527  		When("the resource type argument is not lowercase", func() {
   528  			BeforeEach(func() {
   529  				targetResource.ResourceType = "DoMaiN"
   530  			})
   531  
   532  			It("calls the right actor", func() {
   533  				Expect(executeErr).ToNot(HaveOccurred())
   534  				Expect(fakeActor.UpdateDomainLabelsByDomainNameCallCount()).To(Equal(1))
   535  			})
   536  
   537  			It("displays a message in the right case", func() {
   538  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for domain (.*)"))
   539  				Expect(testUI.Out).To(Say("OK"))
   540  			})
   541  		})
   542  
   543  		When("updating the domain labels fails", func() {
   544  			BeforeEach(func() {
   545  				fakeActor.UpdateDomainLabelsByDomainNameReturns(
   546  					v7action.Warnings{"some-warning-1", "some-warning-2"},
   547  					errors.New("api call failed"))
   548  			})
   549  
   550  			It("returns the error and prints all warnings", func() {
   551  				Expect(executeErr).To(MatchError("api call failed"))
   552  				Expect(testUI.Err).To(Say("some-warning-1"))
   553  				Expect(testUI.Err).To(Say("some-warning-2"))
   554  			})
   555  		})
   556  
   557  		Context("shows the right update message", func() {
   558  			When("Unsetting labels", func() {
   559  				BeforeEach(func() {
   560  					cmd.Action = Unset
   561  				})
   562  
   563  				It("shows 'Removing' as action", func() {
   564  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for domain %s as some-user...`), domainName))
   565  				})
   566  			})
   567  
   568  			When("Setting labels", func() {
   569  				BeforeEach(func() {
   570  					cmd.Action = Set
   571  				})
   572  
   573  				It("shows 'Setting' as action", func() {
   574  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for domain %s as some-user...`), domainName))
   575  				})
   576  			})
   577  		})
   578  	})
   579  
   580  	When("updating labels on orgs", func() {
   581  		var (
   582  			executeErr  error
   583  			orgName     = "some-org"
   584  			expectedMap map[string]types.NullString
   585  		)
   586  
   587  		BeforeEach(func() {
   588  			targetResource = TargetResource{
   589  				ResourceType: "org",
   590  				ResourceName: orgName,
   591  			}
   592  			fakeSharedActor.CheckTargetReturns(nil)
   593  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
   594  
   595  			expectedMap = map[string]types.NullString{
   596  				"some-label":     types.NewNullString("some-value"),
   597  				"some-other-key": types.NewNullString(),
   598  			}
   599  			labels = expectedMap
   600  
   601  			fakeActor.UpdateOrganizationLabelsByOrganizationNameReturns(
   602  				v7action.Warnings{"some-warning-1", "some-warning-2"},
   603  				nil)
   604  		})
   605  
   606  		JustBeforeEach(func() {
   607  			executeErr = cmd.Execute(targetResource, labels)
   608  		})
   609  
   610  		When("updating the orgs labels succeeds", func() {
   611  			It("does not return an error and prints all warnings", func() {
   612  				Expect(executeErr).ToNot(HaveOccurred())
   613  				Expect(testUI.Err).To(Say("some-warning-1"))
   614  				Expect(testUI.Err).To(Say("some-warning-2"))
   615  			})
   616  
   617  			It("passes the correct parameters into the actor", func() {
   618  				Expect(fakeActor.UpdateOrganizationLabelsByOrganizationNameCallCount()).To(Equal(1))
   619  				actualOrgName, labelsMap := fakeActor.UpdateOrganizationLabelsByOrganizationNameArgsForCall(0)
   620  				Expect(actualOrgName).To(Equal(orgName))
   621  				Expect(labelsMap).To(Equal(expectedMap))
   622  			})
   623  		})
   624  
   625  		When("the resource type argument is not lowercase", func() {
   626  			BeforeEach(func() {
   627  				targetResource.ResourceType = "OrG"
   628  			})
   629  
   630  			It("calls the right actor", func() {
   631  				Expect(executeErr).ToNot(HaveOccurred())
   632  				Expect(fakeActor.UpdateOrganizationLabelsByOrganizationNameCallCount()).To(Equal(1))
   633  			})
   634  
   635  			It("displays a message in the right case", func() {
   636  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for org (.*)"))
   637  				Expect(testUI.Out).To(Say("OK"))
   638  			})
   639  		})
   640  
   641  		When("updating the org labels fails", func() {
   642  			BeforeEach(func() {
   643  				fakeActor.UpdateOrganizationLabelsByOrganizationNameReturns(
   644  					v7action.Warnings{"some-warning-1", "some-warning-2"},
   645  					errors.New("api call failed"))
   646  			})
   647  
   648  			It("returns the error and prints all warnings", func() {
   649  				Expect(executeErr).To(MatchError("api call failed"))
   650  				Expect(testUI.Err).To(Say("some-warning-1"))
   651  				Expect(testUI.Err).To(Say("some-warning-2"))
   652  			})
   653  		})
   654  
   655  		Context("shows the right update message", func() {
   656  			When("Unsetting labels", func() {
   657  				BeforeEach(func() {
   658  					cmd.Action = Unset
   659  				})
   660  
   661  				It("shows 'Removing' as action", func() {
   662  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for org %s as some-user...`), orgName))
   663  				})
   664  			})
   665  
   666  			When("Setting labels", func() {
   667  				BeforeEach(func() {
   668  					cmd.Action = Set
   669  				})
   670  
   671  				It("shows 'Setting' as action", func() {
   672  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for org %s as some-user...`), orgName))
   673  				})
   674  			})
   675  		})
   676  	})
   677  
   678  	When("updating labels on routes", func() {
   679  		var (
   680  			resourceName string
   681  			expectedMap  map[string]types.NullString
   682  			executeErr   error
   683  		)
   684  
   685  		BeforeEach(func() {
   686  			resourceName = "some-route.example.com"
   687  			targetResource = TargetResource{
   688  				ResourceType: "route",
   689  				ResourceName: resourceName,
   690  			}
   691  
   692  			expectedMap = map[string]types.NullString{
   693  				"some-label":     types.NewNullString("some-value"),
   694  				"some-other-key": types.NewNullString(),
   695  			}
   696  			labels = expectedMap
   697  
   698  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
   699  			fakeConfig.TargetedOrganizationReturns(configv3.Organization{Name: "fake-org"})
   700  			fakeConfig.TargetedSpaceReturns(configv3.Space{Name: "fake-space", GUID: "space-guid"})
   701  			fakeActor.UpdateRouteLabelsReturns(v7action.Warnings{"some-warning-1", "some-warning-2"},
   702  				nil)
   703  		})
   704  
   705  		JustBeforeEach(func() {
   706  			executeErr = cmd.Execute(targetResource, labels)
   707  		})
   708  
   709  		When("updating the route labels succeeds", func() {
   710  			It("doesn't error and prints all warnings", func() {
   711  				Expect(executeErr).ToNot(HaveOccurred())
   712  				Expect(testUI.Err).To(Say("some-warning-1"))
   713  				Expect(testUI.Err).To(Say("some-warning-2"))
   714  			})
   715  
   716  			It("passes the right parameters to the actor", func() {
   717  				Expect(fakeActor.UpdateRouteLabelsCallCount()).To(Equal(1))
   718  				name, spaceGUID, labels := fakeActor.UpdateRouteLabelsArgsForCall(0)
   719  				Expect(name).To(Equal(resourceName), "failed to pass route name")
   720  				Expect(labels).To(BeEquivalentTo(expectedMap))
   721  				Expect(spaceGUID).To(Equal("space-guid"))
   722  			})
   723  		})
   724  
   725  		When("the resource type argument is not lowercase", func() {
   726  			BeforeEach(func() {
   727  				targetResource.ResourceType = "rouTE"
   728  			})
   729  
   730  			It("calls the right actor", func() {
   731  				Expect(executeErr).ToNot(HaveOccurred())
   732  				Expect(fakeActor.UpdateRouteLabelsCallCount()).To(Equal(1))
   733  			})
   734  
   735  			It("displays a message in the right case", func() {
   736  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for route (.*)"))
   737  				Expect(testUI.Out).To(Say("OK"))
   738  			})
   739  		})
   740  
   741  		When("updating the route labels fails", func() {
   742  			BeforeEach(func() {
   743  				fakeActor.UpdateRouteLabelsReturns(v7action.Warnings{"some-warning-1", "some-warning-2"},
   744  					errors.New("api call failed"))
   745  			})
   746  
   747  			It("returns the error and prints all warnings", func() {
   748  				Expect(executeErr).To(MatchError("api call failed"))
   749  				Expect(testUI.Err).To(Say("some-warning-1"))
   750  				Expect(testUI.Err).To(Say("some-warning-2"))
   751  			})
   752  		})
   753  
   754  		Context("shows the right update message", func() {
   755  			When("Unsetting labels", func() {
   756  				BeforeEach(func() {
   757  					cmd.Action = Unset
   758  				})
   759  
   760  				It("shows 'Removing' as action", func() {
   761  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for route %s in org fake-org / space fake-space as some-user...`), resourceName))
   762  				})
   763  			})
   764  
   765  			When("Setting labels", func() {
   766  				BeforeEach(func() {
   767  					cmd.Action = Set
   768  				})
   769  
   770  				It("shows 'Setting' as action", func() {
   771  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for route %s in org fake-org / space fake-space as some-user...`), resourceName))
   772  				})
   773  			})
   774  		})
   775  	})
   776  
   777  	When("updating labels on service-broker", func() {
   778  		const expectedServiceBrokerName = "my-broker"
   779  		var (
   780  			expectedMap map[string]types.NullString
   781  			executeErr  error
   782  		)
   783  
   784  		BeforeEach(func() {
   785  			targetResource = TargetResource{
   786  				ResourceType: "service-broker",
   787  				ResourceName: expectedServiceBrokerName,
   788  			}
   789  
   790  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
   791  			expectedMap = map[string]types.NullString{
   792  				"some-label":     types.NewNullString("some-value"),
   793  				"some-other-key": types.NewNullString(),
   794  			}
   795  			labels = expectedMap
   796  		})
   797  
   798  		JustBeforeEach(func() {
   799  			executeErr = cmd.Execute(targetResource, labels)
   800  		})
   801  
   802  		When("updating the service-broker labels succeeds", func() {
   803  			BeforeEach(func() {
   804  				fakeActor.UpdateServiceBrokerLabelsByServiceBrokerNameReturns(v7action.Warnings{"some-warning-1", "some-warning-2"},
   805  					nil)
   806  			})
   807  
   808  			It("prints all warnings and does not return an error", func() {
   809  				Expect(executeErr).ToNot(HaveOccurred())
   810  				Expect(testUI.Err).To(Say("some-warning-1"))
   811  				Expect(testUI.Err).To(Say("some-warning-2"))
   812  			})
   813  
   814  			It("passes the correct parameters into the actor", func() {
   815  				Expect(fakeActor.UpdateServiceBrokerLabelsByServiceBrokerNameCallCount()).To(Equal(1))
   816  				serviceBrokerName, labelsMap := fakeActor.UpdateServiceBrokerLabelsByServiceBrokerNameArgsForCall(0)
   817  				Expect(serviceBrokerName).To(Equal(expectedServiceBrokerName))
   818  				Expect(labelsMap).To(Equal(expectedMap))
   819  			})
   820  		})
   821  
   822  		When("the resource type argument is not lowercase", func() {
   823  			BeforeEach(func() {
   824  				fakeActor.UpdateServiceBrokerLabelsByServiceBrokerNameReturns(v7action.Warnings{"some-warning-1", "some-warning-2"},
   825  					nil)
   826  
   827  				targetResource.ResourceType = "sErVice-BroKer"
   828  			})
   829  
   830  			It("calls the right actor", func() {
   831  				Expect(executeErr).ToNot(HaveOccurred())
   832  				Expect(fakeActor.UpdateServiceBrokerLabelsByServiceBrokerNameCallCount()).To(Equal(1))
   833  			})
   834  
   835  			It("displays a message in the right case", func() {
   836  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for service-broker (.*)"))
   837  				Expect(testUI.Out).To(Say("OK"))
   838  			})
   839  		})
   840  
   841  		When("updating the service-broker labels fails", func() {
   842  			BeforeEach(func() {
   843  				fakeActor.UpdateServiceBrokerLabelsByServiceBrokerNameReturns(v7action.Warnings{"some-warning-1", "some-warning-2"},
   844  					errors.New("api call failed"))
   845  			})
   846  
   847  			It("prints all warnings and returns the error", func() {
   848  				Expect(executeErr).To(MatchError("api call failed"))
   849  				Expect(testUI.Err).To(Say("some-warning-1"))
   850  				Expect(testUI.Err).To(Say("some-warning-2"))
   851  			})
   852  		})
   853  
   854  		Context("shows the right update message", func() {
   855  			When("Unsetting labels", func() {
   856  				BeforeEach(func() {
   857  					cmd.Action = Unset
   858  				})
   859  
   860  				It("shows 'Removing' as action", func() {
   861  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for service-broker %s as some-user...`), expectedServiceBrokerName))
   862  					Expect(testUI.Out).To(Say("OK"))
   863  				})
   864  			})
   865  
   866  			When("Setting labels", func() {
   867  				BeforeEach(func() {
   868  					cmd.Action = Set
   869  				})
   870  
   871  				It("shows 'Setting' as action", func() {
   872  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for service-broker %s as some-user...`), expectedServiceBrokerName))
   873  					Expect(testUI.Out).To(Say("OK"))
   874  				})
   875  			})
   876  		})
   877  	})
   878  
   879  	When("updating labels on service-instance", func() {
   880  		const serviceInstanceName = "some-service-instance"
   881  
   882  		var (
   883  			executeErr  error
   884  			expectedMap map[string]types.NullString
   885  		)
   886  
   887  		BeforeEach(func() {
   888  			targetResource = TargetResource{
   889  				ResourceType: "service-instance",
   890  				ResourceName: serviceInstanceName,
   891  			}
   892  
   893  			fakeConfig.TargetedOrganizationReturns(configv3.Organization{Name: "fake-org"})
   894  			fakeConfig.TargetedSpaceReturns(configv3.Space{Name: "fake-space", GUID: "some-space-guid"})
   895  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
   896  
   897  			expectedMap = map[string]types.NullString{
   898  				"some-label":     types.NewNullString("some-value"),
   899  				"some-other-key": types.NewNullString(),
   900  			}
   901  			labels = expectedMap
   902  		})
   903  
   904  		JustBeforeEach(func() {
   905  			executeErr = cmd.Execute(targetResource, labels)
   906  		})
   907  
   908  		When("updating the service instance labels succeeds", func() {
   909  			BeforeEach(func() {
   910  				fakeActor.UpdateServiceInstanceLabelsReturns(v7action.Warnings{"some-warning-1", "some-warning-2"}, nil)
   911  			})
   912  
   913  			It("prints all warnings and does not return an error ", func() {
   914  				Expect(executeErr).ToNot(HaveOccurred())
   915  				Expect(testUI.Err).To(Say("some-warning-1"))
   916  				Expect(testUI.Err).To(Say("some-warning-2"))
   917  			})
   918  
   919  			It("passes the correct parameters into the actor", func() {
   920  				Expect(fakeActor.UpdateServiceInstanceLabelsCallCount()).To(Equal(1))
   921  				actualServiceInstance, spaceGUID, labelsMap := fakeActor.UpdateServiceInstanceLabelsArgsForCall(0)
   922  				Expect(actualServiceInstance).To(Equal(serviceInstanceName))
   923  				Expect(spaceGUID).To(Equal("some-space-guid"))
   924  				Expect(labelsMap).To(Equal(expectedMap))
   925  			})
   926  		})
   927  
   928  		When("the resource type argument is not lowercase", func() {
   929  			BeforeEach(func() {
   930  				targetResource.ResourceType = "serViCE-iNSTance"
   931  			})
   932  
   933  			It("calls the right actor", func() {
   934  				Expect(executeErr).ToNot(HaveOccurred())
   935  				Expect(fakeActor.UpdateServiceInstanceLabelsCallCount()).To(Equal(1))
   936  			})
   937  
   938  			It("displays a message in the right case", func() {
   939  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for service-instance (.*)"))
   940  				Expect(testUI.Out).To(Say("OK"))
   941  			})
   942  		})
   943  
   944  		When("updating the labels fails", func() {
   945  			BeforeEach(func() {
   946  				fakeActor.UpdateServiceInstanceLabelsReturns(
   947  					v7action.Warnings{"some-warning-1", "some-warning-2"},
   948  					errors.New("api call failed"),
   949  				)
   950  			})
   951  
   952  			It("prints all warnings", func() {
   953  				Expect(testUI.Err).To(Say("some-warning-1"))
   954  				Expect(testUI.Err).To(Say("some-warning-2"))
   955  			})
   956  
   957  			It("returns the error", func() {
   958  				Expect(executeErr).To(MatchError("api call failed"))
   959  			})
   960  		})
   961  
   962  		Context("shows the right update message with org and space", func() {
   963  			When("Unsetting labels", func() {
   964  				BeforeEach(func() {
   965  					cmd.Action = Unset
   966  				})
   967  
   968  				It("shows 'Removing' as action", func() {
   969  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for service-instance %s in org fake-org / space fake-space as some-user...`), serviceInstanceName))
   970  				})
   971  			})
   972  
   973  			When("Setting labels", func() {
   974  				BeforeEach(func() {
   975  					cmd.Action = Set
   976  				})
   977  
   978  				It("shows 'Setting' as action", func() {
   979  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for service-instance %s in org fake-org / space fake-space as some-user...`), serviceInstanceName))
   980  				})
   981  			})
   982  		})
   983  	})
   984  
   985  	When("updating labels on service-offering", func() {
   986  		var executeErr error
   987  
   988  		const serviceBrokerName = "brokerName"
   989  		const serviceOfferingName = "serviceOfferingName"
   990  
   991  		BeforeEach(func() {
   992  			targetResource = TargetResource{
   993  				ResourceType: "service-offering",
   994  				ResourceName: serviceOfferingName,
   995  			}
   996  			labels = map[string]types.NullString{
   997  				"some-label":     types.NewNullString("some-value"),
   998  				"some-other-key": types.NewNullString(),
   999  			}
  1000  
  1001  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
  1002  			fakeActor.UpdateServiceOfferingLabelsReturns(
  1003  				v7action.Warnings{"some-warning-1", "some-warning-2"},
  1004  				nil,
  1005  			)
  1006  		})
  1007  
  1008  		JustBeforeEach(func() {
  1009  			executeErr = cmd.Execute(targetResource, labels)
  1010  		})
  1011  
  1012  		When("updating the labels succeeds", func() {
  1013  			It("does not return an error and prints all warnings", func() {
  1014  				Expect(executeErr).ToNot(HaveOccurred())
  1015  				Expect(testUI.Err).To(Say("some-warning-1"))
  1016  				Expect(testUI.Err).To(Say("some-warning-2"))
  1017  			})
  1018  
  1019  			It("passes the correct parameters into the actor", func() {
  1020  				Expect(fakeActor.UpdateServiceOfferingLabelsCallCount()).To(Equal(1))
  1021  				gotServiceOfferingName, gotBrokerName, gotLabelsMap := fakeActor.UpdateServiceOfferingLabelsArgsForCall(0)
  1022  				Expect(gotServiceOfferingName).To(Equal(serviceOfferingName))
  1023  				Expect(gotBrokerName).To(BeEmpty())
  1024  				Expect(gotLabelsMap).To(Equal(labels))
  1025  			})
  1026  
  1027  			When("a service broker name is specified", func() {
  1028  				BeforeEach(func() {
  1029  					targetResource.ServiceBroker = serviceBrokerName
  1030  				})
  1031  
  1032  				It("passes the broker name", func() {
  1033  					Expect(fakeActor.UpdateServiceOfferingLabelsCallCount()).To(Equal(1))
  1034  					_, gotBrokerName, _ := fakeActor.UpdateServiceOfferingLabelsArgsForCall(0)
  1035  					Expect(gotBrokerName).To(Equal(serviceBrokerName))
  1036  				})
  1037  			})
  1038  		})
  1039  
  1040  		When("the resource type argument is not lowercase", func() {
  1041  			BeforeEach(func() {
  1042  				targetResource.ResourceType = "Service-OffErinG"
  1043  			})
  1044  
  1045  			It("calls the right actor", func() {
  1046  				Expect(executeErr).ToNot(HaveOccurred())
  1047  				Expect(fakeActor.UpdateServiceOfferingLabelsCallCount()).To(Equal(1))
  1048  			})
  1049  
  1050  			It("displays a message in the right case", func() {
  1051  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for service-offering (.*)"))
  1052  				Expect(testUI.Out).To(Say("OK"))
  1053  			})
  1054  		})
  1055  
  1056  		When("updating the labels fails", func() {
  1057  			BeforeEach(func() {
  1058  				fakeActor.UpdateServiceOfferingLabelsReturns(
  1059  					v7action.Warnings{"some-warning-1", "some-warning-2"},
  1060  					errors.New("api call failed"),
  1061  				)
  1062  			})
  1063  
  1064  			It("returns the error and prints all warnings", func() {
  1065  				Expect(executeErr).To(MatchError("api call failed"))
  1066  				Expect(testUI.Err).To(Say("some-warning-1"))
  1067  				Expect(testUI.Err).To(Say("some-warning-2"))
  1068  			})
  1069  		})
  1070  
  1071  		Context("shows the right update message", func() {
  1072  			When("the broker name is not specified", func() {
  1073  				When("Unsetting labels", func() {
  1074  					BeforeEach(func() {
  1075  						cmd.Action = Unset
  1076  					})
  1077  
  1078  					It("shows 'Removing' as action", func() {
  1079  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for service-offering %s as some-user...`), serviceOfferingName))
  1080  						Expect(testUI.Out).To(Say("OK"))
  1081  					})
  1082  				})
  1083  
  1084  				When("Setting labels", func() {
  1085  					BeforeEach(func() {
  1086  						cmd.Action = Set
  1087  					})
  1088  
  1089  					It("shows 'Setting' as action", func() {
  1090  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for service-offering %s as some-user...`), serviceOfferingName))
  1091  						Expect(testUI.Out).To(Say("OK"))
  1092  					})
  1093  				})
  1094  			})
  1095  
  1096  			When("the broker name is specified", func() {
  1097  				BeforeEach(func() {
  1098  					targetResource.ServiceBroker = serviceBrokerName
  1099  				})
  1100  
  1101  				When("Unsetting labels", func() {
  1102  					BeforeEach(func() {
  1103  						cmd.Action = Unset
  1104  					})
  1105  
  1106  					It("shows 'Removing' as action", func() {
  1107  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for service-offering %s from service broker %s as some-user...`), serviceOfferingName, serviceBrokerName))
  1108  						Expect(testUI.Out).To(Say("OK"))
  1109  					})
  1110  				})
  1111  
  1112  				When("Setting labels", func() {
  1113  					BeforeEach(func() {
  1114  						cmd.Action = Set
  1115  					})
  1116  
  1117  					It("shows 'Setting' as action", func() {
  1118  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for service-offering %s from service broker %s as some-user...`), serviceOfferingName, serviceBrokerName))
  1119  						Expect(testUI.Out).To(Say("OK"))
  1120  					})
  1121  				})
  1122  			})
  1123  		})
  1124  	})
  1125  
  1126  	When("updating labels on service-plan", func() {
  1127  		var executeErr error
  1128  
  1129  		const serviceBrokerName = "brokerName"
  1130  		const serviceOfferingName = "serviceOfferingName"
  1131  		const servicePlanName = "servicePlanName"
  1132  
  1133  		BeforeEach(func() {
  1134  			targetResource = TargetResource{
  1135  				ResourceType: "service-plan",
  1136  				ResourceName: servicePlanName,
  1137  			}
  1138  			labels = map[string]types.NullString{
  1139  				"some-label":     types.NewNullString("some-value"),
  1140  				"some-other-key": types.NewNullString(),
  1141  			}
  1142  
  1143  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
  1144  			fakeActor.UpdateServicePlanLabelsReturns(
  1145  				v7action.Warnings{"some-warning-1", "some-warning-2"},
  1146  				nil,
  1147  			)
  1148  		})
  1149  
  1150  		JustBeforeEach(func() {
  1151  			executeErr = cmd.Execute(targetResource, labels)
  1152  		})
  1153  
  1154  		When("updating the labels succeeds", func() {
  1155  			It("does not return an error and prints all warnings", func() {
  1156  				Expect(executeErr).ToNot(HaveOccurred())
  1157  				Expect(testUI.Err).To(Say("some-warning-1"))
  1158  				Expect(testUI.Err).To(Say("some-warning-2"))
  1159  			})
  1160  
  1161  			It("passes the correct parameters into the actor", func() {
  1162  				Expect(fakeActor.UpdateServicePlanLabelsCallCount()).To(Equal(1))
  1163  				gotServicePlanName, gotServiceOfferingName, gotBrokerName, gotLabelsMap := fakeActor.UpdateServicePlanLabelsArgsForCall(0)
  1164  				Expect(gotServicePlanName).To(Equal(servicePlanName))
  1165  				Expect(gotServiceOfferingName).To(BeEmpty())
  1166  				Expect(gotBrokerName).To(BeEmpty())
  1167  				Expect(gotLabelsMap).To(Equal(labels))
  1168  			})
  1169  
  1170  			When("a service broker name is specified", func() {
  1171  				BeforeEach(func() {
  1172  					targetResource.ServiceBroker = serviceBrokerName
  1173  				})
  1174  
  1175  				It("passes the broker name", func() {
  1176  					Expect(fakeActor.UpdateServicePlanLabelsCallCount()).To(Equal(1))
  1177  					_, _, gotBrokerName, _ := fakeActor.UpdateServicePlanLabelsArgsForCall(0)
  1178  					Expect(gotBrokerName).To(Equal(serviceBrokerName))
  1179  				})
  1180  			})
  1181  
  1182  			When("a service offering name is specified", func() {
  1183  				BeforeEach(func() {
  1184  					targetResource.ServiceOffering = serviceOfferingName
  1185  				})
  1186  
  1187  				It("passes the broker name", func() {
  1188  					Expect(fakeActor.UpdateServicePlanLabelsCallCount()).To(Equal(1))
  1189  					_, gotOfferingName, _, _ := fakeActor.UpdateServicePlanLabelsArgsForCall(0)
  1190  					Expect(gotOfferingName).To(Equal(serviceOfferingName))
  1191  				})
  1192  			})
  1193  		})
  1194  
  1195  		When("the resource type argument is not lowercase", func() {
  1196  			BeforeEach(func() {
  1197  				targetResource.ResourceType = "Service-PlAN"
  1198  			})
  1199  
  1200  			It("calls the right actor", func() {
  1201  				Expect(executeErr).ToNot(HaveOccurred())
  1202  				Expect(fakeActor.UpdateServicePlanLabelsCallCount()).To(Equal(1))
  1203  			})
  1204  
  1205  			It("displays a message in the right case", func() {
  1206  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for service-plan (.*)"))
  1207  				Expect(testUI.Out).To(Say("OK"))
  1208  			})
  1209  		})
  1210  
  1211  		When("updating the labels fails", func() {
  1212  			BeforeEach(func() {
  1213  				fakeActor.UpdateServicePlanLabelsReturns(
  1214  					v7action.Warnings{"some-warning-1", "some-warning-2"},
  1215  					errors.New("api call failed"),
  1216  				)
  1217  			})
  1218  
  1219  			It("returns the error and prints all warnings", func() {
  1220  				Expect(executeErr).To(MatchError("api call failed"))
  1221  				Expect(testUI.Err).To(Say("some-warning-1"))
  1222  				Expect(testUI.Err).To(Say("some-warning-2"))
  1223  			})
  1224  		})
  1225  
  1226  		Context("shows the right update message", func() {
  1227  			When("no extra flags are specified", func() {
  1228  				When("Unsetting labels", func() {
  1229  					BeforeEach(func() {
  1230  						cmd.Action = Unset
  1231  					})
  1232  
  1233  					It("shows 'Removing' as action", func() {
  1234  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for service-plan %s as some-user...`), servicePlanName))
  1235  						Expect(testUI.Out).To(Say("OK"))
  1236  					})
  1237  				})
  1238  
  1239  				When("Setting labels", func() {
  1240  					BeforeEach(func() {
  1241  						cmd.Action = Set
  1242  					})
  1243  
  1244  					It("shows 'Setting' as action", func() {
  1245  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for service-plan %s as some-user...`), servicePlanName))
  1246  						Expect(testUI.Out).To(Say("OK"))
  1247  					})
  1248  				})
  1249  			})
  1250  
  1251  			When("the broker name is specified", func() {
  1252  				BeforeEach(func() {
  1253  					targetResource.ServiceBroker = serviceBrokerName
  1254  				})
  1255  
  1256  				When("Unsetting labels", func() {
  1257  					BeforeEach(func() {
  1258  						cmd.Action = Unset
  1259  					})
  1260  
  1261  					It("shows 'Removing' as action", func() {
  1262  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for service-plan %s from service broker %s as some-user...`), servicePlanName, serviceBrokerName))
  1263  						Expect(testUI.Out).To(Say("OK"))
  1264  					})
  1265  				})
  1266  
  1267  				When("Setting labels", func() {
  1268  					BeforeEach(func() {
  1269  						cmd.Action = Set
  1270  					})
  1271  
  1272  					It("shows 'Setting' as action", func() {
  1273  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for service-plan %s from service broker %s as some-user...`), servicePlanName, serviceBrokerName))
  1274  						Expect(testUI.Out).To(Say("OK"))
  1275  					})
  1276  				})
  1277  			})
  1278  
  1279  			When("the offering name is specified", func() {
  1280  				BeforeEach(func() {
  1281  					targetResource.ServiceOffering = serviceOfferingName
  1282  				})
  1283  
  1284  				When("Unsetting labels", func() {
  1285  					BeforeEach(func() {
  1286  						cmd.Action = Unset
  1287  					})
  1288  
  1289  					It("shows 'Removing' as action", func() {
  1290  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for service-plan %s from service offering %s as some-user...`), servicePlanName, serviceOfferingName))
  1291  						Expect(testUI.Out).To(Say("OK"))
  1292  					})
  1293  				})
  1294  
  1295  				When("Setting labels", func() {
  1296  					BeforeEach(func() {
  1297  						cmd.Action = Set
  1298  					})
  1299  
  1300  					It("shows 'Setting' as action", func() {
  1301  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for service-plan %s from service offering %s as some-user...`), servicePlanName, serviceOfferingName))
  1302  						Expect(testUI.Out).To(Say("OK"))
  1303  					})
  1304  				})
  1305  			})
  1306  
  1307  			When("both the offering name and the broker name are specified", func() {
  1308  				BeforeEach(func() {
  1309  					targetResource.ServiceBroker = serviceBrokerName
  1310  					targetResource.ServiceOffering = serviceOfferingName
  1311  				})
  1312  
  1313  				When("Unsetting labels", func() {
  1314  					BeforeEach(func() {
  1315  						cmd.Action = Unset
  1316  					})
  1317  
  1318  					It("shows 'Removing' as action", func() {
  1319  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for service-plan %s from service offering %s / service broker %s as some-user...`), servicePlanName, serviceOfferingName, serviceBrokerName))
  1320  						Expect(testUI.Out).To(Say("OK"))
  1321  					})
  1322  				})
  1323  
  1324  				When("Setting labels", func() {
  1325  					BeforeEach(func() {
  1326  						cmd.Action = Set
  1327  					})
  1328  
  1329  					It("shows 'Setting' as action", func() {
  1330  						Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for service-plan %s from service offering %s / service broker %s as some-user...`), servicePlanName, serviceOfferingName, serviceBrokerName))
  1331  						Expect(testUI.Out).To(Say("OK"))
  1332  					})
  1333  				})
  1334  			})
  1335  		})
  1336  	})
  1337  
  1338  	When("updating labels on spaces", func() {
  1339  		var (
  1340  			executeErr  error
  1341  			spaceName   string
  1342  			expectedMap map[string]types.NullString
  1343  		)
  1344  
  1345  		BeforeEach(func() {
  1346  			spaceName = "spiff"
  1347  			targetResource = TargetResource{
  1348  				ResourceType: "space",
  1349  				ResourceName: spaceName,
  1350  			}
  1351  			expectedMap = map[string]types.NullString{
  1352  				"some-label":     types.NewNullString("some-value"),
  1353  				"some-other-key": types.NewNullString(),
  1354  			}
  1355  			labels = expectedMap
  1356  
  1357  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
  1358  			fakeConfig.TargetedOrganizationReturns(
  1359  				configv3.Organization{Name: "fake-org", GUID: "some-org-guid"})
  1360  
  1361  			fakeActor.UpdateSpaceLabelsBySpaceNameReturns(
  1362  				v7action.Warnings{"some-warning-1", "some-warning-2"},
  1363  				nil)
  1364  		})
  1365  
  1366  		JustBeforeEach(func() {
  1367  			executeErr = cmd.Execute(targetResource, labels)
  1368  		})
  1369  
  1370  		When("updating the space labels succeeds", func() {
  1371  			It("does not return an error and prints all warnings", func() {
  1372  				Expect(executeErr).ToNot(HaveOccurred())
  1373  				Expect(testUI.Err).To(Say("some-warning-1"))
  1374  				Expect(testUI.Err).To(Say("some-warning-2"))
  1375  			})
  1376  
  1377  			It("passes the correct parameters into the actor", func() {
  1378  				Expect(fakeActor.UpdateSpaceLabelsBySpaceNameCallCount()).To(Equal(1))
  1379  				actualSpaceName, orgGUID, labelsMap := fakeActor.UpdateSpaceLabelsBySpaceNameArgsForCall(0)
  1380  				Expect(actualSpaceName).To(Equal(spaceName))
  1381  				Expect(orgGUID).To(Equal("some-org-guid"))
  1382  				Expect(labelsMap).To(Equal(expectedMap))
  1383  			})
  1384  		})
  1385  
  1386  		When("the resource type argument is not lowercase", func() {
  1387  			BeforeEach(func() {
  1388  				targetResource.ResourceType = "SpAcE"
  1389  			})
  1390  
  1391  			It("calls the right actor", func() {
  1392  				Expect(executeErr).ToNot(HaveOccurred())
  1393  				Expect(fakeActor.UpdateSpaceLabelsBySpaceNameCallCount()).To(Equal(1))
  1394  			})
  1395  
  1396  			It("displays a message in the right case", func() {
  1397  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for space (.*)"))
  1398  				Expect(testUI.Out).To(Say("OK"))
  1399  			})
  1400  		})
  1401  
  1402  		When("updating the space labels fails", func() {
  1403  			BeforeEach(func() {
  1404  				fakeActor.UpdateSpaceLabelsBySpaceNameReturns(
  1405  					v7action.Warnings{"some-warning-1", "some-warning-2"},
  1406  					errors.New("api call failed"),
  1407  				)
  1408  			})
  1409  
  1410  			It("returns the error and prints all warnings", func() {
  1411  				Expect(executeErr).To(MatchError("api call failed"))
  1412  				Expect(testUI.Err).To(Say("some-warning-1"))
  1413  				Expect(testUI.Err).To(Say("some-warning-2"))
  1414  			})
  1415  		})
  1416  
  1417  		Context("shows the right update message", func() {
  1418  			When("Unsetting labels", func() {
  1419  				BeforeEach(func() {
  1420  					cmd.Action = Unset
  1421  				})
  1422  
  1423  				It("shows 'Removing' as action", func() {
  1424  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for space %s in org fake-org as some-user...`), spaceName))
  1425  					Expect(testUI.Out).To(Say("OK"))
  1426  				})
  1427  			})
  1428  
  1429  			When("Setting labels", func() {
  1430  				BeforeEach(func() {
  1431  					cmd.Action = Set
  1432  				})
  1433  
  1434  				It("shows 'Setting' as action", func() {
  1435  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for space %s in org fake-org as some-user...`), spaceName))
  1436  					Expect(testUI.Out).To(Say("OK"))
  1437  				})
  1438  			})
  1439  		})
  1440  	})
  1441  
  1442  	When("updating labels on stacks", func() {
  1443  		const stackName = "some-stack"
  1444  
  1445  		var (
  1446  			executeErr  error
  1447  			expectedMap map[string]types.NullString
  1448  		)
  1449  
  1450  		BeforeEach(func() {
  1451  			targetResource = TargetResource{
  1452  				ResourceType: "stack",
  1453  				ResourceName: stackName,
  1454  			}
  1455  			fakeActor.GetCurrentUserReturns(configv3.User{Name: "some-user"}, nil)
  1456  			fakeSharedActor.CheckTargetReturns(nil)
  1457  			expectedMap = map[string]types.NullString{
  1458  				"some-label":     types.NewNullString("some-value"),
  1459  				"some-other-key": types.NewNullString(),
  1460  			}
  1461  			labels = expectedMap
  1462  		})
  1463  
  1464  		JustBeforeEach(func() {
  1465  			executeErr = cmd.Execute(targetResource, labels)
  1466  		})
  1467  
  1468  		When("updating the stack labels succeeds", func() {
  1469  			BeforeEach(func() {
  1470  				fakeActor.UpdateStackLabelsByStackNameReturns(v7action.Warnings{"some-warning-1", "some-warning-2"},
  1471  					nil)
  1472  			})
  1473  
  1474  			It("does not return an error and prints all warnings", func() {
  1475  				Expect(executeErr).ToNot(HaveOccurred())
  1476  				Expect(testUI.Err).To(Say("some-warning-1"))
  1477  				Expect(testUI.Err).To(Say("some-warning-2"))
  1478  			})
  1479  
  1480  			It("passes the correct parameters into the actor", func() {
  1481  				Expect(fakeActor.UpdateStackLabelsByStackNameCallCount()).To(Equal(1))
  1482  				actualStackName, labelsMap := fakeActor.UpdateStackLabelsByStackNameArgsForCall(0)
  1483  				Expect(actualStackName).To(Equal(stackName))
  1484  				Expect(labelsMap).To(Equal(expectedMap))
  1485  			})
  1486  		})
  1487  
  1488  		When("the resource type argument is not lowercase", func() {
  1489  			BeforeEach(func() {
  1490  				targetResource.ResourceType = "sTaCk"
  1491  			})
  1492  
  1493  			It("calls the right actor", func() {
  1494  				Expect(executeErr).ToNot(HaveOccurred())
  1495  				Expect(fakeActor.UpdateStackLabelsByStackNameCallCount()).To(Equal(1))
  1496  			})
  1497  
  1498  			It("displays a message in the right case", func() {
  1499  				Expect(testUI.Out).To(Say("(.*) label\\(s\\) for stack (.*)"))
  1500  				Expect(testUI.Out).To(Say("OK"))
  1501  			})
  1502  		})
  1503  
  1504  		When("updating the stack labels fails", func() {
  1505  			BeforeEach(func() {
  1506  				fakeActor.UpdateStackLabelsByStackNameReturns(
  1507  					v7action.Warnings{"some-warning-1", "some-warning-2"},
  1508  					errors.New("api call failed"),
  1509  				)
  1510  			})
  1511  
  1512  			It("returns the error and prints all warnings", func() {
  1513  				Expect(executeErr).To(MatchError("api call failed"))
  1514  				Expect(testUI.Err).To(Say("some-warning-1"))
  1515  				Expect(testUI.Err).To(Say("some-warning-2"))
  1516  			})
  1517  		})
  1518  
  1519  		Context("shows the right update message", func() {
  1520  			When("Unsetting labels", func() {
  1521  				BeforeEach(func() {
  1522  					cmd.Action = Unset
  1523  				})
  1524  
  1525  				It("shows 'Removing' as action", func() {
  1526  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Removing label(s) for stack %s as some-user...`), stackName))
  1527  					Expect(testUI.Out).To(Say("OK"))
  1528  				})
  1529  			})
  1530  
  1531  			When("Setting labels", func() {
  1532  				BeforeEach(func() {
  1533  					cmd.Action = Set
  1534  				})
  1535  
  1536  				It("shows 'Setting' as action", func() {
  1537  					Expect(testUI.Out).To(Say(regexp.QuoteMeta(`Setting label(s) for stack %s as some-user...`), stackName))
  1538  					Expect(testUI.Out).To(Say("OK"))
  1539  				})
  1540  			})
  1541  		})
  1542  	})
  1543  })