github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/command/flag/timeout_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("Timeout", func() {
    12  	var (
    13  		timeout Timeout
    14  	)
    15  
    16  	Describe("UnmarshalFlag", func() {
    17  		BeforeEach(func() {
    18  			timeout = Timeout{}
    19  		})
    20  
    21  		When("passed a positive integer", func() {
    22  			It("sets the value", func() {
    23  				err := timeout.UnmarshalFlag("42")
    24  				Expect(err).ToNot(HaveOccurred())
    25  				Expect(timeout.Value).To(BeEquivalentTo(42))
    26  				Expect(timeout.IsSet).To(BeTrue())
    27  			})
    28  		})
    29  
    30  		When("passed a non-positive integer", func() {
    31  			It("it returns an error", func() {
    32  				err := timeout.UnmarshalFlag("0")
    33  				Expect(err).To(MatchError(&flags.Error{
    34  					Type:    flags.ErrRequired,
    35  					Message: `Timeout must be an integer greater than or equal to 1`,
    36  				}))
    37  			})
    38  		})
    39  	})
    40  })