-
Notifications
You must be signed in to change notification settings - Fork 0
/
encdec_test.go
49 lines (44 loc) · 938 Bytes
/
encdec_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
package boom
import (
"testing"
"time"
)
type nestedObjType struct {
NestedField string
}
type EmbeddedStruct struct {
EmbeddedField string
}
type objType struct {
IntField int
FloatField float64
TimeField time.Time
StrField string
BoolField bool
NestedObjField nestedObjType
EmbeddedStruct
}
func TestEncodeDecode(t *testing.T) {
now := time.Now().Round(0)
obj := objType{
IntField: 123,
FloatField: 123.456,
TimeField: now,
StrField: "object",
BoolField: true,
NestedObjField: nestedObjType{NestedField: "nested object"},
EmbeddedStruct: EmbeddedStruct{EmbeddedField: "embedded object"},
}
encoded, err := GobEncode(obj)
if err != nil {
t.Fatal(err)
}
var decoded objType
err = GobDecode(encoded, &decoded)
if err != nil {
t.Fatal(err)
}
if decoded != obj {
t.Fatalf("original and decoded objects differs:\n%+v\n%+v", obj, decoded)
}
}