github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/api/cloudcontroller/ccv3/resource_test.go (about)

     1  package ccv3_test
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("Resource", func() {
    12  	Describe("MarshalJSON", func() {
    13  		It("marshals the json properly", func() {
    14  			resource := Resource{
    15  				Filename: "some-file-1",
    16  				Mode:     0744,
    17  				SHA1:     "some-sha-1",
    18  				Size:     1,
    19  			}
    20  			data, err := json.Marshal(resource)
    21  			Expect(err).ToNot(HaveOccurred())
    22  			Expect(data).To(MatchJSON(`{
    23  				"fn":   "some-file-1",
    24  				"mode": "744",
    25  				"sha1": "some-sha-1",
    26  				"size": 1
    27  			}`))
    28  		})
    29  	})
    30  
    31  	Describe("MarshalJSON", func() {
    32  		It("marshals the json properly", func() {
    33  			raw := `{
    34  				"fn":   "some-file-1",
    35  				"mode": "744",
    36  				"sha1": "some-sha-1",
    37  				"size": 1
    38  			}`
    39  
    40  			var data Resource
    41  			err := json.Unmarshal([]byte(raw), &data)
    42  			Expect(err).ToNot(HaveOccurred())
    43  			Expect(data).To(Equal(Resource{
    44  				Filename: "some-file-1",
    45  				Mode:     0744,
    46  				SHA1:     "some-sha-1",
    47  				Size:     1,
    48  			}))
    49  		})
    50  	})
    51  })