github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/command/flag/health_check_type_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("HealthCheckType", func() {
    13  	var healthCheck HealthCheckType
    14  
    15  	Describe("Complete", func() {
    16  		DescribeTable("returns list of completions",
    17  			func(prefix string, matches []flags.Completion) {
    18  				completions := healthCheck.Complete(prefix)
    19  				Expect(completions).To(Equal(matches))
    20  			},
    21  			Entry("returns 'port' and 'process' when passed 'p'", "p",
    22  				[]flags.Completion{{Item: "port"}, {Item: "process"}}),
    23  			Entry("returns 'port' and 'process' when passed 'P'", "P",
    24  				[]flags.Completion{{Item: "port"}, {Item: "process"}}),
    25  			Entry("returns 'port' when passed 'poR'", "poR",
    26  				[]flags.Completion{{Item: "port"}}),
    27  			Entry("completes to 'http' when passed 'h'", "h",
    28  				[]flags.Completion{{Item: "http"}}),
    29  			Entry("completes to 'http', 'port', and 'process' when passed nothing", "",
    30  				[]flags.Completion{{Item: "http"}, {Item: "port"}, {Item: "process"}}),
    31  			Entry("completes to nothing when passed 'wut'", "wut",
    32  				[]flags.Completion{}),
    33  		)
    34  	})
    35  
    36  	Describe("UnmarshalFlag", func() {
    37  		BeforeEach(func() {
    38  			healthCheck = HealthCheckType{}
    39  		})
    40  
    41  		DescribeTable("downcases and sets type",
    42  			func(settingType string, expectedType constant.HealthCheckType) {
    43  				err := healthCheck.UnmarshalFlag(settingType)
    44  				Expect(err).ToNot(HaveOccurred())
    45  				Expect(healthCheck.Type).To(Equal(expectedType))
    46  			},
    47  			Entry("sets 'port' when passed 'port'", "port", constant.Port),
    48  			Entry("sets 'port' when passed 'pOrt'", "pOrt", constant.Port),
    49  			Entry("sets 'process' when passed 'process'", "process", constant.Process),
    50  			Entry("sets 'http' when passed 'http'", "http", constant.HTTP),
    51  		)
    52  
    53  		When("passed anything else", func() {
    54  			It("returns an error", func() {
    55  				err := healthCheck.UnmarshalFlag("banana")
    56  				Expect(err).To(MatchError(&flags.Error{
    57  					Type:    flags.ErrRequired,
    58  					Message: `HEALTH_CHECK_TYPE must be "port", "process", or "http"`,
    59  				}))
    60  				Expect(healthCheck.Type).To(BeEmpty())
    61  			})
    62  		})
    63  	})
    64  })