github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/command/flag/health_check_type_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("HealthCheckType", func() {
    12  	var healthCheck HealthCheckType
    13  
    14  	Describe("Complete", func() {
    15  		DescribeTable("returns list of completions",
    16  			func(prefix string, matches []flags.Completion) {
    17  				completions := healthCheck.Complete(prefix)
    18  				Expect(completions).To(Equal(matches))
    19  			},
    20  			Entry("returns 'port' and 'process' when passed 'p'", "p",
    21  				[]flags.Completion{{Item: "port"}, {Item: "process"}}),
    22  			Entry("returns 'port' and 'process' when passed 'P'", "P",
    23  				[]flags.Completion{{Item: "port"}, {Item: "process"}}),
    24  			Entry("returns 'port' when passed 'poR'", "poR",
    25  				[]flags.Completion{{Item: "port"}}),
    26  			Entry("completes to 'http' when passed 'h'", "h",
    27  				[]flags.Completion{{Item: "http"}}),
    28  			Entry("completes to 'http', 'port', and 'process' when passed nothing", "",
    29  				[]flags.Completion{{Item: "http"}, {Item: "port"}, {Item: "process"}}),
    30  			Entry("completes to nothing when passed 'wut'", "wut",
    31  				[]flags.Completion{}),
    32  		)
    33  	})
    34  
    35  	Describe("UnmarshalFlag", func() {
    36  		BeforeEach(func() {
    37  			healthCheck = HealthCheckType{}
    38  		})
    39  
    40  		DescribeTable("downcases and sets type",
    41  			func(settingType string, expectedType string) {
    42  				err := healthCheck.UnmarshalFlag(settingType)
    43  				Expect(err).ToNot(HaveOccurred())
    44  				Expect(healthCheck.Type).To(Equal(expectedType))
    45  			},
    46  			Entry("sets 'port' when passed 'port'", "port", "port"),
    47  			Entry("sets 'port' when passed 'pOrt'", "pOrt", "port"),
    48  			Entry("sets 'process' when passed 'none'", "none", "none"),
    49  			Entry("sets 'process' when passed 'process'", "process", "process"),
    50  			Entry("sets 'http' when passed 'http'", "http", "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  })