github.com/lzy4123/fabric@v2.1.1+incompatible/core/dispatcher/protobuf_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package dispatcher_test 8 9 import ( 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 13 lc "github.com/hyperledger/fabric-protos-go/peer/lifecycle" 14 "github.com/hyperledger/fabric/core/dispatcher" 15 16 "github.com/golang/protobuf/proto" 17 ) 18 19 var _ = Describe("ProtobufImpl", func() { 20 var ( 21 pi *dispatcher.ProtobufImpl 22 sampleMsg *lc.InstallChaincodeArgs 23 ) 24 25 BeforeEach(func() { 26 pi = &dispatcher.ProtobufImpl{} 27 sampleMsg = &lc.InstallChaincodeArgs{ 28 ChaincodeInstallPackage: []byte("install-package"), 29 } 30 }) 31 32 Describe("Marshal", func() { 33 It("passes through to the proto implementation", func() { 34 res, err := pi.Marshal(sampleMsg) 35 Expect(err).NotTo(HaveOccurred()) 36 37 msg := &lc.InstallChaincodeArgs{} 38 err = proto.Unmarshal(res, msg) 39 Expect(err).NotTo(HaveOccurred()) 40 Expect(proto.Equal(msg, sampleMsg)).To(BeTrue()) 41 }) 42 }) 43 44 Describe("Unmarshal", func() { 45 It("passes through to the proto implementation", func() { 46 res, err := proto.Marshal(sampleMsg) 47 Expect(err).NotTo(HaveOccurred()) 48 49 msg := &lc.InstallChaincodeArgs{} 50 err = pi.Unmarshal(res, msg) 51 Expect(err).NotTo(HaveOccurred()) 52 Expect(proto.Equal(msg, sampleMsg)).To(BeTrue()) 53 }) 54 }) 55 })