github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/v2_formatted_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("V2 Formatted Resource", func() {
    13  		Describe("MarshalJSON", func() {
    14  			It("marshals the json properly", func() {
    15  				resource := V2FormattedResource{
    16  					Filename: "some-file-1",
    17  					Mode:     0744,
    18  					SHA1:     "some-sha-1",
    19  					Size:     1,
    20  				}
    21  				data, err := json.Marshal(resource)
    22  				Expect(err).ToNot(HaveOccurred())
    23  				Expect(data).To(MatchJSON(`{
    24  				"fn":   "some-file-1",
    25  				"mode": "744",
    26  				"sha1": "some-sha-1",
    27  				"size": 1
    28  			}`))
    29  			})
    30  		})
    31  
    32  		Describe("UnmarshalJSON", func() {
    33  			It("unmarshals the json properly", func() {
    34  				raw := `{
    35  				"fn":   "some-file-1",
    36  				"mode": "744",
    37  				"sha1": "some-sha-1",
    38  				"size": 1
    39  			}`
    40  
    41  				var data V2FormattedResource
    42  				err := json.Unmarshal([]byte(raw), &data)
    43  				Expect(err).ToNot(HaveOccurred())
    44  				Expect(data).To(Equal(V2FormattedResource{
    45  					Filename: "some-file-1",
    46  					Mode:     0744,
    47  					SHA1:     "some-sha-1",
    48  					Size:     1,
    49  				}))
    50  			})
    51  		})
    52  	})
    53  })