github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/command/flag/network_protocol_test.go (about)

     1  package flag_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/command/flag"
     5  	flags "github.com/jessevdk/go-flags"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/ginkgo/extensions/table"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("NetworkProtocol", func() {
    12  	var proto NetworkProtocol
    13  
    14  	Describe("Complete", func() {
    15  		DescribeTable("returns list of completions",
    16  			func(prefix string, matches []flags.Completion) {
    17  				completions := proto.Complete(prefix)
    18  				Expect(completions).To(Equal(matches))
    19  			},
    20  			Entry("returns 'tcp' when passed 't'", "t",
    21  				[]flags.Completion{{Item: "tcp"}}),
    22  			Entry("returns 'tcp' when passed 'T'", "T",
    23  				[]flags.Completion{{Item: "tcp"}}),
    24  			Entry("returns 'udp' when passed 'u'", "u",
    25  				[]flags.Completion{{Item: "udp"}}),
    26  			Entry("returns 'udp' when passed 'U'", "U",
    27  				[]flags.Completion{{Item: "udp"}}),
    28  			Entry("returns 'tcp' and 'udp' when passed ''", "",
    29  				[]flags.Completion{{Item: "tcp"}, {Item: "udp"}}),
    30  		)
    31  	})
    32  
    33  	Describe("UnmarshalFlag", func() {
    34  		BeforeEach(func() {
    35  			proto = NetworkProtocol{}
    36  		})
    37  
    38  		DescribeTable("downcases and sets type",
    39  			func(input string, expectedProtocol string) {
    40  				err := proto.UnmarshalFlag(input)
    41  				Expect(err).ToNot(HaveOccurred())
    42  				Expect(proto.Protocol).To(Equal(expectedProtocol))
    43  			},
    44  			Entry("sets 'tcp' when passed 'tcp'", "tcp", "tcp"),
    45  			Entry("sets 'tcp' when passed 'tCp'", "tCp", "tcp"),
    46  			Entry("sets 'udp' when passed 'udp'", "udp", "udp"),
    47  			Entry("sets 'udp' when passed 'uDp'", "uDp", "udp"),
    48  		)
    49  
    50  		Context("when passed anything else", func() {
    51  			It("returns an error", func() {
    52  				err := proto.UnmarshalFlag("banana")
    53  				Expect(err).To(MatchError(&flags.Error{
    54  					Type:    flags.ErrRequired,
    55  					Message: `PROTOCOL must be "tcp" or "udp"`,
    56  				}))
    57  				Expect(proto.Protocol).To(BeEmpty())
    58  			})
    59  		})
    60  	})
    61  })