-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack_test.go
66 lines (52 loc) · 1.2 KB
/
pack_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 zbus
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRequest(t *testing.T) {
type T struct {
Name string
Age float64
}
arg := T{"Azmy", 36}
objID := ObjectID{"object", "1.0"}
request, err := NewRequest("my-id", "", objID, "DoSomething", "arg1", 2, arg)
if ok := assert.NoError(t, err); !ok {
t.Fatal()
}
msg, err := request.Encode()
if ok := assert.NoError(t, err); !ok {
t.Fatal()
}
loaded, err := LoadRequest(msg)
if ok := assert.NoError(t, err); !ok {
t.Fatal()
}
if ok := assert.Equal(t, request.ID, loaded.ID); !ok {
t.Error()
}
if ok := assert.Equal(t, request.Object, loaded.Object); !ok {
t.Error()
}
if ok := assert.Equal(t, request.Method, loaded.Method); !ok {
t.Error()
}
must := func(o interface{}, err error) interface{} {
if ok := assert.NoError(t, err); !ok {
t.Fatal()
}
return o
}
if ok := assert.Equal(t, "arg1", must(loaded.Value(0, reflect.TypeOf("")))); !ok {
t.Error()
}
intArg := must(loaded.Value(1, reflect.TypeOf(0)))
if ok := assert.Equal(t, 2, intArg); !ok {
t.Error()
}
structArg := must(loaded.Value(2, reflect.TypeOf(T{})))
if ok := assert.Equal(t, arg, structArg); !ok {
t.Error()
}
}