github.com/swisscom/cloudfoundry-cli@v7.1.0+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 IsSet: true, 15 Value: 0xBAD, 16 } 17 }) 18 19 Describe("ParseStringValue", func() { 20 When("the empty string is provided", func() { 21 It("sets IsSet to false", func() { 22 err := nullUint64.ParseStringValue("") 23 Expect(err).ToNot(HaveOccurred()) 24 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: false})) 25 }) 26 }) 27 28 When("an invalid integer is provided", func() { 29 It("returns an error", func() { 30 err := nullUint64.ParseStringValue("abcdef") 31 Expect(err).To(HaveOccurred()) 32 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: false})) 33 }) 34 }) 35 36 When("a negative integer is provided", func() { 37 It("returns an error", func() { 38 err := nullUint64.ParseStringValue("-1") 39 Expect(err).To(HaveOccurred()) 40 }) 41 }) 42 43 When("a valid integer is provided", func() { 44 It("stores the integer and sets IsSet to true", func() { 45 err := nullUint64.ParseStringValue("0") 46 Expect(err).ToNot(HaveOccurred()) 47 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: true})) 48 }) 49 }) 50 }) 51 52 Describe("UnmarshalJSON", func() { 53 When("integer value is provided", func() { 54 It("parses JSON number correctly", func() { 55 err := nullUint64.UnmarshalJSON([]byte("42")) 56 Expect(err).ToNot(HaveOccurred()) 57 Expect(nullUint64).To(Equal(NullUint64{Value: 42, IsSet: true})) 58 }) 59 }) 60 61 When("a null value is provided", func() { 62 It("returns an unset NullUint64", func() { 63 err := nullUint64.UnmarshalJSON([]byte("null")) 64 Expect(err).ToNot(HaveOccurred()) 65 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: false})) 66 }) 67 }) 68 69 When("empty string is provided", func() { 70 It("returns an unset NullUint64", func() { 71 err := nullUint64.UnmarshalJSON([]byte("")) 72 Expect(err).ToNot(HaveOccurred()) 73 Expect(nullUint64).To(Equal(NullUint64{Value: 0, IsSet: false})) 74 }) 75 }) 76 }) 77 })