Skip to content

Commit 0d4bbb4

Browse files
committed
add unit tests for set-controller and SetSSLParam
1 parent a1eab94 commit 0d4bbb4

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

ovs/client_test.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,27 @@ func TestNew(t *testing.T) {
2929
{
3030
desc: "no options",
3131
c: &Client{
32-
flags: make([]string, 0),
33-
debug: false,
32+
flags: make([]string, 0),
33+
ofctlFlags: make([]string, 0),
34+
debug: false,
3435
},
3536
},
3637
{
3738
desc: "Timeout(2)",
3839
options: []OptionFunc{Timeout(2)},
3940
c: &Client{
40-
flags: []string{"--timeout=2"},
41-
debug: false,
41+
flags: []string{"--timeout=2"},
42+
ofctlFlags: make([]string, 0),
43+
debug: false,
4244
},
4345
},
4446
{
4547
desc: "Debug(true)",
4648
options: []OptionFunc{Debug(true)},
4749
c: &Client{
48-
flags: make([]string, 0),
49-
debug: true,
50+
flags: make([]string, 0),
51+
ofctlFlags: make([]string, 0),
52+
debug: true,
5053
},
5154
},
5255
{
@@ -72,8 +75,9 @@ func TestNew(t *testing.T) {
7275
Debug(true),
7376
},
7477
c: &Client{
75-
flags: []string{"--timeout=5"},
76-
debug: true,
78+
flags: []string{"--timeout=5"},
79+
ofctlFlags: make([]string, 0),
80+
debug: true,
7781
},
7882
},
7983
{
@@ -82,8 +86,19 @@ func TestNew(t *testing.T) {
8286
Sudo(),
8387
},
8488
c: &Client{
85-
flags: make([]string, 0),
86-
sudo: true,
89+
flags: make([]string, 0),
90+
ofctlFlags: make([]string, 0),
91+
sudo: true,
92+
},
93+
},
94+
{
95+
desc: "SetSSLParam(pkey, cert, cacert)",
96+
options: []OptionFunc{
97+
SetSSLParam("privkey.pem", "cert.pem", "cacert.pem"),
98+
},
99+
c: &Client{
100+
flags: make([]string, 0),
101+
ofctlFlags: []string{"--private-key=privkey.pem", "--certificate=cert.pem", "--ca-cert=cacert.pem"},
87102
},
88103
},
89104
}
@@ -101,6 +116,15 @@ func TestNew(t *testing.T) {
101116
t.Fatalf("unexpected Client.debug:\n- want: %v\n- got: %v",
102117
want, got)
103118
}
119+
if want, got := tt.c.sudo, c.sudo; !reflect.DeepEqual(want, got) {
120+
t.Fatalf("unexpected Client.sudo:\n- want: %v\n- got: %v",
121+
want, got)
122+
}
123+
124+
if want, got := tt.c.ofctlFlags, c.ofctlFlags; !reflect.DeepEqual(want, got) {
125+
t.Fatalf("unexpected Client.ofctlFlags:\n- want: %v\n- got: %v",
126+
want, got)
127+
}
104128
})
105129
}
106130
}

ovs/vswitch_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,32 @@ func TestClientVSwitchDeletePortOK(t *testing.T) {
141141
}
142142
}
143143

144+
func TestClientVSwitchSetControllerOK(t *testing.T) {
145+
bridge := "br0"
146+
address := "pssl:6653:127.0.0.1"
147+
148+
// Apply Timeout option to verify arguments
149+
c := testClient([]OptionFunc{Timeout(1)}, func(cmd string, args ...string) ([]byte, error) {
150+
// Verify correct command and arguments passed, including option flags
151+
if want, got := "ovs-vsctl", cmd; want != got {
152+
t.Fatalf("incorrect command:\n- want: %v\n- got: %v",
153+
want, got)
154+
}
155+
156+
wantArgs := []string{"--timeout=1", "set-controller", string(bridge), address}
157+
if want, got := wantArgs, args; !reflect.DeepEqual(want, got) {
158+
t.Fatalf("incorrect arguments\n- want: %v\n- got: %v",
159+
want, got)
160+
}
161+
162+
return nil, nil
163+
})
164+
165+
if err := c.VSwitch.SetController(bridge, address); err != nil {
166+
t.Fatalf("unexpected error for Client.VSwitch.SetController: %v", err)
167+
}
168+
}
169+
144170
func TestClientVSwitchListPorts(t *testing.T) {
145171
tests := []struct {
146172
name string

0 commit comments

Comments
 (0)