-
Notifications
You must be signed in to change notification settings - Fork 59
/
client_test.go
143 lines (128 loc) · 3.08 KB
/
client_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package goovn
import (
"testing"
"github.com/stretchr/testify/assert"
)
const DUMMYTABLE = "Table1"
func TestNewClient_InvalidNBTables(t *testing.T) {
cfg := buildOvnDbConfig(DBNB)
cfg.TableCols = map[string][]string{
DUMMYTABLE: {},
}
_, err := NewClient(cfg)
assert.Error(t, err)
t.Log(err.Error())
}
func TestNewClient_ValidNBTableInvalidCol(t *testing.T) {
cfg := buildOvnDbConfig(DBNB)
cfg.TableCols = map[string][]string{
TableLogicalSwitchPort: {"col1"},
}
_, err := NewClient(cfg)
assert.Error(t, err)
t.Log(err.Error())
}
func TestNewClient_ValidNBTableCols(t *testing.T) {
cfg := buildOvnDbConfig(DBNB)
cfg.TableCols = map[string][]string{
TableLogicalSwitch: {},
}
api, err := NewClient(cfg)
if err != nil {
t.Fatal(err)
}
// create Switch with some values in external_ids
t.Logf("Adding %s to OVN with external_ids set", LS3)
cmd, err := api.LSAdd(LS3)
if err != nil {
t.Fatal(err)
}
err = api.Execute(cmd)
if err != nil {
t.Fatal(err)
}
// Add external_ids to LS3
external_ids := map[string]string{NEUTRON_NETWORK: DUMMY, FOO: BAR}
cmd, err = api.LSExtIdsAdd(LS3, external_ids)
if err != nil {
t.Fatal(err)
}
// execute the commands
err = api.Execute(cmd)
if err != nil {
t.Fatal(err)
}
// Get the logical switch
ls, err := api.LSGet(LS3)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, ls[0].Name, LS3)
assert.Equal(t, ls[0].ExternalID[NEUTRON_NETWORK], external_ids[NEUTRON_NETWORK])
assert.Equal(t, ls[0].ExternalID[FOO], external_ids[FOO])
// Finally delete Switch
t.Logf("Deleting LS3")
cmd, err = ovndbapi.LSDel(LS3)
if err != nil && err != ErrorNotFound {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatalf("err executing command:%v", err)
}
t.Logf("Deleting LS3 Done")
// Create a Logical Router and we should not be able to list the LR since
// we didn't express interest in the Logical_Router table
t.Logf("Adding LR %s", LR)
cmd, err = api.LRAdd(LR, nil)
if err != nil {
t.Fatal(err)
}
err = api.Execute(cmd)
if err != nil {
t.Fatal(err)
}
t.Logf("Listing LR %s", LR)
// We will not get the LR since we are not monitoring it.
_, err = api.LRList()
assert.Equal(t, err, ErrorNotFound)
// We cannot delete the LR since the client doesn't have the info for it.
_ = api.Close()
cfg = buildOvnDbConfig(DBNB)
cfg.TableCols = map[string][]string{
TableLogicalRouter: {},
}
api, err = NewClient(cfg)
if err != nil {
t.Fatal(err)
}
// finally delete the logical router
t.Logf("Deleting LR %s", LR)
cmd, err = ovndbapi.LRDel(LR)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}
t.Logf("Deleting LR %s Done", LR)
}
func TestNewClient_InvalidSBTables(t *testing.T) {
cfg := buildOvnDbConfig(DBSB)
cfg.TableCols = map[string][]string{
DUMMYTABLE: {},
}
_, err := NewClient(cfg)
assert.Error(t, err)
t.Log(err.Error())
}
func TestNewClient_ValidSBTableInvalidCol(t *testing.T) {
cfg := buildOvnDbConfig(DBSB)
cfg.TableCols = map[string][]string{
TableChassis: {"col1"},
}
_, err := NewClient(cfg)
assert.Error(t, err)
t.Log(err.Error())
}