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