blob: c0bb68408e72d096a26f870ef34112e52a729b31 [file] [log] [blame]
vinokuma04dc9f82023-07-31 15:47:49 +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 "errors"
22 "reflect"
23 "testing"
24 "voltha-go-controller/internal/test/mocks"
25
26 "github.com/golang/mock/gomock"
27 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
28)
29
30func TestDeleteDbPathKeys(t *testing.T) {
31 type args struct {
32 cntx context.Context
33 keyPath string
34 }
35 tests := []struct {
36 name string
37 args args
38 wantErr bool
39 }{
40 {
41 name: "Positive_Case_DeleteDbPathKeys",
42 args: args{
43 cntx: context.Background(),
44 keyPath: "test_key",
45 },
46 wantErr: false,
47 },
48 }
49 for _, tt := range tests {
50 t.Run(tt.name, func(t *testing.T) {
51 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
52 db = dbintf
53 dbintf.EXPECT().DeleteAll(gomock.Any(), gomock.Any()).AnyTimes()
54 if err := DeleteDbPathKeys(tt.args.cntx, tt.args.keyPath); (err != nil) != tt.wantErr {
55 t.Errorf("DeleteDbPathKeys() error = %v, wantErr %v", err, tt.wantErr)
56 }
57 })
58 }
59}
60
61func TestMigrateVnets(t *testing.T) {
62 type args struct {
63 cntx context.Context
64 data []byte
65 }
66 voltVnet_test := &VoltVnet{
67 Version: "v3",
68 VnetConfig: VnetConfig{
69 Name: "2310-4096-4096",
70 VnetType: "Encapsulation",
71 SVlan: 2310,
72 CVlan: 4096,
73 UniVlan: 4096,
74 SVlanTpid: 0,
75 DhcpRelay: true,
76 },
77 VnetOper: VnetOper{
78 PendingDeviceToDelete: "SDX63200313",
79 },
80 }
81
82 byteData, _ := json.Marshal(voltVnet_test)
83 tests := []struct {
84 name string
85 args args
86 want string
87 }{
88 {
89 name: "Positive_Case_DeleteDbPathKeys",
90 args: args{
91 cntx: context.Background(),
92 data: byteData,
93 },
94 want: string(byteData),
95 },
96 }
97 for _, tt := range tests {
98 t.Run(tt.name, func(t *testing.T) {
99 if got := MigrateVnets(tt.args.cntx, tt.args.data); reflect.DeepEqual(got, tt.want) {
100 t.Errorf("MigrateVnets() = %v, want %v", got, tt.want)
101 }
102 })
103 }
104}
105
106func TestMigrateServices(t *testing.T) {
107 type args struct {
108 cntx context.Context
109 data []byte
110 }
111 vsmap := make(map[string]interface{})
112 vsmap["MecLearning"] = true
113 byteData, _ := json.Marshal(&vsmap)
114 tests := []struct {
115 name string
116 args args
117 want string
118 }{
119 {
120 name: "Positive_Case_MigrateServices",
121 args: args{
122 cntx: context.Background(),
123 data: byteData,
124 },
125 want: string(byteData),
126 },
127 }
128 for _, tt := range tests {
129 t.Run(tt.name, func(t *testing.T) {
130 if got := MigrateServices(tt.args.cntx, tt.args.data); reflect.DeepEqual(got, tt.want) {
131 t.Errorf("MigrateServices() = %v, want %v", got, tt.want)
132 }
133 })
134 }
135}
136
137func TestMigrateVpvs(t *testing.T) {
138 type args struct {
139 cntx context.Context
140 data []byte
141 }
142 vpvmap := make(map[string]interface{})
Akash Soni230e6212023-10-16 10:46:07 +0530143 vpvmap["MacLearning"] = true
144 vpvmap["UsFlowsApplied"] = true
145 vpvmap["DsFlowsApplied"] = true
vinokuma04dc9f82023-07-31 15:47:49 +0530146 byteData, _ := json.Marshal(&vpvmap)
147 tests := []struct {
148 name string
149 args args
150 want string
151 }{
152 {
153 name: "Positive_Case_MigrateVpvs",
154 args: args{
155 cntx: context.Background(),
156 data: byteData,
157 },
158 want: string(byteData),
159 },
160 }
161 for _, tt := range tests {
162 t.Run(tt.name, func(t *testing.T) {
163 if got := MigrateVpvs(tt.args.cntx, tt.args.data); reflect.DeepEqual(got, tt.want) {
164 t.Errorf("MigrateVpvs() = %v, want %v", got, tt.want)
165 }
166 })
167 }
168}
169
170func TestMigrateMvlans(t *testing.T) {
171 type args struct {
172 cntx context.Context
173 data []byte
174 }
175 devicesList := make(map[string]OperInProgress)
176 devicesList["SDX6320031"] = opt82
177 mvp := &MvlanProfile{
178 DevicesList: devicesList,
179 }
180 byteData, _ := json.Marshal(mvp)
181 tests := []struct {
182 name string
183 args args
184 want string
185 }{
186 {
187 name: "Positive_Case_MigrateMvlans",
188 args: args{
189 cntx: context.Background(),
190 data: byteData,
191 },
192 want: string(byteData),
193 },
194 }
195 for _, tt := range tests {
196 t.Run(tt.name, func(t *testing.T) {
197 if got := MigrateMvlans(tt.args.cntx, tt.args.data); reflect.DeepEqual(got, tt.want) {
198 t.Errorf("MigrateMvlans() = %v, want %v", got, tt.want)
199 }
200 })
201 }
202}
203
204func TestMigrateIgmpConfs(t *testing.T) {
205 type args struct {
206 cntx context.Context
207 data []byte
208 }
209 igmpProfile_data := IgmpProfile{
210 ProfileID: "test_profile_id",
211 }
212 b, err := json.Marshal(igmpProfile_data)
213 if err != nil {
214 panic(err)
215 }
216 tests := []struct {
217 name string
218 args args
219 want string
220 }{
221 {
222 name: "test_MigrateIgmpConfs",
223 args: args{
224 cntx: context.Background(),
225 data: b,
226 },
227 want: "ModuleToBeDeleted",
228 },
229 {
230 name: "unmarshal error",
231 args: args{
232 cntx: context.Background(),
233 data: []byte{},
234 },
235 },
236 {
237 name: "WriteToDb_error",
238 args: args{
239 cntx: context.Background(),
240 data: b,
241 },
242 want: "ModuleToBeDeleted",
243 },
244 }
245 for _, tt := range tests {
246 t.Run(tt.name, func(t *testing.T) {
247 switch tt.name {
248 case "test_MigrateIgmpConfs":
249 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
250 db = dbintf
251 dbintf.EXPECT().PutIgmpProfile(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
252 if got := MigrateIgmpConfs(tt.args.cntx, tt.args.data); got != tt.want {
253 t.Errorf("MigrateIgmpConfs() = %v, want %v", got, tt.want)
254 }
255 case "unmarshal error":
256 if got := MigrateIgmpConfs(tt.args.cntx, tt.args.data); got != tt.want {
257 t.Errorf("MigrateIgmpConfs() = %v, want %v", got, tt.want)
258 }
259 case "WriteToDb_error":
260 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
261 db = dbintf
262 dbintf.EXPECT().PutIgmpProfile(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error"))
263 if got := MigrateIgmpConfs(tt.args.cntx, tt.args.data); got != tt.want {
264 t.Errorf("MigrateIgmpConfs() = %v, want %v", got, tt.want)
265 }
266 }
267 })
268 }
269}
270
271func TestMigrateIgmpGroups(t *testing.T) {
272 type args struct {
273 cntx context.Context
274 data []byte
275 }
276 data := []byte{}
277 tests := []struct {
278 name string
279 args args
280 want string
281 }{
282 {
283 name: "Positive_Case_MigrateIgmpGroups",
284 args: args{
285 cntx: context.Background(),
286 data: data,
287 },
288 want: "",
289 },
290 }
291 for _, tt := range tests {
292 t.Run(tt.name, func(t *testing.T) {
293 if got := MigrateIgmpGroups(tt.args.cntx, tt.args.data); got != tt.want {
294 t.Errorf("MigrateIgmpGroups() = %v, want %v", got, tt.want)
295 }
296 })
297 }
298}
299
300func TestMigrateIgmpDevices(t *testing.T) {
301 type args struct {
302 cntx context.Context
303 data []byte
304 }
305 data := []byte{}
306 tests := []struct {
307 name string
308 args args
309 want string
310 }{
311 {
312 name: "Positive_Case_MigrateIgmpDevices",
313 args: args{
314 cntx: context.Background(),
315 data: data,
316 },
317 want: "",
318 },
319 }
320 for _, tt := range tests {
321 t.Run(tt.name, func(t *testing.T) {
322 if got := MigrateIgmpDevices(tt.args.cntx, tt.args.data); got != tt.want {
323 t.Errorf("MigrateIgmpDevices() = %v, want %v", got, tt.want)
324 }
325 })
326 }
327}
328
329func TestMigrateIgmpChannels(t *testing.T) {
330 type args struct {
331 cntx context.Context
332 data []byte
333 }
334 data := []byte{}
335 tests := []struct {
336 name string
337 args args
338 want string
339 }{
340 {
341 name: "Positive_Case_MigrateIgmpChannels",
342 args: args{
343 cntx: context.Background(),
344 data: data,
345 },
346 want: "",
347 },
348 }
349 for _, tt := range tests {
350 t.Run(tt.name, func(t *testing.T) {
351 if got := MigrateIgmpChannels(tt.args.cntx, tt.args.data); got != tt.want {
352 t.Errorf("MigrateIgmpChannels() = %v, want %v", got, tt.want)
353 }
354 })
355 }
356}
357
358func TestMigrateIgmpPorts(t *testing.T) {
359 type args struct {
360 cntx context.Context
361 data []byte
362 }
363 data := []byte{}
364 tests := []struct {
365 name string
366 args args
367 want string
368 }{
369 {
370 name: "Positive_Case_MigrateIgmpPorts",
371 args: args{
372 cntx: context.Background(),
373 data: data,
374 },
375 want: "",
376 },
377 }
378 for _, tt := range tests {
379 t.Run(tt.name, func(t *testing.T) {
380 if got := MigrateIgmpPorts(tt.args.cntx, tt.args.data); got != tt.want {
381 t.Errorf("MigrateIgmpPorts() = %v, want %v", got, tt.want)
382 }
383 })
384 }
385}
386
387func TestMigrateIgmpProfs(t *testing.T) {
388 type args struct {
389 cntx context.Context
390 data []byte
391 }
392 data := []byte{}
393 tests := []struct {
394 name string
395 args args
396 want string
397 }{
398 {
399 name: "Positive_Case_MigrateIgmpProfs",
400 args: args{
401 cntx: context.Background(),
402 data: data,
403 },
404 want: "",
405 },
406 }
407 for _, tt := range tests {
408 t.Run(tt.name, func(t *testing.T) {
409 if got := MigrateIgmpProfs(tt.args.cntx, tt.args.data); got != tt.want {
410 t.Errorf("MigrateIgmpProfs() = %v, want %v", got, tt.want)
411 }
412 })
413 }
414}
415
416func TestMigrateMcastConfs(t *testing.T) {
417 type args struct {
418 cntx context.Context
419 data []byte
420 }
421 data := []byte{}
422 tests := []struct {
423 name string
424 args args
425 want string
426 }{
427 {
428 name: "Positive_Case_MigrateMcastConfs",
429 args: args{
430 cntx: context.Background(),
431 data: data,
432 },
433 want: "",
434 },
435 }
436 for _, tt := range tests {
437 t.Run(tt.name, func(t *testing.T) {
438 if got := MigrateMcastConfs(tt.args.cntx, tt.args.data); got != tt.want {
439 t.Errorf("MigrateMcastConfs() = %v, want %v", got, tt.want)
440 }
441 })
442 }
443}
444
445func TestMigrateLogLevels(t *testing.T) {
446 type args struct {
447 cntx context.Context
448 data []byte
449 }
450 data := []byte{}
451 tests := []struct {
452 name string
453 args args
454 want string
455 }{
456 {
457 name: "Positive_Case_MigrateLogLevels",
458 args: args{
459 cntx: context.Background(),
460 data: data,
461 },
462 want: "",
463 },
464 }
465 for _, tt := range tests {
466 t.Run(tt.name, func(t *testing.T) {
467 if got := MigrateLogLevels(tt.args.cntx, tt.args.data); got != tt.want {
468 t.Errorf("MigrateLogLevels() = %v, want %v", got, tt.want)
469 }
470 })
471 }
472}
473
474func TestMigrateHealth(t *testing.T) {
475 type args struct {
476 cntx context.Context
477 data []byte
478 }
479 data := []byte{}
480 tests := []struct {
481 name string
482 args args
483 want string
484 }{
485 {
486 name: "Positive_Case_MigrateHealth",
487 args: args{
488 cntx: context.Background(),
489 data: data,
490 },
491 want: "",
492 },
493 }
494 for _, tt := range tests {
495 t.Run(tt.name, func(t *testing.T) {
496 if got := MigrateHealth(tt.args.cntx, tt.args.data); got != tt.want {
497 t.Errorf("MigrateHealth() = %v, want %v", got, tt.want)
498 }
499 })
500 }
501}
502
503func TestMigratePonCounters(t *testing.T) {
504 type args struct {
505 cntx context.Context
506 data []byte
507 }
508 data := []byte{}
509 tests := []struct {
510 name string
511 args args
512 want string
513 }{
514 {
515 name: "Positive_Case_MigratePonCounters",
516 args: args{
517 cntx: context.Background(),
518 data: data,
519 },
520 want: "",
521 },
522 }
523 for _, tt := range tests {
524 t.Run(tt.name, func(t *testing.T) {
525 if got := MigratePonCounters(tt.args.cntx, tt.args.data); got != tt.want {
526 t.Errorf("MigratePonCounters() = %v, want %v", got, tt.want)
527 }
528 })
529 }
530}
531
532func TestMigrateChannelCounters(t *testing.T) {
533 type args struct {
534 cntx context.Context
535 data []byte
536 }
537 data := []byte{}
538 tests := []struct {
539 name string
540 args args
541 want string
542 }{
543 {
544 name: "Positive_Case_MigrateChannelCounters",
545 args: args{
546 cntx: context.Background(),
547 data: data,
548 },
549 want: "",
550 },
551 }
552 for _, tt := range tests {
553 t.Run(tt.name, func(t *testing.T) {
554 if got := MigrateChannelCounters(tt.args.cntx, tt.args.data); got != tt.want {
555 t.Errorf("MigrateChannelCounters() = %v, want %v", got, tt.want)
556 }
557 })
558 }
559}
560
561func TestMigrateServiceCounters(t *testing.T) {
562 type args struct {
563 cntx context.Context
564 data []byte
565 }
566 data := []byte{}
567 tests := []struct {
568 name string
569 args args
570 want string
571 }{
572 {
573 name: "Positive_Case_MigrateServiceCounters",
574 args: args{
575 cntx: context.Background(),
576 data: data,
577 },
578 want: "",
579 },
580 }
581 for _, tt := range tests {
582 t.Run(tt.name, func(t *testing.T) {
583 if got := MigrateServiceCounters(tt.args.cntx, tt.args.data); got != tt.want {
584 t.Errorf("MigrateServiceCounters() = %v, want %v", got, tt.want)
585 }
586 })
587 }
588}
589
590func TestMigrateNbDevices(t *testing.T) {
591 type args struct {
592 cntx context.Context
593 data []byte
594 }
595 data := []byte{}
596 tests := []struct {
597 name string
598 args args
599 want string
600 }{
601 {
602 name: "Positive_Case_MigrateNbDevices",
603 args: args{
604 cntx: context.Background(),
605 data: data,
606 },
607 want: "",
608 },
609 }
610 for _, tt := range tests {
611 t.Run(tt.name, func(t *testing.T) {
612 if got := MigrateNbDevices(tt.args.cntx, tt.args.data); got != tt.want {
613 t.Errorf("MigrateNbDevices() = %v, want %v", got, tt.want)
614 }
615 })
616 }
617}
618
619func TestMigrateFlowHash(t *testing.T) {
620 type args struct {
621 data []byte
622 }
623 data := []byte{}
624 tests := []struct {
625 name string
626 args args
627 want string
628 }{
629 {
630 name: "Positive_Case_MigrateFlowHash",
631 args: args{
632 data: data,
633 },
634 want: "",
635 },
636 }
637 for _, tt := range tests {
638 t.Run(tt.name, func(t *testing.T) {
639 if got := MigrateFlowHash(tt.args.data); got != tt.want {
640 t.Errorf("MigrateFlowHash() = %v, want %v", got, tt.want)
641 }
642 })
643 }
644}
645
646func TestMigrateMeters(t *testing.T) {
647 type args struct {
648 cntx context.Context
649 data []byte
650 }
651 data := []byte{}
652 tests := []struct {
653 name string
654 args args
655 want string
656 }{
657 {
658 name: "Positive_Case_MigrateMeters",
659 args: args{
660 data: data,
661 },
662 want: "",
663 },
664 }
665 for _, tt := range tests {
666 t.Run(tt.name, func(t *testing.T) {
667 if got := MigrateMeters(tt.args.cntx, tt.args.data); got != tt.want {
668 t.Errorf("MigrateMeters() = %v, want %v", got, tt.want)
669 }
670 })
671 }
672}
673
674func TestMigrateDevices(t *testing.T) {
675 type args struct {
676 cntx context.Context
677 data []byte
678 }
679 data := []byte{}
680 tests := []struct {
681 name string
682 args args
683 want string
684 }{
685 {
686 name: "Positive_Case_MigrateFlowHash",
687 args: args{
688 data: data,
689 },
690 want: "",
691 },
692 }
693 for _, tt := range tests {
694 t.Run(tt.name, func(t *testing.T) {
695 if got := MigrateDevices(tt.args.cntx, tt.args.data); got != tt.want {
696 t.Errorf("MigrateDevices() = %v, want %v", got, tt.want)
697 }
698 })
699 }
700}
701
702func TestMigrateDevicePorts(t *testing.T) {
703 type args struct {
704 cntx context.Context
705 data []byte
706 }
707 data := []byte{}
708 tests := []struct {
709 name string
710 args args
711 want string
712 }{
713 {
714 name: "Positive_Case_MigrateFlowHash",
715 args: args{
716 data: data,
717 },
718 want: "",
719 },
720 }
721 for _, tt := range tests {
722 t.Run(tt.name, func(t *testing.T) {
723 if got := MigrateDevicePorts(tt.args.cntx, tt.args.data); got != tt.want {
724 t.Errorf("MigrateDevicePorts() = %v, want %v", got, tt.want)
725 }
726 })
727 }
728}
729
730func TestMigrateDeviceFlows(t *testing.T) {
731 type args struct {
732 cntx context.Context
733 data []byte
734 }
735 data := []byte{}
736 tests := []struct {
737 name string
738 args args
739 want string
740 }{
741 {
742 name: "Positive_Case_MigrateFlowHash",
743 args: args{
744 data: data,
745 },
746 want: "",
747 },
748 }
749 for _, tt := range tests {
750 t.Run(tt.name, func(t *testing.T) {
751 if got := MigrateDeviceFlows(tt.args.cntx, tt.args.data); got != tt.want {
752 t.Errorf("MigrateDeviceFlows() = %v, want %v", got, tt.want)
753 }
754 })
755 }
756}
757
758func TestMigrateDeviceGroups(t *testing.T) {
759 type args struct {
760 cntx context.Context
761 data []byte
762 }
763 data := []byte{}
764 tests := []struct {
765 name string
766 args args
767 want string
768 }{
769 {
770 name: "Positive_Case_MigrateFlowHash",
771 args: args{
772 data: data,
773 },
774 want: "",
775 },
776 }
777 for _, tt := range tests {
778 t.Run(tt.name, func(t *testing.T) {
779 if got := MigrateDeviceGroups(tt.args.cntx, tt.args.data); got != tt.want {
780 t.Errorf("MigrateDeviceGroups() = %v, want %v", got, tt.want)
781 }
782 })
783 }
784}
785
786func TestMigrateDeviceMeters(t *testing.T) {
787 type args struct {
788 cntx context.Context
789 data []byte
790 }
791 data := []byte{}
792 tests := []struct {
793 name string
794 args args
795 want string
796 }{
797 {
798 name: "Positive_Case_MigrateFlowHash",
799 args: args{
800 data: data,
801 },
802 want: "",
803 },
804 }
805 for _, tt := range tests {
806 t.Run(tt.name, func(t *testing.T) {
807 if got := MigrateDeviceMeters(tt.args.cntx, tt.args.data); got != tt.want {
808 t.Errorf("MigrateDeviceMeters() = %v, want %v", got, tt.want)
809 }
810 })
811 }
812}
813
814func TestMigrateDeviceFlowHash(t *testing.T) {
815 type args struct {
816 cntx context.Context
817 data []byte
818 }
819 data := []byte{}
820 tests := []struct {
821 name string
822 args args
823 want string
824 }{
825 {
826 name: "Positive_Case_MigrateFlowHash",
827 args: args{
828 data: data,
829 },
830 want: "",
831 },
832 }
833 for _, tt := range tests {
834 t.Run(tt.name, func(t *testing.T) {
835 if got := MigrateDeviceFlowHash(tt.args.cntx, tt.args.data); got != tt.want {
836 t.Errorf("MigrateDeviceFlowHash() = %v, want %v", got, tt.want)
837 }
838 })
839 }
840}
841
842func TestFetchAndMigrateDeviceDBData(t *testing.T) {
843 type args struct {
844 module string
845 }
846 var module string
847 tests := []struct {
848 name string
849 args args
850 wantErr bool
851 }{
852 {
853 name: "Positive_Case_MigrateFlowHash",
854 args: args{
855 module: module,
856 },
857 wantErr: false,
858 },
859 }
860 for _, tt := range tests {
861 t.Run(tt.name, func(t *testing.T) {
862 if err := FetchAndMigrateDeviceDBData(tt.args.module); (err != nil) != tt.wantErr {
863 t.Errorf("FetchAndMigrateDeviceDBData() error = %v, wantErr %v", err, tt.wantErr)
864 }
865 })
866 }
867}
868
869func TestDataMigration_WriteToDb(t *testing.T) {
870 type args struct {
871 cntx context.Context
872 }
873 tests := []struct {
874 name string
875 args args
876 wantErr bool
877 }{
878 {
879 name: "Positive_Case_MigrateFlowHash",
880 args: args{
881 cntx: context.Background(),
882 },
883 wantErr: false,
884 },
885 }
886 for _, tt := range tests {
887 t.Run(tt.name, func(t *testing.T) {
888 md := &DataMigration{}
889 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
890 db = dbintf
891 dbintf.EXPECT().PutMigrationInfo(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
892 if err := md.WriteToDb(tt.args.cntx); (err != nil) != tt.wantErr {
893 t.Errorf("DataMigration.WriteToDb() error = %v, wantErr %v", err, tt.wantErr)
894 }
895 })
896 }
897}
898
899func TestGetMigrationInfo(t *testing.T) {
900 type args struct {
901 cntx context.Context
902 dmInfo *DataMigration
903 }
904 dmInfo := &DataMigration{
905 Version: "v1",
906 Status: "done",
907 }
908 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
909 db = dbintf
910 dbintf.EXPECT().GetMigrationInfo(gomock.Any()).Return("migrationInfo", nil).AnyTimes()
911 tests := []struct {
912 name string
913 args args
914 wantErr bool
915 }{
916 {
917 name: "Positive_Case_GetMigrationInfo",
918 args: args{
919 cntx: context.Background(),
920 dmInfo: dmInfo,
921 },
922 wantErr: true,
923 },
924 }
925
926 for _, tt := range tests {
927 t.Run(tt.name, func(t *testing.T) {
928 if err := GetMigrationInfo(tt.args.cntx, tt.args.dmInfo); (err != nil) != tt.wantErr {
929 t.Errorf("GetMigrationInfo() error = %v, wantErr %v", err, tt.wantErr)
930 }
931 })
932 }
933}
934
935func TestCheckIfMigrationRequired(t *testing.T) {
936 type args struct {
937 ctx context.Context
938 }
939
940 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
941 db = dbintf
942 dbintf.EXPECT().GetMigrationInfo(gomock.Any()).Return("Migration_Info", nil).AnyTimes()
943 dbintf.EXPECT().PutMigrationInfo(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
944 tests := []struct {
945 name string
946 args args
947 want bool
948 }{
949 {
950 name: "Positive_Case_CheckIfMigrationRequired",
951 args: args{
952 ctx: context.Background(),
953 },
954 want: false,
955 },
956 }
957 for _, tt := range tests {
958 t.Run(tt.name, func(t *testing.T) {
959 if got := CheckIfMigrationRequired(tt.args.ctx); got != tt.want {
960 t.Errorf("CheckIfMigrationRequired() = %v, want %v", got, tt.want)
961 }
962 })
963 }
964}
965
966func TestDataMigration_DelFromDb(t *testing.T) {
967 type args struct {
968 cntx context.Context
969 }
970 tests := []struct {
971 name string
972 args args
973 }{
974 {
975 name: "Positive_Case_DelFromDb",
976 args: args{
977 cntx: context.Background(),
978 },
979 },
980 {
981 name: "Negetive_Case_DelFromDb",
982 args: args{
983 cntx: context.Background(),
984 },
985 },
986 }
987 for _, tt := range tests {
988 t.Run(tt.name, func(t *testing.T) {
989 md := &DataMigration{}
990 switch tt.name {
991 case "Positive_Case_DelFromDb":
992 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
993 db = dbintf
994 dbintf.EXPECT().DelMigrationInfo(gomock.Any()).Return(nil).AnyTimes()
995 case "Negetive_Case_DelFromDb":
996 myError := errors.New("WRONG MESSAGE")
997 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
998 db = dbintf
999 dbintf.EXPECT().DelMigrationInfo(gomock.Any()).Return(myError).AnyTimes()
1000 }
1001 md.DelFromDb(tt.args.cntx)
1002 })
1003 }
1004}
1005
1006func TestMigrateDBData(t *testing.T) {
1007 type args struct {
1008 cntx context.Context
1009 }
1010 byteArr := []byte{23}
1011 dbPathKeysValueMap := map[string]*kvstore.KVPair{}
1012 dbPathKeysValueMap["devices/%s/flows/"] = &kvstore.KVPair{
1013 Key: "devices/%s/flows/",
1014 Value: byteArr,
1015 }
1016
1017 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
1018 db = dbintf
1019 dbintf.EXPECT().List(gomock.Any(), gomock.Any()).Return(dbPathKeysValueMap, nil).AnyTimes()
1020
1021 tests := []struct {
1022 name string
1023 args args
1024 wantErr bool
1025 }{
1026 {
1027 name: "Positive_Case_DelFromDb",
1028 args: args{
1029 cntx: context.Background(),
1030 },
1031 wantErr: true,
1032 },
1033 }
1034 for _, tt := range tests {
1035 t.Run(tt.name, func(t *testing.T) {
1036 if err := MigrateDBData(tt.args.cntx); (err != nil) != tt.wantErr {
1037 t.Errorf("MigrateDBData() error = %v, wantErr %v", err, tt.wantErr)
1038 }
1039 })
1040 }
1041}