forked from ovn-org/libovsdb
-
Notifications
You must be signed in to change notification settings - Fork 10
/
rpc_test.go
129 lines (114 loc) · 3.5 KB
/
rpc_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package libovsdb
import (
"encoding/json"
"reflect"
"testing"
)
func TestNewGetSchemaArgs(t *testing.T) {
database := "Open_vSwitch"
args := NewGetSchemaArgs(database)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch"]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewTransactArgs(t *testing.T) {
database := "Open_vSwitch"
operation := Operation{Op: "insert", Table: "Bridge"}
args := NewTransactArgs(database, operation)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch",{"op":"insert","table":"Bridge"}]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewMultipleTransactArgs(t *testing.T) {
database := "Open_vSwitch"
operation1 := Operation{Op: "insert", Table: "Bridge"}
operation2 := Operation{Op: "delete", Table: "Bridge"}
args := NewTransactArgs(database, operation1, operation2)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch",{"op":"insert","table":"Bridge"},{"op":"delete","table":"Bridge"}]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewCancelArgs(t *testing.T) {
id := 1
args := NewCancelArgs(id)
argString, _ := json.Marshal(args)
expected := `[1]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewMonitorArgs(t *testing.T) {
database := "Open_vSwitch"
value := 1
r := MonitorRequest{
Columns: []string{"name", "ports", "external_ids"},
Select: MonitorSelect{
Initial: true,
Insert: true,
Delete: true,
Modify: true,
},
}
requests := make(map[string]MonitorRequest)
requests["Bridge"] = r
args := NewMonitorArgs(database, value, requests)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch",1,{"Bridge":{"columns":["name","ports","external_ids"],"select":{"initial":true,"insert":true,"delete":true,"modify":true}}}]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewMonitorCancelArgs(t *testing.T) {
value := 1
args := NewMonitorCancelArgs(value)
argString, _ := json.Marshal(args)
expected := `[1]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewLockArgs(t *testing.T) {
id := "testId"
args := NewLockArgs(id)
argString, _ := json.Marshal(args)
expected := `["testId"]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestEcho(t *testing.T) {
req := []interface{}{"hi"}
var reply []interface{}
echo(nil, req, &reply)
if !reflect.DeepEqual(req, reply) {
t.Error("Expected: ", req, " Got: ", reply)
}
}
func TestUpdate(t *testing.T) {
var reply interface{}
// Update notification should fail for arrays of size < 2
err := update(nil, []interface{}{"hello"}, &reply)
if err == nil {
t.Error("Expected: error for a dummy request")
}
// Update notification should fail if arg[1] is not map[string]map[string]RowUpdate type
err = update(nil, []interface{}{"hello", "gophers"}, &reply)
if err == nil {
t.Error("Expected: error for a dummy request")
}
// Valid dummy update should pass
validUpdate := make(map[string]interface{})
validRowUpdate := make(map[string]RowUpdate)
validRowUpdate["uuid"] = RowUpdate{}
validUpdate["table"] = validRowUpdate
err = update(nil, []interface{}{"hello", validUpdate}, &reply)
if err != nil {
t.Error(err)
}
}