github.com/sleungcy-sap/cli@v7.1.0+incompatible/command/v7/set_label_command_test.go (about)

     1  package v7_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/command/flag"
     5  	. "code.cloudfoundry.org/cli/command/v7"
     6  	"code.cloudfoundry.org/cli/command/v7/v7fakes"
     7  	"code.cloudfoundry.org/cli/types"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("set-label command", func() {
    13  	var (
    14  		cmd             SetLabelCommand
    15  		resourceName    string
    16  		fakeLabelSetter *v7fakes.FakeLabelSetter
    17  
    18  		executeErr error
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		fakeLabelSetter = new(v7fakes.FakeLabelSetter)
    23  		cmd = SetLabelCommand{
    24  			LabelSetter: fakeLabelSetter,
    25  		}
    26  	})
    27  
    28  	When("some provided labels do not have a value part", func() {
    29  		BeforeEach(func() {
    30  			cmd.RequiredArgs = flag.SetLabelArgs{
    31  				ResourceType: "anything",
    32  				ResourceName: resourceName,
    33  				Labels:       []string{"FOO=BAR", "MISSING_EQUALS", "ENV=FAKE"},
    34  			}
    35  		})
    36  
    37  		It("complains about the missing equal sign", func() {
    38  			err := cmd.Execute(nil)
    39  			Expect(err).To(MatchError("Metadata error: no value provided for label 'MISSING_EQUALS'"))
    40  			Expect(err).To(HaveOccurred())
    41  		})
    42  	})
    43  
    44  	When("all the provided labels are valid", func() {
    45  		BeforeEach(func() {
    46  			cmd.RequiredArgs = flag.SetLabelArgs{
    47  				ResourceType: "anything",
    48  				ResourceName: resourceName,
    49  				Labels:       []string{"FOO=BAZ", "FOO=BAR", "ENV=FAKE"},
    50  			}
    51  			cmd.BuildpackStack = "some-stack"
    52  			cmd.ServiceBroker = "some-service-broker"
    53  			cmd.ServiceOffering = "some-service-offering"
    54  		})
    55  
    56  		It("calls execute with the right parameters", func() {
    57  			executeErr = cmd.Execute(nil)
    58  
    59  			Expect(executeErr).ToNot(HaveOccurred())
    60  			Expect(fakeLabelSetter.ExecuteCallCount()).To(Equal(1))
    61  			targetResource, labels := fakeLabelSetter.ExecuteArgsForCall(0)
    62  			Expect(targetResource.ResourceType).To(Equal(cmd.RequiredArgs.ResourceType))
    63  			Expect(targetResource.ResourceName).To(Equal(cmd.RequiredArgs.ResourceName))
    64  			Expect(targetResource.BuildpackStack).To(Equal(cmd.BuildpackStack))
    65  			Expect(targetResource.ServiceBroker).To(Equal(cmd.ServiceBroker))
    66  			Expect(targetResource.ServiceOffering).To(Equal(cmd.ServiceOffering))
    67  			Expect(labels).To(Equal(map[string]types.NullString{
    68  				"FOO": types.NewNullString("BAR"),
    69  				"ENV": types.NewNullString("FAKE"),
    70  			}))
    71  		})
    72  	})
    73  })