github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/types/optional_boolean_test.go (about)

     1  package types_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/types"
     5  	"code.cloudfoundry.org/jsonry"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/ginkgo/extensions/table"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("optional boolean", func() {
    12  	It("has an unset zero value", func() {
    13  		var s types.OptionalBoolean
    14  		Expect(s.IsSet).To(BeFalse())
    15  		Expect(s.Value).To(BeFalse())
    16  	})
    17  
    18  	DescribeTable(
    19  		"marshaling and unmarshalling",
    20  		func(o types.OptionalBoolean, j string) {
    21  			By("marshalling", func() {
    22  				container := struct {
    23  					A types.OptionalBoolean `jsonry:"a"`
    24  				}{
    25  					A: o,
    26  				}
    27  
    28  				data, err := jsonry.Marshal(container)
    29  				Expect(err).NotTo(HaveOccurred())
    30  				Expect(data).To(MatchJSON(j))
    31  			})
    32  
    33  			By("unmarshalling", func() {
    34  				var receiver struct {
    35  					A types.OptionalBoolean `jsonry:"a"`
    36  				}
    37  				err := jsonry.Unmarshal([]byte(j), &receiver)
    38  				Expect(err).NotTo(HaveOccurred())
    39  				Expect(receiver.A).To(Equal(o))
    40  			})
    41  		},
    42  		Entry("true", types.NewOptionalBoolean(true), `{"a": true}`),
    43  		Entry("false", types.NewOptionalBoolean(false), `{"a": false}`),
    44  		Entry("unset", types.OptionalBoolean{}, `{}`),
    45  	)
    46  })