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

     1  package flag_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/command/flag"
     5  	"code.cloudfoundry.org/cli/types"
     6  	flags "github.com/jessevdk/go-flags"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("Instances", func() {
    12  	var instances Instances
    13  
    14  	BeforeEach(func() {
    15  		instances = Instances{}
    16  	})
    17  
    18  	Describe("UnmarshalFlag", func() {
    19  		When("the empty string is provided", func() {
    20  			It("sets IsSet to false", func() {
    21  				err := instances.IsValidValue("")
    22  				Expect(err).ToNot(HaveOccurred())
    23  				Expect(instances).To(Equal(Instances{NullInt: types.NullInt{Value: 0, IsSet: false}}))
    24  			})
    25  		})
    26  
    27  		When("an invalid integer is provided", func() {
    28  			It("returns an error", func() {
    29  				err := instances.IsValidValue("abcdef")
    30  				Expect(err).To(MatchError(&flags.Error{
    31  					Type:    flags.ErrRequired,
    32  					Message: "invalid argument for flag '-i' (expected int > 0)",
    33  				}))
    34  				Expect(instances).To(Equal(Instances{NullInt: types.NullInt{Value: 0, IsSet: false}}))
    35  			})
    36  		})
    37  
    38  		When("a negative integer is provided", func() {
    39  			It("returns an error", func() {
    40  				err := instances.IsValidValue("-10")
    41  				Expect(err).To(MatchError(&flags.Error{
    42  					Type:    flags.ErrRequired,
    43  					Message: "invalid argument for flag '-i' (expected int > 0)",
    44  				}))
    45  				Expect(instances).To(Equal(Instances{NullInt: types.NullInt{Value: -10, IsSet: true}}))
    46  			})
    47  		})
    48  
    49  		When("a valid integer is provided", func() {
    50  			It("stores the integer and sets IsSet to true", func() {
    51  				err := instances.IsValidValue("0")
    52  				Expect(err).ToNot(HaveOccurred())
    53  				Expect(instances).To(Equal(Instances{NullInt: types.NullInt{Value: 0, IsSet: true}}))
    54  			})
    55  		})
    56  	})
    57  })