github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/flag/color_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("Color", func() { 12 var color Color 13 14 Describe("Complete", func() { 15 DescribeTable("returns list of completions", 16 func(prefix string, matches []flags.Completion) { 17 completions := color.Complete(prefix) 18 Expect(completions).To(Equal(matches)) 19 }, 20 21 Entry("completes to 'true' when passed 't'", "t", 22 []flags.Completion{{Item: "true"}}), 23 Entry("completes to 'false' when passed 'f'", "f", 24 []flags.Completion{{Item: "false"}}), 25 Entry("completes to 'true' when passed 'tR'", "tR", 26 []flags.Completion{{Item: "true"}}), 27 Entry("completes to 'false' when passed 'Fa'", "Fa", 28 []flags.Completion{{Item: "false"}}), 29 Entry("returns 'true' and 'false' when passed nothing", "", 30 []flags.Completion{{Item: "true"}, {Item: "false"}}), 31 Entry("completes to nothing when passed 'wut'", "wut", 32 []flags.Completion{}), 33 ) 34 }) 35 36 Describe("UnmarshalFlag", func() { 37 BeforeEach(func() { 38 color = Color{} 39 }) 40 41 It("accepts true", func() { 42 err := color.UnmarshalFlag("true") 43 Expect(err).ToNot(HaveOccurred()) 44 Expect(color.Color).To(BeTrue()) 45 }) 46 47 It("accepts false", func() { 48 err := color.UnmarshalFlag("FalsE") 49 Expect(err).ToNot(HaveOccurred()) 50 Expect(color.Color).To(BeFalse()) 51 }) 52 53 It("errors on anything else", func() { 54 err := color.UnmarshalFlag("I AM A BANANANANANANANANAE") 55 Expect(err).To(MatchError(&flags.Error{ 56 Type: flags.ErrRequired, 57 Message: `COLOR must be "true" or "false"`, 58 })) 59 }) 60 }) 61 })