github.com/sleungcy/cli@v7.1.0+incompatible/command/flag/deployment_strategy_test.go (about) 1 package flag_test 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 5 . "code.cloudfoundry.org/cli/command/flag" 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("DeploymentStrategy", func() { 13 var strategy DeploymentStrategy 14 15 Describe("Complete", func() { 16 DescribeTable("returns list of completions", 17 func(prefix string, matches []flags.Completion) { 18 completions := strategy.Complete(prefix) 19 Expect(completions).To(Equal(matches)) 20 }, 21 Entry("returns 'rolling' when passed 'r'", "r", 22 []flags.Completion{{Item: "rolling"}}), 23 ) 24 }) 25 26 Describe("UnmarshalFlag", func() { 27 BeforeEach(func() { 28 strategy = DeploymentStrategy{} 29 }) 30 31 DescribeTable("downcases and sets strategy", 32 func(settingType string, expectedType constant.DeploymentStrategy) { 33 err := strategy.UnmarshalFlag(settingType) 34 Expect(err).ToNot(HaveOccurred()) 35 Expect(strategy.Name).To(Equal(expectedType)) 36 }, 37 Entry("sets 'rolling' when passed 'rolling'", "rolling", constant.DeploymentStrategyRolling), 38 Entry("sets 'rolling' when passed 'rOlliNg'", "rOlliNg", constant.DeploymentStrategyRolling), 39 Entry("sets 'rolling' when passed 'ROLLING'", "ROLLING", constant.DeploymentStrategyRolling), 40 ) 41 42 When("passed anything else", func() { 43 It("returns an error", func() { 44 err := strategy.UnmarshalFlag("banana") 45 Expect(err).To(MatchError(&flags.Error{ 46 Type: flags.ErrInvalidChoice, 47 Message: `STRATEGY must be "rolling" or not set`, 48 })) 49 Expect(strategy.Name).To(BeEmpty()) 50 }) 51 }) 52 }) 53 })