github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/command/flag/positive_integer_test.go (about)

     1  package flag_test
     2  
     3  import (
     4  	flags "github.com/jessevdk/go-flags"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  
     8  	. "code.cloudfoundry.org/cli/command/flag"
     9  )
    10  
    11  var _ = Describe("Positive Integer", func() {
    12  	var (
    13  		posInt PositiveInteger
    14  	)
    15  
    16  	Describe("UnmarshalFlag", func() {
    17  		BeforeEach(func() {
    18  			posInt = PositiveInteger{}
    19  		})
    20  
    21  		When("passed a positive integer", func() {
    22  			It("sets the value", func() {
    23  				err := posInt.UnmarshalFlag("42")
    24  				Expect(err).ToNot(HaveOccurred())
    25  				Expect(posInt.Value).To(BeEquivalentTo(42))
    26  			})
    27  		})
    28  
    29  		When("passed a non-positive integer", func() {
    30  			It("it returns an error", func() {
    31  				err := posInt.UnmarshalFlag("0")
    32  				Expect(err).To(MatchError(&flags.Error{
    33  					Type:    flags.ErrMarshal,
    34  					Message: `Value must be greater than or equal to 1.`,
    35  				}))
    36  			})
    37  		})
    38  	})
    39  
    40  })