github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/command/flag/color_test.go (about) 1 package flag_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/command/flag" 5 6 flags "github.com/jessevdk/go-flags" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/ginkgo/extensions/table" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Color", func() { 13 var color Color 14 15 Describe("UnmarshalFlag", func() { 16 BeforeEach(func() { 17 color = Color{} 18 }) 19 20 It("accepts true", func() { 21 err := color.UnmarshalFlag("true") 22 Expect(err).ToNot(HaveOccurred()) 23 Expect(color.Color).To(BeTrue()) 24 }) 25 26 It("accepts false", func() { 27 err := color.UnmarshalFlag("FalsE") 28 Expect(err).ToNot(HaveOccurred()) 29 Expect(color.Color).To(BeFalse()) 30 }) 31 32 It("errors on anything else", func() { 33 err := color.UnmarshalFlag("I AM A BANANANANANANANANAE") 34 Expect(err).To(MatchError(&flags.Error{ 35 Type: flags.ErrRequired, 36 Message: `COLOR must be "true" or "false"`, 37 })) 38 }) 39 }) 40 41 Describe("Complete", func() { 42 DescribeTable("returns list of completions", 43 func(prefix string, matches []flags.Completion) { 44 completions := color.Complete(prefix) 45 Expect(completions).To(Equal(matches)) 46 }, 47 48 Entry("completes to 'true' when passed 't'", "t", 49 []flags.Completion{{Item: "true"}}), 50 Entry("completes to 'false' when passed 'F'", "F", 51 []flags.Completion{{Item: "false"}}), 52 Entry("returns 'true' and 'false' when passed nothing", "", 53 []flags.Completion{{Item: "true"}, {Item: "false"}}), 54 Entry("completes to nothing when passed 'wut'", "wut", 55 []flags.Completion{}), 56 ) 57 }) 58 })