blob: b6b8738e786c7909b00c01260f16fa3cdcd8f9c7 [file] [log] [blame]
vinokumaf7605fc2023-06-02 18:08:01 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package application
17
18import (
19 "context"
20 "testing"
21 "voltha-go-controller/internal/pkg/intf"
22 "voltha-go-controller/internal/pkg/of"
23 "voltha-go-controller/internal/pkg/util"
24 "voltha-go-controller/internal/test/mocks"
25
26 "github.com/golang/mock/gomock"
27)
28
29var voltPortVnet = &VoltPortVnet{
30 Device: "test_device",
31}
32var voltService = &VoltService{
33 Version: "test_version",
34}
35
36func TestExecuteFlowEvent(t *testing.T) {
37 type args struct {
38 cntx context.Context
39 vd *VoltDevice
40 cookie string
41 flowStatus intf.FlowStatus
42 }
43 tests := []struct {
44 name string
45 args args
46 want bool
47 }{
48 {
49 name: "ExecuteFlowEvent_add",
50 args: args{
51 cntx: context.Background(),
52 vd: &VoltDevice{
53 SouthBoundID: "test_device_id",
54 FlowAddEventMap: util.NewConcurrentMap(),
55 },
56 cookie: "test_cookie",
57 flowStatus: intf.FlowStatus{
58 Device: "test_device",
59 FlowModType: of.CommandAdd,
60 },
61 },
62 },
63 {
64 name: "ExecuteFlowEvent_del",
65 args: args{
66 cntx: context.Background(),
67 vd: &VoltDevice{
68 SouthBoundID: "test_device_id",
69 FlowDelEventMap: util.NewConcurrentMap(),
70 },
71 cookie: "test_cookie",
72 flowStatus: intf.FlowStatus{
73 Device: "test_device",
74 FlowModType: of.CommandDel,
75 },
76 },
77 },
78 }
79 for _, tt := range tests {
80 t.Run(tt.name, func(t *testing.T) {
81 switch tt.name {
82 case "ExecuteFlowEvent_add":
83 if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
84 t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
85 }
86 case "ExecuteFlowEvent_del":
87 if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
88 t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
89 }
90 }
91 })
92 }
93}
94
95func TestInitEventFuncMapper(t *testing.T) {
96 tests := []struct {
97 name string
98 }{
99 {
100 name: "InitEventFuncMapper",
101 },
102 }
103 for _, tt := range tests {
104 t.Run(tt.name, func(t *testing.T) {
105 InitEventFuncMapper()
106 })
107 }
108}
109
110func TestProcessUsIgmpFlowAddEvent(t *testing.T) {
111 type args struct {
112 cntx context.Context
113 event *FlowEvent
114 flowStatus intf.FlowStatus
115 }
116 tests := []struct {
117 name string
118 args args
119 }{
120 {
121 name: "ProcessUsIgmpFlowAddEvent",
122 args: args{
123 cntx: context.Background(),
124 event: &FlowEvent{
125 device: "test_device",
126 eType: EventTypeControlFlowAdded,
127 eventData: voltPortVnet,
128 },
129 flowStatus: intf.FlowStatus{
130 Device: "test_device",
131 Status: uint32(0),
132 },
133 },
134 },
vinokuma04dc9f82023-07-31 15:47:49 +0530135 {
136 name: "ProcessUsIgmpFlowAddEvent_else_condition",
137 args: args{
138 cntx: context.Background(),
139 event: &FlowEvent{
140 device: "test_device",
141 eType: EventTypeControlFlowAdded,
142 eventData: voltPortVnet,
143 },
144 flowStatus: intf.FlowStatus{
145 Device: "test_device",
146 Status: uint32(1001),
147 },
148 },
149 },
vinokumaf7605fc2023-06-02 18:08:01 +0530150 }
151 for _, tt := range tests {
152 t.Run(tt.name, func(t *testing.T) {
153 ProcessUsIgmpFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
154 })
155 }
156}
157
158func TestProcessServiceFlowAddEvent(t *testing.T) {
159 type args struct {
160 cntx context.Context
161 event *FlowEvent
162 flowStatus intf.FlowStatus
163 }
164
165 tests := []struct {
166 name string
167 args args
168 }{
169 {
170 name: "ProcessServiceFlowAddEvent",
171 args: args{
172 cntx: context.Background(),
173 event: &FlowEvent{
174 device: "test_device",
175 eventData: voltService,
176 },
177 },
178 },
vinokuma04dc9f82023-07-31 15:47:49 +0530179 {
180 name: "ProcessServiceFlowAddEvent_else_condition",
181 args: args{
182 cntx: context.Background(),
183 event: &FlowEvent{
184 device: "test_device",
185 eventData: voltService,
186 },
187 flowStatus: intf.FlowStatus{
188 Status: uint32(1001),
189 },
190 },
191 },
vinokumaf7605fc2023-06-02 18:08:01 +0530192 }
193 for _, tt := range tests {
194 t.Run(tt.name, func(t *testing.T) {
195 ProcessServiceFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
196 })
197 }
198}
199
200func TestProcessControlFlowAddEvent(t *testing.T) {
201 type args struct {
202 cntx context.Context
203 event *FlowEvent
204 flowStatus intf.FlowStatus
205 }
206 tests := []struct {
207 name string
208 args args
209 }{
210 {
211 name: "ProcessControlFlowAddEvent",
212 args: args{
213 cntx: context.Background(),
214 event: &FlowEvent{
215 eventData: voltPortVnet,
216 },
217 },
218 },
vinokuma04dc9f82023-07-31 15:47:49 +0530219 {
220 name: "ProcessControlFlowAddEvent_else_condition",
221 args: args{
222 cntx: context.Background(),
223 event: &FlowEvent{
224 eventData: voltPortVnet,
225 },
226 flowStatus: intf.FlowStatus{
227 Status: uint32(1001),
228 },
229 },
230 },
vinokumaf7605fc2023-06-02 18:08:01 +0530231 }
232 for _, tt := range tests {
233 t.Run(tt.name, func(t *testing.T) {
234 ProcessControlFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
235 })
236 }
237}
238
239func TestProcessServiceFlowDelEvent(t *testing.T) {
240 type args struct {
241 cntx context.Context
242 event *FlowEvent
243 flowStatus intf.FlowStatus
244 }
245 tests := []struct {
246 name string
247 args args
248 }{
249 {
250 name: "ProcessServiceFlowDelEvent",
251 args: args{
252 cntx: context.Background(),
253 event: &FlowEvent{
254 eventData: voltService,
255 },
256 },
257 },
vinokuma04dc9f82023-07-31 15:47:49 +0530258 {
259 name: "ProcessServiceFlowDelEvent_else_condition",
260 args: args{
261 cntx: context.Background(),
262 event: &FlowEvent{
263 eventData: voltService,
264 },
265 flowStatus: intf.FlowStatus{
266 Status: uint32(1001),
267 },
268 },
269 },
vinokumaf7605fc2023-06-02 18:08:01 +0530270 }
271 for _, tt := range tests {
272 t.Run(tt.name, func(t *testing.T) {
273 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
274 db = dbintf
275 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
276 ProcessServiceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
277 })
278 }
279}
280
281func TestProcessControlFlowDelEvent(t *testing.T) {
282 type args struct {
283 cntx context.Context
284 event *FlowEvent
285 flowStatus intf.FlowStatus
286 }
287 tests := []struct {
288 name string
289 args args
290 }{
291 {
292 name: "ProcessControlFlowDelEvent",
293 args: args{
294 cntx: context.Background(),
295 event: &FlowEvent{
296 eventData: voltPortVnet,
297 },
298 },
299 },
vinokuma04dc9f82023-07-31 15:47:49 +0530300 {
301 name: "ProcessControlFlowDelEvent_else_condition",
302 args: args{
303 cntx: context.Background(),
304 event: &FlowEvent{
305 eventData: voltPortVnet,
306 },
307 flowStatus: intf.FlowStatus{
308 Status: uint32(1001),
309 },
310 },
311 },
vinokumaf7605fc2023-06-02 18:08:01 +0530312 }
313 for _, tt := range tests {
314 t.Run(tt.name, func(t *testing.T) {
315 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
316 db = dbintf
317 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
318 ProcessControlFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
319 })
320 }
321}
322
323func TestProcessMcastFlowDelEvent(t *testing.T) {
324 type args struct {
325 cntx context.Context
326 event *FlowEvent
327 flowStatus intf.FlowStatus
328 }
329 mvlanProfile := &MvlanProfile{
330 Version: "test_version",
331 }
332 tests := []struct {
333 name string
334 args args
335 }{
336 {
337 name: "ProcessMcastFlowDelEvent",
338 args: args{
339 cntx: context.Background(),
340 event: &FlowEvent{
341 eventData: mvlanProfile,
342 },
343 },
344 },
vinokuma04dc9f82023-07-31 15:47:49 +0530345 {
346 name: "ProcessMcastFlowDelEvent_else_condition",
347 args: args{
348 cntx: context.Background(),
349 event: &FlowEvent{
350 eventData: mvlanProfile,
351 },
352 flowStatus: intf.FlowStatus{
353 Status: uint32(1001),
354 },
355 },
356 },
vinokumaf7605fc2023-06-02 18:08:01 +0530357 }
358 for _, tt := range tests {
359 t.Run(tt.name, func(t *testing.T) {
360 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
361 db = dbintf
362 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
363 ProcessMcastFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
364 })
365 }
366}
vinokuma04dc9f82023-07-31 15:47:49 +0530367
368func TestProcessDeviceFlowDelEvent(t *testing.T) {
369 type args struct {
370 cntx context.Context
371 event *FlowEvent
372 flowStatus intf.FlowStatus
373 }
374 tests := []struct {
375 name string
376 args args
377 }{
378 {
379 name: "ProcessDeviceFlowDelEvent",
380 args: args{
381 cntx: context.Background(),
382 event: &FlowEvent{
383 device: test_device,
384 eventData: voltVnet,
385 },
386 flowStatus: intf.FlowStatus{
387 Device: test_device,
388 },
389 },
390 },
391 {
392 name: "ProcessDeviceFlowDelEvent_else_condition",
393 args: args{
394 cntx: context.Background(),
395 event: &FlowEvent{
396 device: test_device,
397 eventData: voltVnet,
398 },
399 flowStatus: intf.FlowStatus{
400 Device: test_device,
401 Status: uint32(1001),
402 },
403 },
404 },
405 }
406 for _, tt := range tests {
407 t.Run(tt.name, func(t *testing.T) {
408 switch tt.name {
409 case "ProcessDeviceFlowDelEvent":
410 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
411 db = dbintf
412 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes()
413 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
414 case "ProcessDeviceFlowDelEvent_else_condition":
415 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
416 }
417 })
418 }
419}