-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvom_test.go
59 lines (48 loc) · 1.02 KB
/
vom_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
// Copyright 2016 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package miniv
import (
"bytes"
"testing"
"v.io/v23/uniqueid"
"v.io/v23/vom"
)
func TestVomStruct(t *testing.T) {
ts0 := testStruct{A: 1, B: 3.14, Inner: inner{String: "Hello."}}
buf := &bytes.Buffer{}
e := vom.NewEncoder(buf)
err := e.Encode(ts0)
if err != nil {
t.Fatal(err)
}
out, err := decodeStruct(buf.Bytes())
if err != nil {
t.Fatal(err)
}
ts1 := out.(testStruct)
if ts0 != ts1 {
t.Error(ts0, "does not equal", ts1)
}
}
func TestVomUid(t *testing.T) {
uid0, err := uniqueid.Random()
if err != nil {
t.Fatal(err)
}
t.Log("the uniqueid is", uid0)
buf := &bytes.Buffer{}
e := vom.NewEncoder(buf)
err = e.Encode(uid0)
if err != nil {
t.Fatal(err)
}
out, err := decodeStruct(buf.Bytes())
if err != nil {
t.Fatal(err)
}
uid := out.(uniqueid.Id)
if !bytes.Equal(uid[:], uid0[:]) {
t.Error("uid not equal:", uid0, uid)
}
}