blob: 862152175dae9cf2fc656b0a86fa085fa1f5ecb4 [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) {
Akash Sonief452f12024-12-12 18:20:28 +0530153 ProcessUsIgmpFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
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 }
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530165 vs := &VoltService{
Akash Sonief452f12024-12-12 18:20:28 +0530166 VoltServiceCfg: VoltServiceCfg{},
vinokumaf7605fc2023-06-02 18:08:01 +0530167 }
168
169 tests := []struct {
170 name string
171 args args
172 }{
173 {
174 name: "ProcessServiceFlowAddEvent",
175 args: args{
176 cntx: context.Background(),
177 event: &FlowEvent{
178 device: "test_device",
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530179 eventData: vs,
vinokumaf7605fc2023-06-02 18:08:01 +0530180 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530181 flowEventMap: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +0530182 },
183 },
vinokuma04dc9f82023-07-31 15:47:49 +0530184 {
185 name: "ProcessServiceFlowAddEvent_else_condition",
186 args: args{
187 cntx: context.Background(),
188 event: &FlowEvent{
189 device: "test_device",
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530190 eventData: vs,
vinokuma04dc9f82023-07-31 15:47:49 +0530191 },
192 flowStatus: intf.FlowStatus{
193 Status: uint32(1001),
194 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530195 flowEventMap: util.NewConcurrentMap(),
vinokuma04dc9f82023-07-31 15:47:49 +0530196 },
197 },
vinokumaf7605fc2023-06-02 18:08:01 +0530198 }
199 for _, tt := range tests {
200 t.Run(tt.name, func(t *testing.T) {
Akash Sonief452f12024-12-12 18:20:28 +0530201 ProcessServiceFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530202 })
203 }
204}
205
206func TestProcessControlFlowAddEvent(t *testing.T) {
207 type args struct {
208 cntx context.Context
209 event *FlowEvent
210 flowStatus intf.FlowStatus
211 }
212 tests := []struct {
213 name string
214 args args
215 }{
216 {
217 name: "ProcessControlFlowAddEvent",
218 args: args{
219 cntx: context.Background(),
220 event: &FlowEvent{
221 eventData: voltPortVnet,
222 },
223 },
224 },
vinokuma04dc9f82023-07-31 15:47:49 +0530225 {
226 name: "ProcessControlFlowAddEvent_else_condition",
227 args: args{
228 cntx: context.Background(),
229 event: &FlowEvent{
230 eventData: voltPortVnet,
231 },
232 flowStatus: intf.FlowStatus{
233 Status: uint32(1001),
234 },
235 },
236 },
vinokumaf7605fc2023-06-02 18:08:01 +0530237 }
238 for _, tt := range tests {
239 t.Run(tt.name, func(t *testing.T) {
Akash Sonief452f12024-12-12 18:20:28 +0530240 ProcessControlFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530241 })
242 }
243}
244
245func TestProcessServiceFlowDelEvent(t *testing.T) {
246 type args struct {
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530247 cntx context.Context
248 event *FlowEvent
249 flowStatus intf.FlowStatus
250 flowEventMap *util.ConcurrentMap
vinokumaf7605fc2023-06-02 18:08:01 +0530251 }
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530252 vs := &VoltService{
Akash Sonief452f12024-12-12 18:20:28 +0530253 VoltServiceCfg: VoltServiceCfg{},
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530254 }
255
vinokumaf7605fc2023-06-02 18:08:01 +0530256 tests := []struct {
257 name string
258 args args
259 }{
260 {
261 name: "ProcessServiceFlowDelEvent",
262 args: args{
263 cntx: context.Background(),
264 event: &FlowEvent{
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530265 eventData: vs,
vinokumaf7605fc2023-06-02 18:08:01 +0530266 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530267 flowEventMap: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +0530268 },
269 },
vinokuma04dc9f82023-07-31 15:47:49 +0530270 {
271 name: "ProcessServiceFlowDelEvent_else_condition",
272 args: args{
273 cntx: context.Background(),
274 event: &FlowEvent{
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530275 eventData: vs,
vinokuma04dc9f82023-07-31 15:47:49 +0530276 },
277 flowStatus: intf.FlowStatus{
278 Status: uint32(1001),
279 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530280 flowEventMap: util.NewConcurrentMap(),
vinokuma04dc9f82023-07-31 15:47:49 +0530281 },
282 },
vinokumaf7605fc2023-06-02 18:08:01 +0530283 }
284 for _, tt := range tests {
285 t.Run(tt.name, func(t *testing.T) {
286 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
287 db = dbintf
288 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Akash Sonief452f12024-12-12 18:20:28 +0530289 ProcessServiceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530290 })
291 }
292}
293
294func TestProcessControlFlowDelEvent(t *testing.T) {
295 type args struct {
296 cntx context.Context
297 event *FlowEvent
298 flowStatus intf.FlowStatus
299 }
300 tests := []struct {
301 name string
302 args args
303 }{
304 {
305 name: "ProcessControlFlowDelEvent",
306 args: args{
307 cntx: context.Background(),
308 event: &FlowEvent{
309 eventData: voltPortVnet,
310 },
311 },
312 },
vinokuma04dc9f82023-07-31 15:47:49 +0530313 {
314 name: "ProcessControlFlowDelEvent_else_condition",
315 args: args{
316 cntx: context.Background(),
317 event: &FlowEvent{
318 eventData: voltPortVnet,
319 },
320 flowStatus: intf.FlowStatus{
321 Status: uint32(1001),
322 },
323 },
324 },
vinokumaf7605fc2023-06-02 18:08:01 +0530325 }
326 for _, tt := range tests {
327 t.Run(tt.name, func(t *testing.T) {
328 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
329 db = dbintf
330 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Akash Sonief452f12024-12-12 18:20:28 +0530331 ProcessControlFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530332 })
333 }
334}
335
336func TestProcessMcastFlowDelEvent(t *testing.T) {
337 type args struct {
338 cntx context.Context
339 event *FlowEvent
340 flowStatus intf.FlowStatus
341 }
342 mvlanProfile := &MvlanProfile{
343 Version: "test_version",
344 }
345 tests := []struct {
346 name string
347 args args
348 }{
349 {
350 name: "ProcessMcastFlowDelEvent",
351 args: args{
352 cntx: context.Background(),
353 event: &FlowEvent{
354 eventData: mvlanProfile,
355 },
356 },
357 },
vinokuma04dc9f82023-07-31 15:47:49 +0530358 {
359 name: "ProcessMcastFlowDelEvent_else_condition",
360 args: args{
361 cntx: context.Background(),
362 event: &FlowEvent{
363 eventData: mvlanProfile,
364 },
365 flowStatus: intf.FlowStatus{
366 Status: uint32(1001),
367 },
368 },
369 },
vinokumaf7605fc2023-06-02 18:08:01 +0530370 }
371 for _, tt := range tests {
372 t.Run(tt.name, func(t *testing.T) {
373 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
374 db = dbintf
375 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Akash Sonief452f12024-12-12 18:20:28 +0530376 ProcessMcastFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530377 })
378 }
379}
vinokuma04dc9f82023-07-31 15:47:49 +0530380
381func TestProcessDeviceFlowDelEvent(t *testing.T) {
382 type args struct {
383 cntx context.Context
384 event *FlowEvent
385 flowStatus intf.FlowStatus
386 }
387 tests := []struct {
388 name string
389 args args
390 }{
391 {
392 name: "ProcessDeviceFlowDelEvent",
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 },
402 },
403 },
404 {
405 name: "ProcessDeviceFlowDelEvent_else_condition",
406 args: args{
407 cntx: context.Background(),
408 event: &FlowEvent{
409 device: test_device,
410 eventData: voltVnet,
411 },
412 flowStatus: intf.FlowStatus{
413 Device: test_device,
414 Status: uint32(1001),
415 },
416 },
417 },
418 }
419 for _, tt := range tests {
420 t.Run(tt.name, func(t *testing.T) {
421 switch tt.name {
422 case "ProcessDeviceFlowDelEvent":
423 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
424 db = dbintf
425 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes()
Akash Sonief452f12024-12-12 18:20:28 +0530426 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokuma04dc9f82023-07-31 15:47:49 +0530427 case "ProcessDeviceFlowDelEvent_else_condition":
Akash Sonief452f12024-12-12 18:20:28 +0530428 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokuma04dc9f82023-07-31 15:47:49 +0530429 }
430 })
431 }
432}