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