forked from renproject/mpc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
marshal_test.go
66 lines (55 loc) · 1.58 KB
/
marshal_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
56
57
58
59
60
61
62
63
64
65
66
package rkpg_test
import (
"fmt"
"reflect"
"github.com/renproject/mpc/rkpg"
"github.com/renproject/surge/surgeutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Surge marshalling", func() {
trials := 10
ts := []reflect.Type{
reflect.TypeOf(rkpg.State{}),
reflect.TypeOf(rkpg.RKPGer{}),
}
for _, t := range ts {
t := t
Context(fmt.Sprintf("surge marshalling and unmarshalling for %v", t), func() {
It("should be the same after marshalling and unmarshalling", func() {
for i := 0; i < trials; i++ {
Expect(surgeutil.MarshalUnmarshalCheck(t)).To(Succeed())
}
})
It("should not panic when fuzzing", func() {
for i := 0; i < trials; i++ {
Expect(func() { surgeutil.Fuzz(t) }).ToNot(Panic())
}
})
Context("marshalling", func() {
It("should return an error when the buffer is too small", func() {
for i := 0; i < trials; i++ {
Expect(surgeutil.MarshalBufTooSmall(t)).To(Succeed())
}
})
It("should return an error when the memory quota is too small", func() {
for i := 0; i < trials; i++ {
Expect(surgeutil.MarshalRemTooSmall(t)).To(Succeed())
}
})
})
Context("unmarshalling", func() {
It("should return an error when the buffer is too small", func() {
for i := 0; i < trials; i++ {
Expect(surgeutil.UnmarshalBufTooSmall(t)).To(Succeed())
}
})
It("should return an error when the memory quota is too small", func() {
for i := 0; i < trials; i++ {
Expect(surgeutil.UnmarshalRemTooSmall(t)).To(Succeed())
}
})
})
})
}
})