github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/resources/last_operation_resource_test.go (about) 1 package resources_test 2 3 import ( 4 "encoding/json" 5 6 . "code.cloudfoundry.org/cli/resources" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/ginkgo/extensions/table" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("last operation resource", func() { 13 DescribeTable( 14 "Marshaling and Unmarshaling", 15 func(lastOperation LastOperation, serialized string) { 16 By("marshaling", func() { 17 Expect(json.Marshal(lastOperation)).To(MatchJSON(serialized)) 18 }) 19 20 By("unmarshaling", func() { 21 var parsed LastOperation 22 Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred()) 23 Expect(parsed).To(Equal(lastOperation)) 24 }) 25 }, 26 Entry("type", LastOperation{Type: "fake-type"}, `{"type": "fake-type"}`), 27 Entry("state", LastOperation{State: "fake-state"}, `{"state": "fake-state"}`), 28 Entry("description", LastOperation{Description: "fake-description"}, `{"description": "fake-description"}`), 29 Entry("created_at", LastOperation{CreatedAt: "fake-created-at"}, `{"created_at": "fake-created-at"}`), 30 Entry("updated_at", LastOperation{UpdatedAt: "fake-updated-at"}, `{"updated_at": "fake-updated-at"}`), 31 Entry( 32 "everything", 33 LastOperation{ 34 Type: CreateOperation, 35 State: OperationInProgress, 36 Description: "doing stuff", 37 CreatedAt: "yesterday", 38 UpdatedAt: "just now", 39 }, 40 `{ 41 "type": "create", 42 "state": "in progress", 43 "description": "doing stuff", 44 "created_at": "yesterday", 45 "updated_at": "just now" 46 }`, 47 ), 48 ) 49 50 DescribeTable( 51 "OmitJSONry", 52 func(lastOperation LastOperation, expected bool) { 53 Expect(lastOperation.OmitJSONry()).To(Equal(expected)) 54 }, 55 Entry("empty object", LastOperation{}, true), 56 Entry("type", LastOperation{Type: CreateOperation}, false), 57 Entry("state", LastOperation{State: OperationInProgress}, false), 58 Entry("created_at", LastOperation{CreatedAt: "now"}, false), 59 Entry("updated_at", LastOperation{UpdatedAt: "now"}, false), 60 ) 61 })