blob: 7d9223021b41c40e77740d825669989c8fa4553b [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 "encoding/json"
21 "net"
22 "reflect"
23 "sync"
24 "testing"
vinokuma04dc9f82023-07-31 15:47:49 +053025 "time"
vinokumaf7605fc2023-06-02 18:08:01 +053026 "voltha-go-controller/internal/pkg/controller"
27 "voltha-go-controller/internal/pkg/intf"
28 "voltha-go-controller/internal/pkg/of"
29 "voltha-go-controller/internal/pkg/util"
30 "voltha-go-controller/internal/test/mocks"
31
32 "github.com/golang/mock/gomock"
33 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
34 "github.com/stretchr/testify/assert"
35 "go.uber.org/atomic"
36)
37
vinokuma02fbfd02023-07-05 15:23:33 +053038var test_data = "1234"
39
vinokumaf7605fc2023-06-02 18:08:01 +053040func TestVoltApplication_RestoreNbDeviceFromDb(t *testing.T) {
41 type args struct {
42 cntx context.Context
43 deviceID string
44 }
45 tests := []struct {
46 name string
47 args args
48 }{
49 {
50 name: "VoltApplication_RestoreNbDeviceFromDb",
51 args: args{
52 cntx: context.Background(),
53 deviceID: "test_device_id",
54 },
55 },
56 {
57 name: "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type",
58 args: args{
59 cntx: context.Background(),
60 deviceID: "test_device_id1",
61 },
62 },
63 {
64 name: "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error",
65 args: args{
66 cntx: context.Background(),
67 deviceID: "test_device_id1",
68 },
69 },
70 }
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 va := &VoltApplication{
74 NbDevice: sync.Map{},
75 }
76 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
77 db = dbintf
78 switch tt.name {
79 case "VoltApplication_RestoreNbDeviceFromDb":
80 var port PonPortCfg
81 port = PonPortCfg{
82 PortAlarmProfileID: "test",
83 PortID: 256,
84 MaxActiveChannels: 256,
85 ActiveIGMPChannels: 7679,
86 EnableMulticastKPI: false,
87 }
88 b, err := json.Marshal(port)
89 if err != nil {
90 panic(err)
91 }
92 test := map[string]*kvstore.KVPair{}
93 test["test_device_id"] = &kvstore.KVPair{
94 Key: "test_device_id",
95 Value: b,
96 }
97 dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
98 got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
99 assert.NotNil(t, got)
100 case "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type":
101 test := map[string]*kvstore.KVPair{}
102 test["test_device_id"] = &kvstore.KVPair{
103 Key: "test_device_id",
vinokuma703a70b2023-07-17 10:06:43 +0530104 Value: invalid_value,
vinokumaf7605fc2023-06-02 18:08:01 +0530105 }
106 dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
107 got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
108 assert.NotNil(t, got)
109 case "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error":
110 b, err := json.Marshal("error")
111 if err != nil {
112 panic(err)
113 }
114 test := map[string]*kvstore.KVPair{}
115 test["test_device_id"] = &kvstore.KVPair{
116 Key: "test_device_id",
117 Value: b,
118 }
119 dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1)
120 got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID)
121 assert.NotNil(t, got)
122 }
123 })
124 }
125}
126
127func TestVoltApplication_UpdateDeviceConfig(t *testing.T) {
128 type args struct {
129 cntx context.Context
130 deviceConfig *DeviceConfig
131 }
132
133 dvcConfg := &DeviceConfig{
134 SerialNumber: "SDX6320031",
135 HardwareIdentifier: "0.0.0.0",
136 IPAddress: "127.26.1.74",
137 UplinkPort: "43322",
138 NasID: "12345",
139 NniDhcpTrapVid: 123,
140 }
141
142 voltDev := &VoltDevice{
143 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
144 SerialNum: "SDX6320031",
145 NniDhcpTrapVid: 123,
146 }
147 tests := []struct {
148 name string
149 args args
150 }{
151 {
152 name: "SDX6320031",
153 args: args{
154 cntx: context.Background(),
155 deviceConfig: dvcConfg,
156 },
157 },
158 }
159
160 for _, tt := range tests {
161 t.Run(tt.name, func(t *testing.T) {
162 va := &VoltApplication{
163 DevicesDisc: sync.Map{},
164 DevicesConfig: sync.Map{},
165 }
166 va.DevicesDisc.Store("SDX6320031", voltDev)
167 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
168 db = dbintf
169 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
170
171 va.UpdateDeviceConfig(tt.args.cntx, tt.args.deviceConfig)
172 })
173 }
174}
175
176func TestVoltApplication_RestoreOltFlowService(t *testing.T) {
177 type fields struct {
178 OltFlowServiceConfig OltFlowService
179 }
180 type args struct {
181 cntx context.Context
182 }
183 tests := []struct {
184 name string
185 fields fields
186 args args
187 }{
188 {
189 name: "OltFlowService",
190 args: args{
191 cntx: context.Background(),
192 },
193 fields: fields{
194 OltFlowServiceConfig: OltFlowService{
195 DefaultTechProfileID: 1233,
196 EnableDhcpOnNni: true,
197 EnableIgmpOnNni: false,
198 RemoveFlowsOnDisable: false,
199 },
200 },
201 },
202 }
203 for _, tt := range tests {
204 t.Run(tt.name, func(t *testing.T) {
205 va := &VoltApplication{
206 OltFlowServiceConfig: tt.fields.OltFlowServiceConfig,
207 }
208
209 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
210 db = dbintf
211 dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes()
212
213 va.RestoreOltFlowService(tt.args.cntx)
214 })
215 }
216}
217
218func TestVoltApplication_UpdateOltFlowService(t *testing.T) {
219 type fields struct {
220 OltFlowServiceConfig OltFlowService
221 }
222 type args struct {
223 cntx context.Context
224 oltFlowService OltFlowService
225 }
226 tests := []struct {
227 name string
228 fields fields
229 args args
230 }{
231 {
232 name: "OltFlowService",
233 args: args{
234 cntx: context.Background(),
235 oltFlowService: OltFlowService{
236 DefaultTechProfileID: 1233,
237 EnableDhcpOnNni: true,
238 EnableIgmpOnNni: false,
239 RemoveFlowsOnDisable: false,
240 },
241 },
242 fields: fields{
243 OltFlowServiceConfig: OltFlowService{
244 DefaultTechProfileID: 1233,
245 EnableDhcpOnNni: true,
246 EnableIgmpOnNni: false,
247 RemoveFlowsOnDisable: false,
248 },
249 },
250 },
251 }
252 for _, tt := range tests {
253 t.Run(tt.name, func(t *testing.T) {
254 va := &VoltApplication{
255 OltFlowServiceConfig: tt.fields.OltFlowServiceConfig,
256 }
257
258 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
259 db = dbintf
260 dbintf.EXPECT().PutOltFlowService(gomock.Any(), gomock.Any()).AnyTimes()
261 va.UpdateOltFlowService(tt.args.cntx, tt.args.oltFlowService)
262 })
263 }
264}
265
266func TestVoltApplication_TriggerPendingVpvDeleteReq(t *testing.T) {
267 type args struct {
268 cntx context.Context
269 device string
270 }
271 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
272 test := map[*VoltPortVnet]bool{}
273 test[&VoltPortVnet{Device: "SDX6320031", Port: "16777472", MacAddr: macAdd}] = true
274 tests := []struct {
275 name string
276 args args
277 }{
278 {
279 name: "SDX6320031",
280 args: args{
281 cntx: context.Background(),
282 device: "SDX6320031",
283 },
284 },
285 }
286 for _, tt := range tests {
287 t.Run(tt.name, func(t *testing.T) {
288 va := &VoltApplication{
289 VoltPortVnetsToDelete: test,
290 }
291 va.TriggerPendingVpvDeleteReq(tt.args.cntx, tt.args.device)
292 })
293 }
294}
295
296func TestVoltApplication_TriggerPendingProfileDeleteReq(t *testing.T) {
297 type args struct {
298 cntx context.Context
299 device string
300 }
301 tests := []struct {
302 name string
303 args args
304 }{
305 {
306 name: "SDX6320031",
307 args: args{
308 cntx: context.Background(),
309 device: "SDX6320031",
310 },
311 },
312 }
313 for _, tt := range tests {
314 t.Run(tt.name, func(t *testing.T) {
315 va := &VoltApplication{
316 DevicesDisc: sync.Map{},
317 }
318 va.TriggerPendingProfileDeleteReq(tt.args.cntx, tt.args.device)
319 })
320 }
321}
322
323func TestVoltApplication_TriggerPendingServiceDeleteReq(t *testing.T) {
324 type args struct {
325 cntx context.Context
326 device string
327 }
328 voltServ := &VoltService{
329 VoltServiceOper: VoltServiceOper{
330 Device: "SDX6320031",
331 ForceDelete: true,
332 },
333 }
334
335 servicesToDel := map[string]bool{}
336 servicesToDel["SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65"] = true
337
338 tests := []struct {
339 name string
340 args args
341 }{
342 {
343 name: "Positive_Case_TriggerPendingServiceDeleteReq",
344 args: args{
345 cntx: context.Background(),
346 device: "SDX6320031",
347 },
348 },
349 }
350 for _, tt := range tests {
351 t.Run(tt.name, func(t *testing.T) {
352 va := &VoltApplication{
353 ServicesToDelete: servicesToDel,
354 ServiceByName: sync.Map{},
355 DevicesDisc: sync.Map{},
356 }
357
358 va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
359
360 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
361 db = dbintf
362 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
363 dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes()
364 va.TriggerPendingServiceDeleteReq(tt.args.cntx, tt.args.device)
365 })
366 }
367}
368
369func TestVoltApplication_TriggerPendingVnetDeleteReq(t *testing.T) {
370 type args struct {
371 cntx context.Context
372 device string
373 }
374
375 vnetToDel := map[string]bool{}
376 vnetToDel["2310-4096-4096"] = true
377
378 voltVnet := &VoltVnet{
379 Version: "v3",
380 VnetConfig: VnetConfig{
381 Name: "2310-4096-4096",
382 VnetType: "Encapsulation",
383 SVlan: 2310,
384 CVlan: 4096,
385 UniVlan: 4096,
386 SVlanTpid: 33024,
387 },
388 VnetOper: VnetOper{
389 PendingDeviceToDelete: "SDX63200313",
390 },
391 }
392 voltDev := &VoltDevice{
393 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
394 SerialNum: "SDX6320031",
395 NniDhcpTrapVid: 123,
396 }
397
398 tests := []struct {
399 name string
400 args args
401 }{
402 {
403 name: "Negative_Case_TriggerPendingVnetDeleteReq",
404 args: args{
405 cntx: context.Background(),
406 device: "SDX6320031",
407 },
408 },
409 }
410 for _, tt := range tests {
411 t.Run(tt.name, func(t *testing.T) {
412 va := &VoltApplication{
413 VnetsToDelete: vnetToDel,
414 DevicesDisc: sync.Map{},
415 }
416 va.DevicesDisc.Store("SDX6320031", voltDev)
417 va.VnetsByName.Store("2310-4096-4096", voltVnet)
418 va.TriggerPendingVnetDeleteReq(tt.args.cntx, tt.args.device)
419 })
420 }
421}
422
423func TestVoltApplication_UpdateMacInPortMap(t *testing.T) {
424 type args struct {
425 macAddr net.HardwareAddr
426 port string
427 }
428 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
429 macPort := map[string]string{}
vinokuma02fbfd02023-07-05 15:23:33 +0530430 macPort[macAdd.String()] = test_data
vinokumaf7605fc2023-06-02 18:08:01 +0530431 tests := []struct {
432 name string
433 args args
434 }{
435 {
436 name: "Positive_Case_UpdateMacInPortMap",
437 args: args{
438 macAddr: macAdd,
vinokuma02fbfd02023-07-05 15:23:33 +0530439 port: test_data,
vinokumaf7605fc2023-06-02 18:08:01 +0530440 },
441 },
442 }
443 for _, tt := range tests {
444 t.Run(tt.name, func(t *testing.T) {
445 va := &VoltApplication{
446 macPortMap: macPort,
447 }
448 va.UpdateMacInPortMap(tt.args.macAddr, tt.args.port)
449 })
450 }
451}
452
453func TestVoltApplication_GetMacInPortMap(t *testing.T) {
454 type args struct {
455 macAddr net.HardwareAddr
456 }
457 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
458 macPort := map[string]string{}
vinokuma02fbfd02023-07-05 15:23:33 +0530459 macPort[macAdd.String()] = test_data
vinokumaf7605fc2023-06-02 18:08:01 +0530460 tests := []struct {
461 name string
462 args args
463 want string
464 }{
465 {
466 name: "Positive_Case_GetMacInPortMap",
467 args: args{
468 macAddr: macAdd,
469 },
vinokuma02fbfd02023-07-05 15:23:33 +0530470 want: test_data,
vinokumaf7605fc2023-06-02 18:08:01 +0530471 },
472 }
473 for _, tt := range tests {
474 t.Run(tt.name, func(t *testing.T) {
475 va := &VoltApplication{
476 macPortMap: macPort,
477 }
478 if got := va.GetMacInPortMap(tt.args.macAddr); got != tt.want {
479 t.Errorf("VoltApplication.GetMacInPortMap() = %v, want %v", got, tt.want)
480 }
481 })
482 }
483}
484
485func Test_pushFlowFailureNotif(t *testing.T) {
486 type args struct {
487 flowStatus intf.FlowStatus
488 }
489 tests := []struct {
490 name string
491 args args
492 }{
493 {
494 name: "Positive_Case_pushFlowFailureNotif",
495 args: args{
496 flowStatus: intf.FlowStatus{
497 Device: "SDX6320031",
498 Cookie: "68786618880",
499 Status: 0,
500 Flow: &of.VoltSubFlow{
501 Cookie: 68786618880,
502 TableID: 0,
503 Priority: 100,
504 ErrorReason: "",
505 OldCookie: 0,
506 },
507 },
508 },
509 },
510 }
511 for _, tt := range tests {
512 t.Run(tt.name, func(t *testing.T) {
513 pushFlowFailureNotif(tt.args.flowStatus)
514 })
515 }
516}
517
518func TestGetPonPortIDFromUNIPort(t *testing.T) {
519 type args struct {
520 uniPortID uint32
521 }
522 tests := []struct {
523 name string
524 args args
525 want uint32
526 }{
527 {
528 name: "Positive_Case_pushFlowFailureNotif",
529 args: args{
530 uniPortID: 1049600,
531 },
532 want: 1,
533 },
534 }
535 for _, tt := range tests {
536 t.Run(tt.name, func(t *testing.T) {
537 if got := GetPonPortIDFromUNIPort(tt.args.uniPortID); got != tt.want {
538 t.Errorf("GetPonPortIDFromUNIPort() = %v, want %v", got, tt.want)
539 }
540 })
541 }
542}
543
544func TestVoltApplication_ProcessFlowModResultIndication(t *testing.T) {
545 type args struct {
546 cntx context.Context
547 flowStatus intf.FlowStatus
548 }
549 voltDev := &VoltDevice{
550 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
551 SerialNum: "SDX6320031",
552 NniDhcpTrapVid: 123,
553 FlowAddEventMap: util.NewConcurrentMap(),
554 }
555 flowState := intf.FlowStatus{
556 Device: "SDX6320031",
557 Cookie: "68786618880",
558 Status: 1005,
559 FlowModType: 0,
560 Flow: &of.VoltSubFlow{
561 Cookie: 68786618880,
562 OldCookie: 0,
563 TableID: 0,
564 State: 0,
565 Priority: 100,
566 },
567 }
568 flowAddEvent := map[string]*FlowEvent{}
569 flowEvent := &FlowEvent{
570 device: "SDX6320031",
571 cookie: "68786618880",
572 eType: EventTypeControlFlowAdded,
573 }
574 flowAddEvent["68786618880"] = flowEvent
575 voltDev.FlowAddEventMap.Set("6878661888", flowEvent)
576 tests := []struct {
577 name string
578 args args
579 }{
580 {
581 name: "Positive_Case_ProcessFlowModResultIndication",
582 args: args{
583 cntx: context.Background(),
584 flowStatus: flowState,
585 },
586 },
587 {
588 name: "Negetive_Case_ProcessFlowModResultIndication",
589 args: args{
590 cntx: context.Background(),
591 flowStatus: flowState,
592 },
593 },
594 }
595 for _, tt := range tests {
596 t.Run(tt.name, func(t *testing.T) {
597 va := &VoltApplication{
598 DevicesDisc: sync.Map{},
599 }
600 switch tt.name {
601 case "Positive_Case_ProcessFlowModResultIndication":
602 va.DevicesDisc.Store("SDX6320031", voltDev)
603 va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus)
604 case "Negetive_Case_ProcessFlowModResultIndication":
605 va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus)
606 }
607 })
608 }
609}
610func Test_getPendingPoolKey(t *testing.T) {
611 type args struct {
612 mvlan of.VlanType
613 device string
614 }
615
616 tests := []struct {
617 name string
618 args args
619 want string
620 }{
621 {
622 name: "Positive_Case_getPendingPoolKey",
623 args: args{
624 mvlan: of.VlanAny,
625 device: "SDX6320031",
626 },
627 want: "4096_SDX6320031",
628 },
629 }
630 for _, tt := range tests {
631 t.Run(tt.name, func(t *testing.T) {
632 if got := getPendingPoolKey(tt.args.mvlan, tt.args.device); got != tt.want {
633 t.Errorf("getPendingPoolKey() = %v, want %v", got, tt.want)
634 }
635 })
636 }
637}
638
639func TestNewVoltPort(t *testing.T) {
640 type args struct {
641 device string
642 name string
643 id uint32
644 }
645
646 voltPort := &VoltPort{
647 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
648 Device: "SDX6320031",
649 ID: 16777472,
650 State: PortStateDown,
651 ChannelPerSubAlarmRaised: false,
652 Type: VoltPortTypeNni,
653 }
654
655 voltPort1 := &VoltPort{
656 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
657 Device: "SDX6320031",
658 ID: 1049600,
659 State: PortStateDown,
660 ChannelPerSubAlarmRaised: false,
661 PonPort: GetPonPortIDFromUNIPort(1049600),
662 }
663 tests := []struct {
664 name string
665 args args
666 want *VoltPort
667 }{
668 {
669 name: "Positive_Case_TestNewVoltPort",
670 args: args{
671 id: 16777472,
672 device: "SDX6320031",
673 name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
674 },
675 want: voltPort,
676 },
677 {
678 name: "Positive_Case2_TestNewVoltPort",
679 args: args{
680 id: 1049600,
681 device: "SDX6320031",
682 name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
683 },
684 want: voltPort1,
685 },
686 }
687 for _, tt := range tests {
688 t.Run(tt.name, func(t *testing.T) {
689 switch tt.name {
690 case "Positive_Case_TestNewVoltPort":
691 if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) {
692 t.Errorf("NewVoltPort() = %v, want %v", got, tt.want)
693 }
694 case "Positive_Case2_TestNewVoltPort":
695 if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) {
696 t.Errorf("NewVoltPort() = %v, want %v", got, tt.want)
697 }
698 }
699 })
700 }
701}
702
703func TestVoltPort_SetPortID(t *testing.T) {
704 type args struct {
705 id uint32
706 }
707 tests := []struct {
708 name string
709 args args
710 }{
711 {
712 name: "Positive_Case_TestNewVoltPort",
713 args: args{
714 id: 16777472,
715 },
716 },
717 }
718 for _, tt := range tests {
719 t.Run(tt.name, func(t *testing.T) {
720 vp := &VoltPort{
721 ID: 16777472,
722 Type: VoltPortTypeNni,
723 }
724 vp.SetPortID(tt.args.id)
725 })
726 }
727}
728
729func TestNewVoltDevice(t *testing.T) {
730 type args struct {
731 name string
732 slno string
733 southBoundID string
734 }
735
736 devConfig := &DeviceConfig{
737 SerialNumber: "SDX6320033",
738 NniDhcpTrapVid: 4,
739 }
740 voltDevice := &VoltDevice{
741 Name: "11c3175b-50f3-4220-9555-93df733ded1d",
742 SerialNum: "SDX6320033",
743 SouthBoundID: "68580342-6b3e-57cb-9ea4-06125594e330",
744 State: controller.DeviceStateDOWN,
745 NniPort: "",
746 icmpv6GroupAdded: false,
747 IgmpDsFlowAppliedForMvlan: make(map[uint16]bool),
748 ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
749 MigratingServices: util.NewConcurrentMap(),
750 VpvsBySvlan: util.NewConcurrentMap(),
751 FlowAddEventMap: util.NewConcurrentMap(),
752 FlowDelEventMap: util.NewConcurrentMap(),
753 GlobalDhcpFlowAdded: false,
754 NniDhcpTrapVid: 4,
755 }
756
757 GetApplication().DevicesConfig.Store("SDX6320033", devConfig)
758 tests := []struct {
759 name string
760 args args
761 want *VoltDevice
762 }{
763 {
764 name: "Positive_Case_TestNewVoltDevice",
765 args: args{
766 name: "11c3175b-50f3-4220-9555-93df733ded1d",
767 slno: "SDX6320033",
768 southBoundID: "68580342-6b3e-57cb-9ea4-06125594e330",
769 },
770 want: voltDevice,
771 },
772 }
773 for _, tt := range tests {
774 t.Run(tt.name, func(t *testing.T) {
775 if got := NewVoltDevice(tt.args.name, tt.args.slno, tt.args.southBoundID); !reflect.DeepEqual(got, tt.want) {
776 t.Errorf("NewVoltDevice() = %v, want %v", got, tt.want)
777 }
778 })
779 }
780}
781
782func TestVoltApplication_GetAssociatedVpvsForDevice(t *testing.T) {
783 type args struct {
784 device string
785 svlan of.VlanType
786 }
787
788 voltDev := &VoltDevice{
789 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
790 SerialNum: "SDX6320033",
791 NniDhcpTrapVid: 123,
792 VpvsBySvlan: util.NewConcurrentMap(),
793 }
794
795 cuncurrentMap := &util.ConcurrentMap{
796 Count: atomic.NewUint64(0),
797 }
798
799 voltDev1 := &VoltDevice{
800 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
801 SerialNum: "SDX6320033",
802 NniDhcpTrapVid: 123,
803 VpvsBySvlan: cuncurrentMap,
804 }
805 tests := []struct {
806 name string
807 args args
808 want *util.ConcurrentMap
809 }{
810 {
811 name: "Positive_Case_GetAssociatedVpvsForDevice",
812 args: args{
813 device: "SDX6320033",
814 svlan: of.VlanAny,
815 },
816 want: util.NewConcurrentMap(),
817 },
818 {
819 name: "Positive_Case2_GetAssociatedVpvsForDevice",
820 args: args{
821 device: "SDX6320033",
822 svlan: of.VlanAny,
823 },
824 want: cuncurrentMap,
825 },
826 {
827 name: "Negetive_Case2_GetAssociatedVpvsForDevice",
828 args: args{
829 device: "SDX6320031",
830 svlan: of.VlanAny,
831 },
832 want: nil,
833 },
834 }
835 for _, tt := range tests {
836 t.Run(tt.name, func(t *testing.T) {
837 switch tt.name {
838 case "Positive_Case_GetAssociatedVpvsForDevice":
839 va := &VoltApplication{
840 DevicesDisc: sync.Map{},
841 VnetsBySvlan: util.NewConcurrentMap(),
842 }
843 va.DevicesDisc.Store("SDX6320033", voltDev)
844 if got := va.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
845 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
846 }
847 case "Positive_Case2_GetAssociatedVpvsForDevice":
848 va1 := &VoltApplication{
849 DevicesDisc: sync.Map{},
850 VnetsBySvlan: cuncurrentMap,
851 }
852 va1.DevicesDisc.Store("SDX6320033", voltDev1)
853 va1.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
854 if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
855 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
856 }
857 case "Negetive_Case2_GetAssociatedVpvsForDevice":
858 va1 := &VoltApplication{
859 DevicesDisc: sync.Map{},
860 }
861 if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) {
862 t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want)
863 }
864 }
865 })
866 }
867}
868
869func TestVoltApplication_AssociateVpvsToDevice(t *testing.T) {
870 type args struct {
871 device string
872 vpv *VoltPortVnet
873 }
874
875 vpv := &VoltPortVnet{
876 Device: "SDX6320033",
877 SVlan: of.VlanAny,
878 }
879 voltDev := &VoltDevice{
880 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
881 SerialNum: "SDX6320033",
882 NniDhcpTrapVid: 123,
883 VpvsBySvlan: util.NewConcurrentMap(),
884 }
885 tests := []struct {
886 name string
887 args args
888 }{
889 {
890 name: "Positive_Case_AssociateVpvsToDevice",
891 args: args{
892 device: "SDX6320033",
893 vpv: vpv,
894 },
895 },
896 {
897 name: "Negetive_Case_AssociateVpvsToDevice",
898 args: args{
899 device: "SDX6320033",
900 vpv: vpv,
901 },
902 },
903 }
904 for _, tt := range tests {
905 t.Run(tt.name, func(t *testing.T) {
906 switch tt.name {
907 case "Positive_Case_AssociateVpvsToDevice":
908 va := &VoltApplication{
909 DevicesDisc: sync.Map{},
910 VnetsBySvlan: util.NewConcurrentMap(),
911 }
912 va.DevicesDisc.Store("SDX6320033", voltDev)
913 va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv)
914 case "Negetive_Case_AssociateVpvsToDevice":
915 va := &VoltApplication{
916 DevicesDisc: sync.Map{},
917 VnetsBySvlan: util.NewConcurrentMap(),
918 }
919 va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv)
920 }
921 })
922 }
923}
924
925func TestVoltApplication_DisassociateVpvsFromDevice(t *testing.T) {
926 type args struct {
927 device string
928 vpv *VoltPortVnet
929 }
930 vpv := &VoltPortVnet{
931 Device: "SDX6320033",
932 SVlan: of.VlanAny,
933 }
934
935 voltDev := &VoltDevice{
936 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
937 SerialNum: "SDX6320033",
938 NniDhcpTrapVid: 123,
939 VpvsBySvlan: util.NewConcurrentMap(),
940 }
941 tests := []struct {
942 name string
943 args args
944 }{
945 {
946 name: "Positive_Case_DisassociateVpvsFromDevice",
947 args: args{
948 device: "SDX6320033",
949 vpv: vpv,
950 },
951 },
952 {
953 name: "Negetive_Case_DisassociateVpvsFromDevice",
954 args: args{
955 device: "SDX6320033",
956 vpv: vpv,
957 },
958 },
959 }
960 for _, tt := range tests {
961 t.Run(tt.name, func(t *testing.T) {
962 switch tt.name {
963 case "Positive_Case_DisassociateVpvsFromDevice":
964 va := &VoltApplication{
965 DevicesDisc: sync.Map{},
966 VnetsBySvlan: util.NewConcurrentMap(),
967 }
968 va.DevicesDisc.Store("SDX6320033", voltDev)
969 va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv)
970 case "Negetive_Case_DisassociateVpvsFromDevice":
971 va := &VoltApplication{
972 DevicesDisc: sync.Map{},
973 VnetsBySvlan: util.NewConcurrentMap(),
974 }
975 va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv)
976 }
977 })
978 }
979}
980
981func TestVoltDevice_GetPort(t *testing.T) {
982 type args struct {
983 port string
984 }
985 voltPort := &VoltPort{
986 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
987 Device: "SDX6320031",
988 ID: 16777472,
989 State: PortStateDown,
990 ChannelPerSubAlarmRaised: false,
991 Type: VoltPortTypeNni,
992 }
993 tests := []struct {
994 name string
995 args args
996 want *VoltPort
997 }{
998 {
999 name: "Positive_Case_GetPort",
1000 args: args{
1001 port: "16777472",
1002 },
1003 want: voltPort,
1004 },
1005 {
1006 name: "Negetive_Case_GetPort",
1007 args: args{
1008 port: "16777472",
1009 },
1010 want: nil,
1011 },
1012 }
1013 for _, tt := range tests {
1014 t.Run(tt.name, func(t *testing.T) {
1015 d := &VoltDevice{
1016 Ports: sync.Map{},
1017 }
1018 switch tt.name {
1019 case "Positive_Case_GetPort":
1020 d.Ports.Store("16777472", voltPort)
1021 if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) {
1022 t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want)
1023 }
1024 case "Negetive_Case_GetPort":
1025 if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) {
1026 t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want)
1027 }
1028 }
1029 })
1030 }
1031}
1032
1033func TestVoltDevice_GetPortNameFromPortID(t *testing.T) {
1034 type args struct {
1035 portID uint32
1036 }
1037 voltPort := &VoltPort{
1038 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1039 Device: "SDX6320031",
1040 ID: 16777472,
1041 State: PortStateDown,
1042 ChannelPerSubAlarmRaised: false,
1043 Type: VoltPortTypeNni,
1044 }
1045 tests := []struct {
1046 name string
1047 args args
1048 want string
1049 }{
1050 {
1051 name: "Positive_Case_GetPort",
1052 args: args{
1053 portID: 16777472,
1054 },
1055 want: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1056 },
1057 }
1058 for _, tt := range tests {
1059 t.Run(tt.name, func(t *testing.T) {
1060 d := &VoltDevice{
1061 Ports: sync.Map{},
1062 }
1063 d.Ports.Store(16777472, voltPort)
1064 if got := d.GetPortNameFromPortID(tt.args.portID); got != tt.want {
1065 t.Errorf("VoltDevice.GetPortNameFromPortID() = %v, want %v", got, tt.want)
1066 }
1067 })
1068 }
1069}
1070
1071func TestVoltDevice_DelPort(t *testing.T) {
1072 type args struct {
1073 port string
1074 }
1075 voltPort := &VoltPort{
1076 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1077 Device: "SDX6320031",
1078 ID: 16777472,
1079 State: PortStateDown,
1080 ChannelPerSubAlarmRaised: false,
1081 Type: VoltPortTypeNni,
1082 }
1083 tests := []struct {
1084 name string
1085 args args
1086 }{
1087 {
1088 name: "Positive_Case_DelPort",
1089 args: args{
1090 port: "16777472",
1091 },
1092 },
1093 {
1094 name: "Negetive_Case_DelPort",
1095 args: args{
1096 port: "16777472",
1097 },
1098 },
1099 }
1100 for _, tt := range tests {
1101 t.Run(tt.name, func(t *testing.T) {
1102 d := &VoltDevice{
1103 Ports: sync.Map{},
1104 }
1105 switch tt.name {
1106 case "Positive_Case_DelPort":
1107 d.Ports.Store("16777472", voltPort)
1108 d.DelPort(tt.args.port)
1109 case "Negetive_Case_DelPort":
1110 d.DelPort(tt.args.port)
1111 }
1112 })
1113 }
1114}
1115
1116func TestVoltDevice_pushFlowsForUnis(t *testing.T) {
1117 type args struct {
1118 cntx context.Context
1119 }
1120 tests := []struct {
1121 name string
1122 args args
1123 }{
1124 {
1125 name: "Positive_Case_pushFlowsForUnis",
1126 args: args{
1127 cntx: context.Background(),
1128 },
1129 },
1130 {
1131 name: "Negetive_Case_pushFlowsForUnis",
1132 args: args{
1133 cntx: context.Background(),
1134 },
1135 },
1136 {
1137 name: "Negetive_Case1_pushFlowsForUnis",
1138 args: args{
1139 cntx: context.Background(),
1140 },
1141 },
1142 }
1143 for _, tt := range tests {
1144 t.Run(tt.name, func(t *testing.T) {
1145 d := &VoltDevice{
1146 Name: "SDX6320031",
1147 SerialNum: "SDX6320031",
1148 Ports: sync.Map{},
1149 }
1150 switch tt.name {
1151 case "Positive_Case_pushFlowsForUnis":
1152 voltPort := &VoltPort{
1153 Name: "16777472",
1154 Device: "SDX6320031",
1155 ID: 16777472,
1156 State: PortStateUp,
1157 ChannelPerSubAlarmRaised: false,
1158 Type: VoltPortTypeNni,
1159 }
1160 d.Ports.Store("16777472", voltPort)
1161 ga := GetApplication()
1162 voltPortVnets := make([]*VoltPortVnet, 0)
1163 voltPortVnet := &VoltPortVnet{
1164 Device: "SDX6320031",
1165 Port: "16777472",
1166 DeleteInProgress: true,
1167 }
1168 voltPortVnets = append(voltPortVnets, voltPortVnet)
1169 ga.VnetsByPort.Store("16777472", voltPortVnets)
1170
1171 d.pushFlowsForUnis(tt.args.cntx)
1172 case "Negetive_Case_pushFlowsForUnis":
1173 voltPort1 := &VoltPort{
1174 Name: "16777472",
1175 Device: "SDX6320031",
1176 ID: 16777472,
1177 State: PortStateDown,
1178 ChannelPerSubAlarmRaised: false,
1179 Type: VoltPortTypeNni,
1180 }
1181 d.Ports.Store("16777472", voltPort1)
1182 d.pushFlowsForUnis(tt.args.cntx)
1183 case "Negetive_Case1_pushFlowsForUnis":
1184 voltPort2 := &VoltPort{
1185 Name: "16777472",
1186 Device: "SDX6320031",
1187 ID: 16777472,
1188 State: PortStateUp,
1189 ChannelPerSubAlarmRaised: false,
1190 Type: VoltPortTypeNni,
1191 }
1192 d.Ports.Store("1677747", voltPort2)
1193 d.pushFlowsForUnis(tt.args.cntx)
1194 }
1195 })
1196 }
1197}
1198
1199func TestNewNbDevice(t *testing.T) {
1200 tests := []struct {
1201 name string
1202 want *NbDevice
1203 }{
1204 {
1205 name: "Positive_Case_pushFlowsForUnis",
1206 want: &NbDevice{},
1207 },
1208 }
1209 for _, tt := range tests {
1210 t.Run(tt.name, func(t *testing.T) {
1211 if got := NewNbDevice(); !reflect.DeepEqual(got, tt.want) {
1212 t.Errorf("NewNbDevice() = %v, want %v", got, tt.want)
1213 }
1214 })
1215 }
1216}
1217
1218func TestNbDevice_WriteToDb(t *testing.T) {
1219 type args struct {
1220 cntx context.Context
1221 portID uint32
1222 ponPort *PonPortCfg
1223 }
1224 tests := []struct {
1225 name string
1226 args args
1227 }{
1228 {
1229 name: "Positive_Case_pushFlowsForUnis",
1230 args: args{
1231 cntx: context.Background(),
1232 portID: controller.NNIPortID,
1233 ponPort: &PonPortCfg{
1234 PortID: controller.NNIPortID,
1235 EnableMulticastKPI: false,
1236 },
1237 },
1238 },
1239 }
1240 for _, tt := range tests {
1241 t.Run(tt.name, func(t *testing.T) {
1242 nbd := &NbDevice{
1243 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1244 }
1245 switch tt.name {
1246 case "Positive_Case_pushFlowsForUnis":
1247 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1248 db = dbintf
1249 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1250 nbd.WriteToDb(tt.args.cntx, tt.args.portID, tt.args.ponPort)
1251 }
1252 })
1253 }
1254}
1255
1256func TestNbDevice_AddPortToNbDevice(t *testing.T) {
1257 type args struct {
1258 cntx context.Context
1259 portID uint32
1260 allowedChannels uint32
1261 enableMulticastKPI bool
1262 portAlarmProfileID string
1263 }
1264 ponPort := &PonPortCfg{
1265 PortID: controller.NNIPortID,
1266 MaxActiveChannels: 123,
1267 EnableMulticastKPI: false,
1268 PortAlarmProfileID: "16777",
1269 }
1270 tests := []struct {
1271 name string
1272 args args
1273 want *PonPortCfg
1274 }{
1275 {
1276 name: "Positive_Case_AddPortToNbDevice",
1277 args: args{
1278 cntx: context.Background(),
1279 portID: controller.NNIPortID,
1280 allowedChannels: 123,
1281 enableMulticastKPI: false,
1282 portAlarmProfileID: "16777",
1283 },
1284 want: ponPort,
1285 },
1286 }
1287 for _, tt := range tests {
1288 t.Run(tt.name, func(t *testing.T) {
1289 nbd := &NbDevice{
1290 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1291 PonPorts: sync.Map{},
1292 }
1293 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1294 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1295 db = dbintf
1296 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1297 if got := nbd.AddPortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1298 t.Errorf("NbDevice.AddPortToNbDevice() = %v, want %v", got, tt.want)
1299 }
1300 })
1301 }
1302}
1303
1304func TestVoltApplication_AddDeviceConfig(t *testing.T) {
1305 type args struct {
1306 cntx context.Context
1307 serialNum string
1308 hardwareIdentifier string
1309 nasID string
1310 ipAddress string
1311 uplinkPort string
1312 nniDhcpTrapID int
1313 }
1314 dvcConfg := &DeviceConfig{
1315 SerialNumber: "SDX6320031",
1316 HardwareIdentifier: "0.0.0.0",
1317 IPAddress: "127.26.1.74",
1318 UplinkPort: "16777216",
1319 NasID: "12345",
1320 NniDhcpTrapVid: 123,
1321 }
1322 voltDev := &VoltDevice{
1323 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1324 SerialNum: "SDX6320031",
1325 NniDhcpTrapVid: 123,
1326 }
1327 tests := []struct {
1328 name string
1329 args args
1330 wantErr bool
1331 }{
1332 {
1333 name: "Positive_Case_AddDeviceConfig",
1334 args: args{
1335 cntx: context.Background(),
1336 serialNum: "SDX6320031",
1337 hardwareIdentifier: "0.0.0.0.",
1338 nasID: "12345",
1339 ipAddress: "127.26.1.74",
1340 uplinkPort: "16777216",
1341 nniDhcpTrapID: 123,
1342 },
1343 wantErr: false,
1344 },
1345 }
1346 for _, tt := range tests {
1347 t.Run(tt.name, func(t *testing.T) {
1348 va := &VoltApplication{
1349 DevicesConfig: sync.Map{},
1350 }
1351 va.DevicesConfig.Store("SDX6320031", dvcConfg)
1352 va.DevicesDisc.Store("SDX6320031", voltDev)
1353 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1354 db = dbintf
1355 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
1356 if err := va.AddDeviceConfig(tt.args.cntx, tt.args.serialNum, tt.args.hardwareIdentifier, tt.args.nasID, tt.args.ipAddress, tt.args.uplinkPort, tt.args.nniDhcpTrapID); (err != nil) != tt.wantErr {
1357 t.Errorf("VoltApplication.AddDeviceConfig() error = %v, wantErr %v", err, tt.wantErr)
1358 }
1359 })
1360 }
1361}
1362
1363func TestVoltApplication_GetDeviceConfig(t *testing.T) {
1364 type args struct {
1365 serNum string
1366 }
1367 dvcConfg := &DeviceConfig{
1368 SerialNumber: "SDX6320031",
1369 HardwareIdentifier: "0.0.0.0",
1370 IPAddress: "127.26.1.74",
1371 UplinkPort: "16777216",
1372 NasID: "12345",
1373 NniDhcpTrapVid: 123,
1374 }
1375 tests := []struct {
1376 name string
1377 args args
1378 want *DeviceConfig
1379 }{
1380 {
1381 name: "Positive_Case_GetDeviceConfig",
1382 args: args{
1383 serNum: "SDX6320031",
1384 },
1385 want: dvcConfg,
1386 },
1387 {
1388 name: "Negetive_Case_GetDeviceConfig",
1389 args: args{
1390 serNum: "SDX6320031",
1391 },
1392 want: nil,
1393 },
1394 }
1395 for _, tt := range tests {
1396 t.Run(tt.name, func(t *testing.T) {
1397 va := &VoltApplication{
1398 DevicesConfig: sync.Map{},
1399 }
1400 switch tt.name {
1401 case "Positive_Case_GetDeviceConfig":
1402 va.DevicesConfig.Store("SDX6320031", dvcConfg)
1403 if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
1404 t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
1405 }
1406 case "Negetive_Case_GetDeviceConfig":
1407 if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) {
1408 t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want)
1409 }
1410 }
1411 })
1412 }
1413}
1414
1415func TestNbDevice_UpdatePortToNbDevice(t *testing.T) {
1416 type args struct {
1417 cntx context.Context
1418 portID uint32
1419 allowedChannels uint32
1420 enableMulticastKPI bool
1421 portAlarmProfileID string
1422 }
1423 ponPort := &PonPortCfg{
1424 PortID: controller.NNIPortID,
1425 MaxActiveChannels: 123,
1426 EnableMulticastKPI: false,
1427 PortAlarmProfileID: "16777",
1428 }
1429 tests := []struct {
1430 name string
1431 args args
1432 want *PonPortCfg
1433 }{
1434 {
1435 name: "Positive_Case_UpdatePortToNbDevice",
1436 args: args{
1437 cntx: context.Background(),
1438 portID: controller.NNIPortID,
1439 allowedChannels: 123,
1440 enableMulticastKPI: false,
1441 portAlarmProfileID: "16777",
1442 },
1443 want: ponPort,
1444 },
1445 {
1446 name: "Negetive_Case_UpdatePortToNbDevice",
1447 args: args{
1448 cntx: context.Background(),
1449 portID: 0,
1450 allowedChannels: 123,
1451 enableMulticastKPI: false,
1452 portAlarmProfileID: "16777",
1453 },
1454 want: nil,
1455 },
1456 }
1457 for _, tt := range tests {
1458 t.Run(tt.name, func(t *testing.T) {
1459 nbd := &NbDevice{
1460 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1461 PonPorts: sync.Map{},
1462 }
1463 switch tt.name {
1464 case "Positive_Case_UpdatePortToNbDevice":
1465 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1466 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1467 db = dbintf
1468 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
1469 if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1470 t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
1471 }
1472 case "Negetive_Case_UpdatePortToNbDevice":
1473 if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) {
1474 t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want)
1475 }
1476 }
1477 })
1478 }
1479}
1480
1481func TestNbDevice_DeletePortFromNbDevice(t *testing.T) {
1482 type args struct {
1483 cntx context.Context
1484 portID uint32
1485 }
1486 ponPort := &PonPortCfg{
1487 PortID: controller.NNIPortID,
1488 MaxActiveChannels: 123,
1489 EnableMulticastKPI: false,
1490 PortAlarmProfileID: "16777",
1491 }
1492 tests := []struct {
1493 name string
1494 args args
1495 }{
1496 {
1497 name: "Positive_Case_DeletePortFromNbDevice",
1498 args: args{
1499 portID: controller.NNIPortID,
1500 },
1501 },
1502 }
1503 for _, tt := range tests {
1504 t.Run(tt.name, func(t *testing.T) {
1505 nbd := &NbDevice{
1506 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1507 PonPorts: sync.Map{},
1508 }
1509 nbd.PonPorts.Store(controller.NNIPortID, ponPort)
1510 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1511 db = dbintf
1512 dbintf.EXPECT().DelNbDevicePort(nil, "49686e2d-618f-4e8e-bca0-442ab850a63a", controller.NNIPortID).AnyTimes()
1513 nbd.DeletePortFromNbDevice(tt.args.cntx, tt.args.portID)
1514 })
1515 }
1516}
1517
1518func TestVoltDevice_RegisterFlowAddEvent(t *testing.T) {
1519 type args struct {
1520 cookie string
1521 event *FlowEvent
1522 }
1523 flowEvent := &FlowEvent{
1524 device: "SDX6320031",
1525 cookie: "68786618880",
1526 eType: EventTypeControlFlowAdded,
1527 }
1528 tests := []struct {
1529 name string
1530 args args
1531 }{
1532 {
1533 name: "Positive_Case_RegisterFlowAddEvent",
1534 args: args{
1535 cookie: "68786618880",
1536 event: flowEvent,
1537 },
1538 },
1539 }
1540 for _, tt := range tests {
1541 t.Run(tt.name, func(t *testing.T) {
1542 d := &VoltDevice{
1543 FlowAddEventMap: util.NewConcurrentMap(),
1544 }
1545 d.RegisterFlowAddEvent(tt.args.cookie, tt.args.event)
1546 })
1547 }
1548}
1549
1550func TestVoltDevice_RegisterFlowDelEvent(t *testing.T) {
1551 type args struct {
1552 cookie string
1553 event *FlowEvent
1554 }
1555 flowEvent := &FlowEvent{
1556 device: "SDX6320031",
1557 cookie: "68786618880",
1558 eType: EventTypeControlFlowRemoved,
1559 }
1560 tests := []struct {
1561 name string
1562 args args
1563 }{
1564 {
1565 name: "Positive_Case_RegisterFlowDelEvent",
1566 args: args{
1567 cookie: "68786618880",
1568 event: flowEvent,
1569 },
1570 },
1571 }
1572 for _, tt := range tests {
1573 t.Run(tt.name, func(t *testing.T) {
1574 d := &VoltDevice{
1575 FlowDelEventMap: util.NewConcurrentMap(),
1576 }
1577 d.RegisterFlowDelEvent(tt.args.cookie, tt.args.event)
1578 })
1579 }
1580}
1581
1582func TestVoltDevice_UnRegisterFlowEvent(t *testing.T) {
1583 type args struct {
1584 cookie string
1585 flowModType of.Command
1586 }
1587 tests := []struct {
1588 name string
1589 args args
1590 }{
1591 {
1592 name: "Positive_Case_RegisterFlowDelEvent",
1593 args: args{
1594 cookie: "68786618880",
1595 flowModType: of.CommandDel,
1596 },
1597 },
1598 {
1599 name: "Negetive_Case_RegisterFlowDelEvent",
1600 args: args{
1601 cookie: "68786618880",
1602 flowModType: opt82,
1603 },
1604 },
1605 }
1606 for _, tt := range tests {
1607 t.Run(tt.name, func(t *testing.T) {
1608 switch tt.name {
1609 case "Positive_Case_RegisterFlowDelEvent":
1610 d := &VoltDevice{
1611 FlowDelEventMap: util.NewConcurrentMap(),
1612 }
1613 d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
1614 case "Negetive_Case_RegisterFlowDelEvent":
1615 d := &VoltDevice{
1616 FlowDelEventMap: util.NewConcurrentMap(),
1617 }
1618 d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType)
1619 }
1620 })
1621 }
1622}
1623
1624func TestVoltApplication_InitStaticConfig(t *testing.T) {
1625 tests := []struct {
1626 name string
1627 }{
1628 {
1629 name: "Positive_Case_InitStaticConfig",
1630 },
1631 }
1632 for _, tt := range tests {
1633 t.Run(tt.name, func(t *testing.T) {
1634 va := &VoltApplication{}
1635 va.InitStaticConfig()
1636 })
1637 }
1638}
1639
1640func TestVoltApplication_SetVendorID(t *testing.T) {
1641 type args struct {
1642 vendorID string
1643 }
1644 tests := []struct {
1645 name string
1646 args args
1647 }{
1648 {
1649 name: "Positive_Case_SetVendorID",
1650 args: args{
1651 vendorID: "DT",
1652 },
1653 },
1654 }
1655 for _, tt := range tests {
1656 t.Run(tt.name, func(t *testing.T) {
1657 va := &VoltApplication{}
1658 va.SetVendorID(tt.args.vendorID)
1659 })
1660 }
1661}
1662
1663func TestVoltApplication_GetVendorID(t *testing.T) {
1664 tests := []struct {
1665 name string
1666 want string
1667 }{
1668 {
1669 name: "Positive_Case_GetVendorID",
1670 want: "DT",
1671 },
1672 }
1673 for _, tt := range tests {
1674 t.Run(tt.name, func(t *testing.T) {
1675 va := &VoltApplication{
1676 vendorID: "DT",
1677 }
1678 if got := va.GetVendorID(); got != tt.want {
1679 t.Errorf("VoltApplication.GetVendorID() = %v, want %v", got, tt.want)
1680 }
1681 })
1682 }
1683}
1684
1685func TestVoltApplication_SetRebootFlag(t *testing.T) {
1686 type args struct {
1687 flag bool
1688 }
1689 tests := []struct {
1690 name string
1691 args args
1692 }{
1693 {
1694 name: "Positive_Case_SetRebootFlag",
1695 args: args{
1696 flag: true,
1697 },
1698 },
1699 }
1700 for _, tt := range tests {
1701 t.Run(tt.name, func(t *testing.T) {
1702 va := &VoltApplication{}
1703 va.SetRebootFlag(tt.args.flag)
1704 })
1705 }
1706}
1707
1708func TestVoltApplication_GetUpgradeFlag(t *testing.T) {
1709 tests := []struct {
1710 name string
1711 want bool
1712 }{
1713 {
1714 name: "Positive_Case_GetUpgradeFlag",
1715 want: true,
1716 },
1717 }
1718 for _, tt := range tests {
1719 t.Run(tt.name, func(t *testing.T) {
1720 va := &VoltApplication{}
1721 isUpgradeComplete = true
1722 if got := va.GetUpgradeFlag(); got != tt.want {
1723 t.Errorf("VoltApplication.GetUpgradeFlag() = %v, want %v", got, tt.want)
1724 }
1725 })
1726 }
1727}
1728
1729func TestVoltApplication_SetUpgradeFlag(t *testing.T) {
1730 type args struct {
1731 flag bool
1732 }
1733 tests := []struct {
1734 name string
1735 args args
1736 }{
1737 {
1738 name: "Positive_Case_GetUpgradeFlag",
1739 args: args{
1740 flag: true,
1741 },
1742 },
1743 }
1744 for _, tt := range tests {
1745 t.Run(tt.name, func(t *testing.T) {
1746 va := &VoltApplication{}
1747 va.SetUpgradeFlag(tt.args.flag)
1748 })
1749 }
1750}
1751
1752func TestVoltApplication_AddDevice(t *testing.T) {
1753 type args struct {
1754 cntx context.Context
1755 device string
1756 slno string
1757 southBoundID string
1758 }
1759 voltDev := &VoltDevice{
1760 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1761 SerialNum: "SDX6320031",
1762 NniDhcpTrapVid: 123,
1763 NniPort: "16777216",
1764 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1765 }
1766 nbd := &NbDevice{
1767 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1768 PonPorts: sync.Map{},
1769 }
1770 ponPortCnf := &PonPortCfg{
1771 PortID: controller.NNIPortID,
1772 MaxActiveChannels: 123,
1773 EnableMulticastKPI: false,
1774 PortAlarmProfileID: "16777",
1775 }
1776 tests := []struct {
1777 name string
1778 args args
1779 }{
1780 {
1781 name: "Positive_Case_AddDevice",
1782 args: args{
1783 cntx: context.Background(),
1784 device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1785 slno: "SDX6320031",
1786 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1787 },
1788 },
1789 {
1790 name: "Negetive_Case_AddDevice",
1791 args: args{
1792 cntx: context.Background(),
1793 device: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1794 slno: "SDX6320031",
1795 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1796 },
1797 },
1798 }
1799 for _, tt := range tests {
1800 t.Run(tt.name, func(t *testing.T) {
1801 va := &VoltApplication{
1802 DevicesDisc: sync.Map{},
1803 NbDevice: sync.Map{},
1804 }
1805 switch tt.name {
1806 case "Positive_Case_AddDevice":
1807 va.DevicesDisc.Store("SDX6320031", voltDev)
1808 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a123", nbd)
1809 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
1810 va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
1811 case "Negetive_Case_AddDevice":
1812 va.DevicesDisc.Store("SDX6320031", voltDev)
1813 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
1814 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1815 db = dbintf
1816 dbintf.EXPECT().GetAllNbPorts(context.Background(), "49686e2d-618f-4e8e-bca0-442ab850a63a123").AnyTimes()
1817 va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID)
1818 }
1819 })
1820 }
1821}
1822
1823func TestVoltApplication_DelDevice(t *testing.T) {
1824 type args struct {
1825 cntx context.Context
1826 device string
1827 }
1828 voltDev := &VoltDevice{
1829 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1830 SerialNum: "SDX6320031",
1831 NniDhcpTrapVid: 123,
1832 NniPort: "16777216",
1833 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1834 }
1835 tests := []struct {
1836 name string
1837 args args
1838 }{
1839 {
1840 name: "Positive_Case_AddDevice",
1841 args: args{
1842 cntx: context.Background(),
1843 device: "SDX6320031",
1844 },
1845 },
1846 {
1847 name: "Delete_Case_AddDevice",
1848 args: args{
1849 cntx: context.Background(),
1850 device: "SDX6320031",
1851 },
1852 },
1853 }
1854 for _, tt := range tests {
1855 t.Run(tt.name, func(t *testing.T) {
1856 va := &VoltApplication{
1857 DevicesDisc: sync.Map{},
1858 }
1859 switch tt.name {
1860 case "Positive_Case_AddDevice":
1861 va.DevicesDisc.Store("SDX6320031", voltDev)
1862 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1863 db = dbintf
1864 dbintf.EXPECT().DelAllRoutesForDevice(context.Background(), "SDX6320031").AnyTimes()
1865 dbintf.EXPECT().GetAllMigrateServicesReq(context.Background(), "SDX6320031").AnyTimes()
1866 dbintf.EXPECT().DelAllGroup(context.Background(), "SDX6320031").AnyTimes()
1867 dbintf.EXPECT().DelAllMeter(context.Background(), "SDX6320031").AnyTimes()
1868 dbintf.EXPECT().DelAllPorts(context.Background(), "SDX6320031").AnyTimes()
1869 va.DelDevice(tt.args.cntx, tt.args.device)
1870 case "Delete_Case_AddDevice":
1871 va.DelDevice(tt.args.cntx, tt.args.device)
1872 }
1873 })
1874 }
1875}
1876
1877func TestVoltApplication_PortAddInd(t *testing.T) {
1878 type args struct {
1879 cntx context.Context
1880 device string
1881 id uint32
1882 portName string
1883 }
1884 voltDev := &VoltDevice{
1885 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1886 SerialNum: "SDX6320031",
1887 NniDhcpTrapVid: 123,
1888 NniPort: "16777216",
1889 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1890 }
1891 tests := []struct {
1892 name string
1893 args args
1894 }{
1895 {
1896 name: "Positive_Case_PortAddInd",
1897 args: args{
1898 cntx: context.Background(),
1899 device: "SDX6320031",
1900 id: controller.NNIPortID,
1901 portName: "16777216",
1902 },
1903 },
1904 {
1905 name: "Negetive_Case_PortAddInd",
1906 args: args{
1907 cntx: context.Background(),
1908 device: "SDX6320031",
1909 id: controller.NNIPortID,
1910 portName: "16777216",
1911 },
1912 },
1913 }
1914 for _, tt := range tests {
1915 t.Run(tt.name, func(t *testing.T) {
1916 va := &VoltApplication{
1917 DevicesDisc: sync.Map{},
1918 }
1919 switch tt.name {
1920 case "Positive_Case_PortAddInd":
1921 va.DevicesDisc.Store("SDX6320031", voltDev)
1922 va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
1923 case "Negetive_Case_PortAddInd":
1924 va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName)
1925 }
1926 })
1927 }
1928}
1929
1930func TestVoltApplication_PortUpdateInd(t *testing.T) {
1931 type args struct {
1932 device string
1933 portName string
1934 id uint32
1935 }
1936 voltDev := &VoltDevice{
1937 Name: "SDX6320031",
1938 SerialNum: "SDX6320031",
1939 NniDhcpTrapVid: 123,
1940 NniPort: "16777216",
1941 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123",
1942 }
1943 tests := []struct {
1944 name string
1945 args args
1946 }{
1947 {
1948 name: "Positive_Case_PortUpdateInd",
1949 args: args{
1950 device: "SDX6320031",
1951 id: controller.NNIPortID,
1952 portName: "16777216",
1953 },
1954 },
1955 {
1956 name: "Negetive_Case_PortUpdateInd",
1957 args: args{
1958 device: "SDX6320031",
1959 id: controller.NNIPortID,
1960 portName: "16777216",
1961 },
1962 },
1963 }
1964 for _, tt := range tests {
1965 t.Run(tt.name, func(t *testing.T) {
1966 va := &VoltApplication{
1967 DevicesDisc: sync.Map{},
1968 }
1969 switch tt.name {
1970 case "Positive_Case_PortAddInd":
1971 va.DevicesDisc.Store("SDX6320031", voltDev)
1972 d := &VoltDevice{
1973 Ports: sync.Map{},
1974 }
1975 voltPort := &VoltPort{
1976 Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
1977 Device: "SDX6320031",
1978 ID: 16777472,
1979 State: PortStateDown,
1980 ChannelPerSubAlarmRaised: false,
1981 Type: VoltPortTypeNni,
1982 }
1983 d.Ports.Store(16777472, voltPort)
1984 va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
1985 case "Negetive_Case_PortUpdateInd":
1986 va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id)
1987 }
1988 })
1989 }
1990}
1991
1992func TestVoltApplication_AddNbPonPort(t *testing.T) {
1993 type args struct {
1994 cntx context.Context
1995 oltSbID string
1996 portID uint32
1997 maxAllowedChannels uint32
1998 enableMulticastKPI bool
1999 portAlarmProfileID string
2000 }
2001 voltDev := &VoltDevice{
2002 Name: "SDX6320031",
2003 SerialNum: "SDX6320031",
2004 NniDhcpTrapVid: 123,
2005 NniPort: "16777216",
2006 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2007 }
2008 nbd := &NbDevice{
2009 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2010 }
2011 tests := []struct {
2012 name string
2013 args args
2014 wantErr bool
2015 }{
2016 {
2017 name: "Positive_Case_AddNbPonPort",
2018 args: args{
2019 cntx: context.Background(),
2020 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2021 portID: 16777472,
2022 maxAllowedChannels: 0,
2023 enableMulticastKPI: false,
2024 portAlarmProfileID: "16777",
2025 },
2026 },
2027 {
2028 name: "Negetive_Case_AddNbPonPort",
2029 args: args{
2030 cntx: context.Background(),
2031 oltSbID: "0",
2032 portID: 16777472,
2033 maxAllowedChannels: 0,
2034 enableMulticastKPI: false,
2035 portAlarmProfileID: "16777",
2036 },
2037 },
2038 }
2039 for _, tt := range tests {
2040 t.Run(tt.name, func(t *testing.T) {
2041 va := &VoltApplication{
2042 DevicesDisc: sync.Map{},
2043 NbDevice: sync.Map{},
2044 }
2045 switch tt.name {
2046 case "Positive_Case_AddNbPonPort":
2047 va.DevicesDisc.Store("SDX6320031", voltDev)
2048 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2049 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2050 db = dbintf
2051 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2052 if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2053 t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2054 }
2055 case "Negetive_Case_AddNbPonPort":
2056 va.DevicesDisc.Store("SDX6320031", voltDev)
2057 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2058 db = dbintf
2059 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2060 if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2061 t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2062 }
2063 }
2064 })
2065 }
2066}
2067
2068func TestVoltApplication_UpdateNbPonPort(t *testing.T) {
2069 type args struct {
2070 cntx context.Context
2071 oltSbID string
2072 portID uint32
2073 maxAllowedChannels uint32
2074 enableMulticastKPI bool
2075 portAlarmProfileID string
2076 }
2077 voltDev := &VoltDevice{
2078 Name: "SDX6320031",
2079 SerialNum: "SDX6320031",
2080 NniDhcpTrapVid: 123,
2081 NniPort: "16777216",
2082 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2083 ActiveChannelsPerPon: sync.Map{},
2084 }
2085 nbd := &NbDevice{
2086 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2087 PonPorts: sync.Map{},
2088 }
2089 ponPortCnf := &PonPortCfg{
2090 PortID: controller.NNIPortID,
2091 MaxActiveChannels: 123,
2092 EnableMulticastKPI: false,
2093 PortAlarmProfileID: "16777",
2094 }
2095 tests := []struct {
2096 name string
2097 args args
2098 wantErr bool
2099 }{
2100 {
2101 name: "Positive_Case_UpdateNbPonPort",
2102 args: args{
2103 cntx: context.Background(),
2104 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2105 portID: controller.NNIPortID,
2106 maxAllowedChannels: 0,
2107 enableMulticastKPI: false,
2108 portAlarmProfileID: "16777",
2109 },
2110 wantErr: false,
2111 },
2112 {
2113 name: "Negetive_Case_Port_doesn't_exists",
2114 args: args{
2115 cntx: context.Background(),
2116 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2117 portID: 16777472,
2118 maxAllowedChannels: 0,
2119 enableMulticastKPI: false,
2120 portAlarmProfileID: "16777",
2121 },
2122 wantErr: true,
2123 },
2124 {
2125 name: "Negetive_Case_Device-doesn't-exists",
2126 args: args{
2127 cntx: context.Background(),
2128 oltSbID: "0",
2129 portID: 16777472,
2130 maxAllowedChannels: 0,
2131 enableMulticastKPI: false,
2132 portAlarmProfileID: "16777",
2133 },
2134 wantErr: true,
2135 },
2136 }
2137 for _, tt := range tests {
2138 t.Run(tt.name, func(t *testing.T) {
2139 va := &VoltApplication{
2140 DevicesDisc: sync.Map{},
2141 NbDevice: sync.Map{},
2142 }
2143 switch tt.name {
2144 case "Positive_Case_UpdateNbPonPort":
2145 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2146 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
2147 va.DevicesDisc.Store("SDX6320031", voltDev)
2148 voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
2149 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2150 db = dbintf
2151 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2152 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2153 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2154 }
2155 case "Negetive_Case_Port_doesn't_exists":
2156 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2157 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2158 db = dbintf
2159 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2160 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2161 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2162 }
2163 case "Negetive_Case_Device-doesn't-exists":
2164 va.DevicesDisc.Store("SDX6320031", voltDev)
2165 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2166 db = dbintf
2167 dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2168 if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr {
2169 t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2170 }
2171 }
2172 })
2173 }
2174}
2175
2176func TestVoltApplication_DeleteNbPonPort(t *testing.T) {
2177 type args struct {
2178 cntx context.Context
2179 oltSbID string
2180 portID uint32
2181 }
2182 voltDev := &VoltDevice{
2183 Name: "SDX6320031",
2184 SerialNum: "SDX6320031",
2185 NniDhcpTrapVid: 123,
2186 NniPort: "16777216",
2187 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2188 ActiveChannelsPerPon: sync.Map{},
2189 }
2190 nbd := &NbDevice{
2191 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2192 }
2193 ponPortCnf := &PonPortCfg{
2194 PortID: controller.NNIPortID,
2195 MaxActiveChannels: 123,
2196 EnableMulticastKPI: false,
2197 PortAlarmProfileID: "16777",
2198 }
2199 tests := []struct {
2200 name string
2201 args args
2202 wantErr bool
2203 }{
2204 {
2205 name: "Positive_Case_DeleteNbPonPort",
2206 args: args{
2207 cntx: context.Background(),
2208 oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2209 portID: controller.NNIPortID,
2210 },
2211 wantErr: false,
2212 },
2213 {
2214 name: "Negetive_Case_DeleteNbPonPort",
2215 args: args{
2216 cntx: context.Background(),
2217 oltSbID: "0",
2218 portID: controller.NNIPortID,
2219 },
2220 wantErr: false,
2221 },
2222 }
2223 for _, tt := range tests {
2224 t.Run(tt.name, func(t *testing.T) {
2225 va := &VoltApplication{
2226 DevicesDisc: sync.Map{},
2227 NbDevice: sync.Map{},
2228 }
2229 switch tt.name {
2230 case "Positive_Case_DeleteNbPonPort":
2231 va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd)
2232 nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf)
2233 va.DevicesDisc.Store("SDX6320031", voltDev)
2234 voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf)
2235 va.DevicesDisc.Store("SDX6320031", voltDev)
2236 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2237 db = dbintf
2238 dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2239 if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
2240 t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2241 }
2242 case "Negetive_Case_DeleteNbPonPort":
2243 va.DevicesDisc.Store("SDX6320031", voltDev)
2244 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2245 db = dbintf
2246 dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
2247 if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr {
2248 t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr)
2249 }
2250 }
2251 })
2252 }
2253}
2254
2255func TestVoltApplication_DeviceUpInd(t *testing.T) {
2256 type args struct {
2257 device string
2258 }
2259 voltDev := &VoltDevice{
2260 Name: "SDX6320031",
2261 SerialNum: "SDX6320031",
2262 NniDhcpTrapVid: 123,
2263 NniPort: "16777216",
2264 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2265 }
2266 tests := []struct {
2267 name string
2268 args args
2269 }{
2270 {
2271 name: "Positive_Case_DeviceUpInd",
2272 args: args{
2273 device: "SDX6320031",
2274 },
2275 },
2276 {
2277 name: "Negetive_Case_DeviceUpInd",
2278 args: args{
2279 device: "o",
2280 },
2281 },
2282 }
2283 for _, tt := range tests {
2284 t.Run(tt.name, func(t *testing.T) {
2285 va := &VoltApplication{
2286 DevicesDisc: sync.Map{},
2287 }
2288 switch tt.name {
2289 case "Positive_Case_DeviceUpInd":
2290 va.DevicesDisc.Store("SDX6320031", voltDev)
2291 va.DeviceUpInd(tt.args.device)
2292 case "Negetive_Case_DeviceUpInd":
2293 va.DeviceUpInd(tt.args.device)
2294 }
2295 })
2296 }
2297}
2298
2299func TestVoltApplication_DeviceDownInd(t *testing.T) {
2300 type args struct {
2301 device string
2302 }
2303 voltDev := &VoltDevice{
2304 Name: "SDX6320031",
2305 SerialNum: "SDX6320031",
2306 NniDhcpTrapVid: 123,
2307 NniPort: "16777216",
2308 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2309 }
2310 tests := []struct {
2311 name string
2312 args args
2313 }{
2314 {
2315 name: "Positive_Case_DeviceDownInd",
2316 args: args{
2317 device: "SDX6320031",
2318 },
2319 },
2320 {
2321 name: "Negetive_Case_DeviceDownInd",
2322 args: args{
2323 device: "o",
2324 },
2325 },
2326 }
2327 for _, tt := range tests {
2328 t.Run(tt.name, func(t *testing.T) {
2329 va := &VoltApplication{
2330 DevicesDisc: sync.Map{},
2331 }
2332 switch tt.name {
2333 case "Positive_Case_DeviceDownInd":
2334 va.DevicesDisc.Store("SDX6320031", voltDev)
2335 va.DeviceDownInd(tt.args.device)
2336 case "Negetive_Case_DeviceDownInd":
2337 va.DeviceDownInd(tt.args.device)
2338 }
2339 })
2340 }
2341}
2342
2343func TestVoltApplication_DeviceRebootInd(t *testing.T) {
2344 type args struct {
2345 cntx context.Context
2346 device string
2347 serialNum string
2348 southBoundID string
2349 }
2350 voltDev := &VoltDevice{
2351 Name: "SDX6320031",
2352 SerialNum: "SDX6320031",
2353 NniDhcpTrapVid: 123,
2354 NniPort: "16777216",
2355 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2356 State: controller.DeviceStateREBOOTED,
2357 }
2358 tests := []struct {
2359 name string
2360 args args
2361 }{
2362 {
2363 name: "Positive_Case_DeviceRebootInd",
2364 args: args{
2365 device: "SDX6320031",
2366 serialNum: "SDX6320031",
2367 southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2368 },
2369 },
2370 }
2371 for _, tt := range tests {
2372 t.Run(tt.name, func(t *testing.T) {
2373 va := &VoltApplication{
2374 DevicesDisc: sync.Map{},
2375 }
2376 va.DevicesDisc.Store("SDX6320031", voltDev)
2377 va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID)
2378 })
2379 }
2380}
vinokuma02fbfd02023-07-05 15:23:33 +05302381
2382func TestVoltApplication_GetDeviceFromPort(t *testing.T) {
2383 type args struct {
2384 port string
2385 }
2386 voltDev := &VoltDevice{
2387 Name: "SDX6320031",
2388 SerialNum: "SDX6320031",
2389 NniDhcpTrapVid: 123,
2390 NniPort: "16777216",
2391 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2392 Ports: sync.Map{},
2393 }
2394 voltPort := &VoltPort{
2395 Name: "16777216",
2396 Device: "SDX6320031",
2397 ID: 16777216,
2398 State: PortStateDown,
2399 ChannelPerSubAlarmRaised: false,
2400 Type: VoltPortTypeNni,
2401 }
2402 tests := []struct {
2403 name string
2404 args args
2405 want *VoltDevice
2406 wantErr bool
2407 }{
2408 {
2409 name: "Positive_Case_GetDeviceFromPort",
2410 args: args{
2411 port: "16777216",
2412 },
2413 want: voltDev,
2414 wantErr: false,
2415 },
2416 }
2417 for _, tt := range tests {
2418 t.Run(tt.name, func(t *testing.T) {
2419 va := &VoltApplication{
2420 DevicesDisc: sync.Map{},
2421 PortsDisc: sync.Map{},
2422 }
2423 va.PortsDisc.Store("16777216", voltPort)
2424 va.DevicesDisc.Store("SDX6320031", voltDev)
2425 got, err := va.GetDeviceFromPort(tt.args.port)
2426 if (err != nil) != tt.wantErr {
2427 t.Errorf("VoltApplication.GetDeviceFromPort() error = %v, wantErr %v", err, tt.wantErr)
2428 return
2429 }
2430 if !reflect.DeepEqual(got, tt.want) {
2431 t.Errorf("VoltApplication.GetDeviceFromPort() = %v, want %v", got, tt.want)
2432 }
2433 })
2434 }
2435}
2436
2437func TestVoltApplication_GetPortID(t *testing.T) {
2438 type args struct {
2439 port string
2440 }
2441 voltPort := &VoltPort{
2442 Name: "16777216",
2443 Device: "SDX6320031",
2444 ID: 16777216,
2445 State: PortStateDown,
2446 ChannelPerSubAlarmRaised: false,
2447 Type: VoltPortTypeNni,
2448 }
2449 tests := []struct {
2450 name string
2451 args args
2452 want uint32
2453 wantErr bool
2454 }{
2455 {
2456 name: "Positive_Case_GetPortID",
2457 args: args{
2458 port: "16777216",
2459 },
2460 want: 16777216,
2461 wantErr: false,
2462 },
2463 }
2464 for _, tt := range tests {
2465 t.Run(tt.name, func(t *testing.T) {
2466 va := &VoltApplication{
2467 PortsDisc: sync.Map{},
2468 }
2469 va.PortsDisc.Store("16777216", voltPort)
2470 got, err := va.GetPortID(tt.args.port)
2471 if (err != nil) != tt.wantErr {
2472 t.Errorf("VoltApplication.GetPortID() error = %v, wantErr %v", err, tt.wantErr)
2473 return
2474 }
2475 if got != tt.want {
2476 t.Errorf("VoltApplication.GetPortID() = %v, want %v", got, tt.want)
2477 }
2478 })
2479 }
2480}
2481
2482func TestVoltApplication_GetPortName(t *testing.T) {
2483 type args struct {
2484 port uint32
2485 }
2486 voltPort := &VoltPort{
2487 Name: "16777216",
2488 Device: "SDX6320031",
2489 ID: 16777216,
2490 State: PortStateDown,
2491 ChannelPerSubAlarmRaised: false,
2492 Type: VoltPortTypeNni,
2493 }
2494 tests := []struct {
2495 name string
2496 args args
2497 want string
2498 wantErr bool
2499 }{
2500 {
2501 name: "Positive_Case_GetPortID",
2502 args: args{
2503 port: 16777216,
2504 },
2505 want: "16777216",
2506 wantErr: false,
2507 },
2508 }
2509 for _, tt := range tests {
2510 t.Run(tt.name, func(t *testing.T) {
2511 va := &VoltApplication{
2512 PortsDisc: sync.Map{},
2513 }
2514 va.PortsDisc.Store("16777216", voltPort)
2515 got, err := va.GetPortName(tt.args.port)
2516 if (err != nil) != tt.wantErr {
2517 t.Errorf("VoltApplication.GetPortName() error = %v, wantErr %v", err, tt.wantErr)
2518 return
2519 }
2520 if got != tt.want {
2521 t.Errorf("VoltApplication.GetPortName() = %v, want %v", got, tt.want)
2522 }
2523 })
2524 }
2525}
2526
2527func TestVoltApplication_PortUpInd(t *testing.T) {
2528 type args struct {
2529 cntx context.Context
2530 device string
2531 port string
2532 }
2533 voltDev := &VoltDevice{
2534 Name: "SDX6320031",
2535 SerialNum: "SDX6320031",
2536 NniDhcpTrapVid: 123,
2537 NniPort: "16777472",
2538 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2539 Ports: sync.Map{},
2540 VpvsBySvlan: util.NewConcurrentMap(),
2541 }
2542 voltPort := &VoltPort{
2543 Name: "16777472",
2544 Device: "SDX6320031",
2545 ID: 16777472,
2546 State: PortStateUp,
2547 ChannelPerSubAlarmRaised: false,
2548 Type: VoltPortTypeNni,
2549 }
2550 voltServ := &VoltService{
2551 VoltServiceOper: VoltServiceOper{
2552 Device: "SDX6320031",
2553 },
2554 VoltServiceCfg: VoltServiceCfg{
2555 IsActivated: true,
2556 },
2557 }
2558 voltPortVnets := make([]*VoltPortVnet, 0)
2559 voltPortVnet := &VoltPortVnet{
2560 Device: "SDX6320031",
2561 Port: "16777472",
2562 DeleteInProgress: false,
2563 services: sync.Map{},
2564 SVlan: 4096,
2565 CVlan: 2310,
2566 UniVlan: 4096,
2567 SVlanTpid: 65,
2568 servicesCount: atomic.NewUint64(1),
2569 }
2570 voltPortVnets = append(voltPortVnets, voltPortVnet)
2571
2572 tests := []struct {
2573 name string
2574 args args
2575 }{
2576 {
2577 name: "Positive_Case_PortUpInd",
2578 args: args{
2579 cntx: context.Background(),
2580 port: "16777472",
2581 device: "SDX6320031",
2582 },
2583 },
2584 }
2585 for _, tt := range tests {
2586 t.Run(tt.name, func(t *testing.T) {
2587 va := &VoltApplication{
2588 DevicesDisc: sync.Map{},
2589 VnetsByPort: sync.Map{},
2590 }
2591 va.DevicesDisc.Store("SDX6320031", voltDev)
2592 voltDev.Ports.Store("16777472", voltPort)
2593 va.VnetsByPort.Store("16777472", voltPortVnets)
2594 voltPortVnet.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
2595 voltapp := GetApplication()
2596 voltapp.DevicesDisc.Store("SDX6320031", voltDev)
2597 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2598 db = dbintf
2599 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2600 va.PortUpInd(tt.args.cntx, tt.args.device, tt.args.port)
2601 })
2602 }
2603}
2604
2605func TestVoltApplication_PortDownInd(t *testing.T) {
2606 type args struct {
2607 cntx context.Context
2608 device string
2609 port string
2610 }
2611 voltDev := &VoltDevice{
2612 Name: "SDX6320031",
2613 SerialNum: "SDX6320031",
2614 NniDhcpTrapVid: 123,
2615 NniPort: "16777472",
2616 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2617 Ports: sync.Map{},
2618 VpvsBySvlan: util.NewConcurrentMap(),
2619 }
2620 voltPort := &VoltPort{
2621 Name: "16777472",
2622 Device: "SDX6320031",
2623 ID: 16777472,
2624 State: PortStateDown,
2625 ChannelPerSubAlarmRaised: false,
2626 Type: VoltPortTypeNni,
2627 }
2628 voltPortVnets := make([]*VoltPortVnet, 0)
2629 voltPortVnet := &VoltPortVnet{
2630 Device: "SDX6320031",
2631 Port: "16777472",
2632 DeleteInProgress: false,
2633 services: sync.Map{},
2634 SVlan: 4096,
2635 CVlan: 2310,
2636 UniVlan: 4096,
2637 SVlanTpid: 65,
2638 servicesCount: atomic.NewUint64(1),
2639 }
2640 voltPortVnets = append(voltPortVnets, voltPortVnet)
2641 tests := []struct {
2642 name string
2643 args args
2644 }{
2645 {
2646 name: "Positive_Case_PortDownInd",
2647 args: args{
2648 cntx: context.Background(),
2649 port: "16777472",
2650 device: "SDX6320031",
2651 },
2652 },
2653 }
2654 for _, tt := range tests {
2655 t.Run(tt.name, func(t *testing.T) {
2656 va := &VoltApplication{}
2657 va.DevicesDisc.Store("SDX6320031", voltDev)
2658 voltDev.Ports.Store("16777472", voltPort)
2659 va.VnetsByPort.Store("16777472", voltPortVnets)
2660 voltApp := GetApplication()
2661 voltApp.DevicesDisc.Store("SDX6320031", voltDev)
2662 va.PortDownInd(tt.args.cntx, tt.args.device, tt.args.port)
2663 })
2664 }
2665}
2666
2667func TestVoltApplication_UpdateDeviceSerialNumberList(t *testing.T) {
2668 type args struct {
2669 oldOltSlNo string
2670 newOltSlNo string
2671 }
2672 voltDev := &VoltDevice{
2673 Name: "49686e2d-618f-4e8e-bca0",
2674 SerialNum: "SDX6320031",
2675 NniDhcpTrapVid: 123,
2676 NniPort: "16777472",
2677 SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a",
2678 Ports: sync.Map{},
2679 VpvsBySvlan: util.NewConcurrentMap(),
2680 }
2681 tests := []struct {
2682 name string
2683 args args
2684 }{
2685 {
2686 name: "Positive_Case_UpdateDeviceSerialNumberList",
2687 args: args{
2688 oldOltSlNo: "SDX6320030",
2689 newOltSlNo: "SDX6320031",
2690 },
2691 },
2692 }
2693 for _, tt := range tests {
2694 t.Run(tt.name, func(t *testing.T) {
2695 va := &VoltApplication{}
2696 va.DevicesDisc.Store("SDX6320031", voltDev)
2697 va.UpdateDeviceSerialNumberList(tt.args.oldOltSlNo, tt.args.newOltSlNo)
2698 })
2699 }
2700}
vinokuma04dc9f82023-07-31 15:47:49 +05302701
2702func TestVoltApplication_DeleteMacInPortMap(t *testing.T) {
2703 type args struct {
2704 macAddr net.HardwareAddr
2705 }
2706
2707 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
2708 macPort := map[string]string{}
2709 macPort[macAdd.String()] = test_data
2710
2711 tests := []struct {
2712 name string
2713 args args
2714 }{
2715 {
2716 name: "Positive_Case_DeleteMacInPortMap",
2717 args: args{
2718 macAddr: macAdd,
2719 },
2720 },
2721 }
2722 for _, tt := range tests {
2723 t.Run(tt.name, func(t *testing.T) {
2724 va := &VoltApplication{
2725 macPortMap: macPort,
2726 }
2727 va.DeleteMacInPortMap(tt.args.macAddr)
2728 })
2729 }
2730}
2731
2732func TestVoltApplication_TriggerPendingServiceDeactivateReq(t *testing.T) {
2733 type args struct {
2734 cntx context.Context
2735 device string
2736 }
2737 ServicesDeactivate := map[string]bool{}
2738 ServicesDeactivate["SDX6320031-1_SDX6320031-1-4096-2310-4096-65"] = true
2739 voltServ := &VoltService{
2740 VoltServiceOper: VoltServiceOper{
2741 Device: "SDX6320031",
2742 },
2743 VoltServiceCfg: VoltServiceCfg{
2744 Name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65",
2745 SVlan: 4096,
2746 CVlan: 2310,
2747 UniVlan: 4096,
2748 Port: "16777472",
2749 TechProfileID: 65,
2750 },
2751 }
2752
2753 voltPortVnets := make([]*VoltPortVnet, 0)
2754 voltPortVnet := &VoltPortVnet{
2755 Device: "SDX6320031",
2756 Port: "16777472",
2757 DeleteInProgress: false,
2758 services: sync.Map{},
2759 SVlan: 4096,
2760 CVlan: 2310,
2761 UniVlan: 4096,
2762 SVlanTpid: 65,
2763 servicesCount: atomic.NewUint64(1),
2764 }
2765
2766 voltPortVnets = append(voltPortVnets, voltPortVnet)
2767 tests := []struct {
2768 name string
2769 args args
2770 }{
2771 {
2772 name: "Positive_Case_DeleteMacInPortMap",
2773 args: args{
2774 cntx: context.Background(),
2775 device: "SDX6320031",
2776 },
2777 },
2778 }
2779
2780 for _, tt := range tests {
2781 t.Run(tt.name, func(t *testing.T) {
2782 va := &VoltApplication{
2783 ServicesToDeactivate: ServicesDeactivate,
2784 ServiceByName: sync.Map{},
2785 VnetsByPort: sync.Map{},
2786 }
2787 va.ServiceByName.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
2788 va.VnetsByPort.Store("16777472", voltPortVnets)
2789 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2790 db = dbintf
2791 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2792 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
2793 va.TriggerPendingServiceDeactivateReq(tt.args.cntx, tt.args.device)
2794 })
2795 }
2796}
2797
2798func TestVoltApplication_ReadAllFromDb(t *testing.T) {
2799 type args struct {
2800 cntx context.Context
2801 }
2802
2803 migrationInfo := "migration done"
2804 deviceConfig := DeviceConfig{
2805 SerialNumber: "SDX6320031",
2806 UplinkPort: "16777472",
2807 HardwareIdentifier: "0.0.0.0",
2808 IPAddress: "127.26.1.74",
2809 NasID: "12345",
2810 NniDhcpTrapVid: 123,
2811 }
2812
2813 voltVnet := &VoltVnet{
2814 Version: "v3",
2815 VnetConfig: VnetConfig{
2816 Name: "2310-4096-4096",
2817 VnetType: "Encapsulation",
2818 SVlan: 2310,
2819 CVlan: 4096,
2820 UniVlan: 4096,
2821 SVlanTpid: 33024,
2822 },
2823
2824 VnetOper: VnetOper{
2825 PendingDeviceToDelete: "SDX6320031",
2826 DeleteInProgress: true,
2827 },
2828 }
2829
2830 cuncurrentMap := &util.ConcurrentMap{
2831 Count: atomic.NewUint64(0),
2832 }
2833
2834 vnetToDelete := map[string]bool{}
2835 vnetToDelete["2310-4096-4096"] = true
2836 macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
2837 voltPortVnet := &VoltPortVnet{
2838 Device: "SDX6320031",
2839 Port: "16777472",
2840 DeleteInProgress: true,
2841 MacAddr: macAdd,
2842 }
2843
2844 macPortMap := map[string]string{}
2845 voltPortVnetsToDelete := map[*VoltPortVnet]bool{}
2846 voltPortVnetsToDelete[voltPortVnet] = true
2847 macPortMap[macAdd.String()] = "16777472"
2848
2849 tests := []struct {
2850 name string
2851 args args
2852 }{
2853 {
2854 name: "Positive_Case_ReadAllFromDb",
2855 args: args{
2856 cntx: context.Background(),
2857 },
2858 },
2859 }
2860
2861 for _, tt := range tests {
2862 t.Run(tt.name, func(t *testing.T) {
2863 va := &VoltApplication{
2864 VnetsBySvlan: util.NewConcurrentMap(),
2865 VnetsToDelete: vnetToDelete,
2866 macPortMap: macPortMap,
2867 VoltPortVnetsToDelete: voltPortVnetsToDelete,
2868 VnetsByName: sync.Map{},
2869 }
2870
2871 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
2872 db = dbintf
2873 dbintf.EXPECT().GetMeters(gomock.Any()).AnyTimes()
2874 vnet, _ := json.Marshal(voltVnet)
2875 voltVnets := map[string]*kvstore.KVPair{}
2876 voltVnets["2310-4096-4096"] = &kvstore.KVPair{
2877 Key: "2310-4096-4096",
2878 Value: vnet,
2879 }
2880
2881 va.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
2882 dbintf.EXPECT().GetVnets(gomock.Any()).AnyTimes().Return(voltVnets, nil).AnyTimes()
2883 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes()
2884 vpvs, _ := json.Marshal(voltPortVnet)
2885 voltPort := map[string]*kvstore.KVPair{}
2886 voltPort["16777472"] = &kvstore.KVPair{
2887 Key: "16777472",
2888 Value: vpvs,
2889 }
2890 va.VnetsByName.Store("2310-4096-4096", voltVnet)
2891 dbintf.EXPECT().GetVpvs(gomock.Any()).AnyTimes().Return(voltPort, nil).AnyTimes()
2892 dbintf.EXPECT().GetServices(gomock.Any()).AnyTimes()
2893 dbintf.EXPECT().GetMvlans(gomock.Any()).AnyTimes()
2894 dbintf.EXPECT().GetIgmpProfiles(gomock.Any()).AnyTimes()
2895 dbintf.EXPECT().GetMcastConfigs(gomock.Any()).AnyTimes()
2896 dbintf.EXPECT().GetIgmpGroups(gomock.Any()).AnyTimes()
2897 dbintf.EXPECT().GetMigrationInfo(gomock.Any()).Return(migrationInfo, nil).AnyTimes()
2898 dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes()
2899 b, _ := json.Marshal(deviceConfig)
2900 test := map[string]*kvstore.KVPair{}
2901 test["SDX6320031"] = &kvstore.KVPair{
2902 Key: "SDX6320031",
2903 Value: b,
2904 }
2905 dbintf.EXPECT().GetDeviceConfig(gomock.Any()).Return(test, nil).AnyTimes()
2906 dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
2907 va.ReadAllFromDb(tt.args.cntx)
2908 })
2909 }
2910}
2911
2912func TestVoltApplication_RemoveGroupDevicesFromPendingPool(t *testing.T) {
2913 type args struct {
2914 ig *IgmpGroup
2915 }
2916 pendingGroupForDevice := map[string]time.Time{}
2917 pendingGroupForDevice[test_device] = time.Now()
2918 tests := []struct {
2919 name string
2920 args args
2921 }{
2922 {
2923 name: "VoltApplication_RemoveGroupDevicesFromPendingPool",
2924 args: args{
2925 ig: &IgmpGroup{
2926 Version: "test_version",
2927 PendingGroupForDevice: pendingGroupForDevice,
2928 },
2929 },
2930 },
2931 }
2932 for _, tt := range tests {
2933 t.Run(tt.name, func(t *testing.T) {
2934 va := &VoltApplication{}
2935 va.RemoveGroupDevicesFromPendingPool(tt.args.ig)
2936 })
2937 }
2938}