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

     1  package types_test
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	. "code.cloudfoundry.org/cli/types"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("JSONObject", func() {
    12  	It("marshals as JSON", func() {
    13  		serialized, err := json.Marshal(JSONObject{"foo": "bar"})
    14  		Expect(err).NotTo(HaveOccurred())
    15  		Expect(serialized).To(Equal([]byte(`{"foo":"bar"}`)))
    16  	})
    17  
    18  	When("nil", func() {
    19  		It("marshals as an empty object (not as null)", func() {
    20  			var o JSONObject
    21  			serialized, err := json.Marshal(o)
    22  			Expect(err).NotTo(HaveOccurred())
    23  			Expect(serialized).To(Equal([]byte(`{}`)))
    24  		})
    25  	})
    26  })