github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/types/null_uint64_test.go (about) 1 package types_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/types" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 ) 8 9 var _ = Describe("NullUint64", func() { 10 var nullUint64 NullUint64 11 12 BeforeEach(func() { 13 nullUint64 = NullUint64{} 14 }) 15 16 Describe("ParseStringValue", func() { 17 When("the empty string is provided", func() { 18 It("sets IsSet to false", func() { 19 err := nullUint64.ParseStringValue("") 20 Expect(err).ToNot(HaveOccurred()) 21 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: false})) 22 }) 23 }) 24 25 When("an invalid integer is provided", func() { 26 It("returns an error", func() { 27 err := nullUint64.ParseStringValue("abcdef") 28 Expect(err).To(HaveOccurred()) 29 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: false})) 30 }) 31 }) 32 33 When("a negative integer is provided", func() { 34 It("returns an error", func() { 35 err := nullUint64.ParseStringValue("-1") 36 Expect(err).To(HaveOccurred()) 37 }) 38 }) 39 40 When("a valid integer is provided", func() { 41 It("stores the integer and sets IsSet to true", func() { 42 err := nullUint64.ParseStringValue("0") 43 Expect(err).ToNot(HaveOccurred()) 44 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: true})) 45 }) 46 }) 47 }) 48 49 Describe("UnmarshalJSON", func() { 50 When("integer value is provided", func() { 51 It("parses JSON number correctly", func() { 52 err := nullUint64.UnmarshalJSON([]byte("42")) 53 Expect(err).ToNot(HaveOccurred()) 54 Expect(nullUint64).To(Equal(NullUint64{Value: 42, IsSet: true})) 55 }) 56 }) 57 58 When("empty json is provided", func() { 59 It("returns an unset NullUint64", func() { 60 err := nullUint64.UnmarshalJSON([]byte(`""`)) 61 Expect(err).ToNot(HaveOccurred()) 62 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: false})) 63 }) 64 }) 65 }) 66 })