blob: 6bd5da2a355207fa5765be3ced058185ae9270ce [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) {
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530153 ProcessUsIgmpFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus, nil)
vinokumaf7605fc2023-06-02 18:08:01 +0530154 })
155 }
156}
157
158func TestProcessServiceFlowAddEvent(t *testing.T) {
159 type args struct {
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530160 cntx context.Context
161 event *FlowEvent
162 flowStatus intf.FlowStatus
163 flowEventMap *util.ConcurrentMap
164 }
165
166 flowPushCountMap := make(map[string]uint32)
167 vs := &VoltService{
168 VoltServiceCfg: VoltServiceCfg{
169 FlowPushCount: flowPushCountMap,
170 },
vinokumaf7605fc2023-06-02 18:08:01 +0530171 }
172
173 tests := []struct {
174 name string
175 args args
176 }{
177 {
178 name: "ProcessServiceFlowAddEvent",
179 args: args{
180 cntx: context.Background(),
181 event: &FlowEvent{
182 device: "test_device",
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530183 eventData: vs,
vinokumaf7605fc2023-06-02 18:08:01 +0530184 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530185 flowEventMap: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +0530186 },
187 },
vinokuma04dc9f82023-07-31 15:47:49 +0530188 {
189 name: "ProcessServiceFlowAddEvent_else_condition",
190 args: args{
191 cntx: context.Background(),
192 event: &FlowEvent{
193 device: "test_device",
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530194 eventData: vs,
vinokuma04dc9f82023-07-31 15:47:49 +0530195 },
196 flowStatus: intf.FlowStatus{
197 Status: uint32(1001),
198 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530199 flowEventMap: util.NewConcurrentMap(),
vinokuma04dc9f82023-07-31 15:47:49 +0530200 },
201 },
vinokumaf7605fc2023-06-02 18:08:01 +0530202 }
203 for _, tt := range tests {
204 t.Run(tt.name, func(t *testing.T) {
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530205 ProcessServiceFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus, tt.args.flowEventMap)
vinokumaf7605fc2023-06-02 18:08:01 +0530206 })
207 }
208}
209
210func TestProcessControlFlowAddEvent(t *testing.T) {
211 type args struct {
212 cntx context.Context
213 event *FlowEvent
214 flowStatus intf.FlowStatus
215 }
216 tests := []struct {
217 name string
218 args args
219 }{
220 {
221 name: "ProcessControlFlowAddEvent",
222 args: args{
223 cntx: context.Background(),
224 event: &FlowEvent{
225 eventData: voltPortVnet,
226 },
227 },
228 },
vinokuma04dc9f82023-07-31 15:47:49 +0530229 {
230 name: "ProcessControlFlowAddEvent_else_condition",
231 args: args{
232 cntx: context.Background(),
233 event: &FlowEvent{
234 eventData: voltPortVnet,
235 },
236 flowStatus: intf.FlowStatus{
237 Status: uint32(1001),
238 },
239 },
240 },
vinokumaf7605fc2023-06-02 18:08:01 +0530241 }
242 for _, tt := range tests {
243 t.Run(tt.name, func(t *testing.T) {
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530244 ProcessControlFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus, nil)
vinokumaf7605fc2023-06-02 18:08:01 +0530245 })
246 }
247}
248
249func TestProcessServiceFlowDelEvent(t *testing.T) {
250 type args struct {
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530251 cntx context.Context
252 event *FlowEvent
253 flowStatus intf.FlowStatus
254 flowEventMap *util.ConcurrentMap
vinokumaf7605fc2023-06-02 18:08:01 +0530255 }
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530256
257 flowPushCountMap := make(map[string]uint32)
258 vs := &VoltService{
259 VoltServiceCfg: VoltServiceCfg{
260 FlowPushCount: flowPushCountMap,
261 },
262 }
263
vinokumaf7605fc2023-06-02 18:08:01 +0530264 tests := []struct {
265 name string
266 args args
267 }{
268 {
269 name: "ProcessServiceFlowDelEvent",
270 args: args{
271 cntx: context.Background(),
272 event: &FlowEvent{
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530273 eventData: vs,
vinokumaf7605fc2023-06-02 18:08:01 +0530274 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530275 flowEventMap: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +0530276 },
277 },
vinokuma04dc9f82023-07-31 15:47:49 +0530278 {
279 name: "ProcessServiceFlowDelEvent_else_condition",
280 args: args{
281 cntx: context.Background(),
282 event: &FlowEvent{
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530283 eventData: vs,
vinokuma04dc9f82023-07-31 15:47:49 +0530284 },
285 flowStatus: intf.FlowStatus{
286 Status: uint32(1001),
287 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530288 flowEventMap: util.NewConcurrentMap(),
vinokuma04dc9f82023-07-31 15:47:49 +0530289 },
290 },
vinokumaf7605fc2023-06-02 18:08:01 +0530291 }
292 for _, tt := range tests {
293 t.Run(tt.name, func(t *testing.T) {
294 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
295 db = dbintf
296 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530297 ProcessServiceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus, tt.args.flowEventMap)
vinokumaf7605fc2023-06-02 18:08:01 +0530298 })
299 }
300}
301
302func TestProcessControlFlowDelEvent(t *testing.T) {
303 type args struct {
304 cntx context.Context
305 event *FlowEvent
306 flowStatus intf.FlowStatus
307 }
308 tests := []struct {
309 name string
310 args args
311 }{
312 {
313 name: "ProcessControlFlowDelEvent",
314 args: args{
315 cntx: context.Background(),
316 event: &FlowEvent{
317 eventData: voltPortVnet,
318 },
319 },
320 },
vinokuma04dc9f82023-07-31 15:47:49 +0530321 {
322 name: "ProcessControlFlowDelEvent_else_condition",
323 args: args{
324 cntx: context.Background(),
325 event: &FlowEvent{
326 eventData: voltPortVnet,
327 },
328 flowStatus: intf.FlowStatus{
329 Status: uint32(1001),
330 },
331 },
332 },
vinokumaf7605fc2023-06-02 18:08:01 +0530333 }
334 for _, tt := range tests {
335 t.Run(tt.name, func(t *testing.T) {
336 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
337 db = dbintf
338 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530339 ProcessControlFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus, nil)
vinokumaf7605fc2023-06-02 18:08:01 +0530340 })
341 }
342}
343
344func TestProcessMcastFlowDelEvent(t *testing.T) {
345 type args struct {
346 cntx context.Context
347 event *FlowEvent
348 flowStatus intf.FlowStatus
349 }
350 mvlanProfile := &MvlanProfile{
351 Version: "test_version",
352 }
353 tests := []struct {
354 name string
355 args args
356 }{
357 {
358 name: "ProcessMcastFlowDelEvent",
359 args: args{
360 cntx: context.Background(),
361 event: &FlowEvent{
362 eventData: mvlanProfile,
363 },
364 },
365 },
vinokuma04dc9f82023-07-31 15:47:49 +0530366 {
367 name: "ProcessMcastFlowDelEvent_else_condition",
368 args: args{
369 cntx: context.Background(),
370 event: &FlowEvent{
371 eventData: mvlanProfile,
372 },
373 flowStatus: intf.FlowStatus{
374 Status: uint32(1001),
375 },
376 },
377 },
vinokumaf7605fc2023-06-02 18:08:01 +0530378 }
379 for _, tt := range tests {
380 t.Run(tt.name, func(t *testing.T) {
381 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
382 db = dbintf
383 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530384 ProcessMcastFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus, nil)
vinokumaf7605fc2023-06-02 18:08:01 +0530385 })
386 }
387}
vinokuma04dc9f82023-07-31 15:47:49 +0530388
389func TestProcessDeviceFlowDelEvent(t *testing.T) {
390 type args struct {
391 cntx context.Context
392 event *FlowEvent
393 flowStatus intf.FlowStatus
394 }
395 tests := []struct {
396 name string
397 args args
398 }{
399 {
400 name: "ProcessDeviceFlowDelEvent",
401 args: args{
402 cntx: context.Background(),
403 event: &FlowEvent{
404 device: test_device,
405 eventData: voltVnet,
406 },
407 flowStatus: intf.FlowStatus{
408 Device: test_device,
409 },
410 },
411 },
412 {
413 name: "ProcessDeviceFlowDelEvent_else_condition",
414 args: args{
415 cntx: context.Background(),
416 event: &FlowEvent{
417 device: test_device,
418 eventData: voltVnet,
419 },
420 flowStatus: intf.FlowStatus{
421 Device: test_device,
422 Status: uint32(1001),
423 },
424 },
425 },
426 }
427 for _, tt := range tests {
428 t.Run(tt.name, func(t *testing.T) {
429 switch tt.name {
430 case "ProcessDeviceFlowDelEvent":
431 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
432 db = dbintf
433 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes()
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530434 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus, nil)
vinokuma04dc9f82023-07-31 15:47:49 +0530435 case "ProcessDeviceFlowDelEvent_else_condition":
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530436 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus, nil)
vinokuma04dc9f82023-07-31 15:47:49 +0530437 }
438 })
439 }
440}