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