github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/command/flag/tags_test.go (about)

     1  package flag_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/command/flag"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  )
     8  
     9  var _ = Describe("Tags", func() {
    10  	var tags Tags
    11  
    12  	BeforeEach(func() {
    13  		tags = Tags{}
    14  	})
    15  
    16  	Describe("default value", func() {
    17  		It("is unset by default", func() {
    18  			Expect(tags.IsSet).To(BeFalse())
    19  		})
    20  
    21  		It("has an empty value", func() {
    22  			Expect(tags.Value).To(BeEmpty())
    23  		})
    24  	})
    25  
    26  	Describe("UnmarshalFlag", func() {
    27  		When("the empty string is provided", func() {
    28  			It("should return empty list", func() {
    29  				Expect(tags.UnmarshalFlag("")).To(Succeed())
    30  				Expect(tags.IsSet).To(BeTrue())
    31  				Expect(tags.Value).To(ConsistOf([]string{}))
    32  			})
    33  		})
    34  
    35  		When("single tag is provided", func() {
    36  			It("should return the string", func() {
    37  				Expect(tags.UnmarshalFlag("tag")).To(Succeed())
    38  				Expect(tags.IsSet).To(BeTrue())
    39  				Expect(tags.Value).To(ConsistOf([]string{"tag"}))
    40  			})
    41  		})
    42  
    43  		When("multiple comma separated tags are provided", func() {
    44  			It("should return the string", func() {
    45  				Expect(tags.UnmarshalFlag("tag1,tag2")).To(Succeed())
    46  				Expect(tags.IsSet).To(BeTrue())
    47  				Expect(tags.Value).To(ConsistOf([]string{"tag1", "tag2"}))
    48  			})
    49  		})
    50  
    51  		When("multiple tags with spaces are provided", func() {
    52  			It("should return the trimmed tags", func() {
    53  				Expect(tags.UnmarshalFlag(" tag1,  tag2")).To(Succeed())
    54  				Expect(tags.IsSet).To(BeTrue())
    55  				Expect(tags.Value).To(ConsistOf([]string{"tag1", "tag2"}))
    56  			})
    57  		})
    58  
    59  		When("multiple tags with excessive commas are provided", func() {
    60  			It("should return just the tags", func() {
    61  				Expect(tags.UnmarshalFlag(",tag1,tag2,")).To(Succeed())
    62  				Expect(tags.IsSet).To(BeTrue())
    63  				Expect(tags.Value).To(ConsistOf([]string{"tag1", "tag2"}))
    64  			})
    65  		})
    66  	})
    67  })