github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/command/flag/revision_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("Revision", func() {
    12  	var revision Revision
    13  
    14  	BeforeEach(func() {
    15  		revision = Revision{}
    16  	})
    17  
    18  	Describe("UnmarshalFlag", func() {
    19  		When("the empty string is provided", func() {
    20  			It("sets IsSet to false", func() {
    21  				err := revision.IsValidValue("")
    22  				Expect(err).ToNot(HaveOccurred())
    23  				Expect(revision).To(Equal(Revision{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 := revision.IsValidValue("abcdef")
    30  				Expect(err).To(MatchError(&flags.Error{
    31  					Type:    flags.ErrRequired,
    32  					Message: "invalid argument for flag '--revision' (expected int > 0)",
    33  				}))
    34  				Expect(revision).To(Equal(Revision{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 := revision.IsValidValue("-10")
    41  				Expect(err).To(MatchError(&flags.Error{
    42  					Type:    flags.ErrRequired,
    43  					Message: "invalid argument for flag '--revision' (expected int > 0)",
    44  				}))
    45  				Expect(revision).To(Equal(Revision{NullInt: types.NullInt{Value: -10, IsSet: true}}))
    46  			})
    47  		})
    48  
    49  		When("0 is provided", func() {
    50  			It("returns an error", func() {
    51  				err := revision.IsValidValue("0")
    52  				Expect(err).To(MatchError(&flags.Error{
    53  					Type:    flags.ErrRequired,
    54  					Message: "invalid argument for flag '--revision' (expected int > 0)",
    55  				}))
    56  				Expect(revision).To(Equal(Revision{NullInt: types.NullInt{Value: 0, IsSet: true}}))
    57  			})
    58  		})
    59  
    60  		When("a valid integer is provided", func() {
    61  			It("stores the integer and sets IsSet to true", func() {
    62  				err := revision.IsValidValue("1")
    63  				Expect(err).ToNot(HaveOccurred())
    64  				Expect(revision).To(Equal(Revision{NullInt: types.NullInt{Value: 1, IsSet: true}}))
    65  			})
    66  		})
    67  	})
    68  })