@@ -578,83 +578,113 @@ func TestSnapshotStorageLocations(t *testing.T) {
578
578
}
579
579
}
580
580
581
- func TestConvertGiBStringToInt64 (t * testing.T ) {
581
+ func TestConvertStringToInt64 (t * testing.T ) {
582
582
tests := []struct {
583
583
desc string
584
584
inputStr string
585
585
expInt64 int64
586
586
expectError bool
587
587
}{
588
588
{
589
- "valid number string" ,
590
- "10000" ,
591
- 1 ,
592
- false ,
589
+ desc : "valid number string" ,
590
+ inputStr : "10000" ,
591
+ expInt64 : 10000 ,
592
+ expectError : false ,
593
593
},
594
594
{
595
- "round Ki to GiB " ,
596
- "1000Ki " ,
597
- 1 ,
598
- false ,
595
+ desc : "round M to number " ,
596
+ inputStr : "1M " ,
597
+ expInt64 : 1000000 ,
598
+ expectError : false ,
599
599
},
600
600
{
601
- "round k to GiB " ,
602
- "1000k " ,
603
- 1 ,
604
- false ,
601
+ desc : "round m to number " ,
602
+ inputStr : "1m " ,
603
+ expInt64 : 1 ,
604
+ expectError : false ,
605
605
},
606
606
{
607
- "round Mi to GiB " ,
608
- "1000Mi " ,
609
- 1 ,
610
- false ,
607
+ desc : "round k to number " ,
608
+ inputStr : "1k " ,
609
+ expInt64 : 1000 ,
610
+ expectError : false ,
611
611
},
612
612
{
613
- "round M to GiB " ,
614
- "1000M " ,
615
- 1 ,
616
- false ,
613
+ desc : "invalid empty string " ,
614
+ inputStr : " " ,
615
+ expInt64 : 10000 ,
616
+ expectError : true ,
617
617
},
618
618
{
619
- "round G to GiB " ,
620
- "1000G " ,
621
- 932 ,
622
- false ,
619
+ desc : "invalid string " ,
620
+ inputStr : "ew%65 " ,
621
+ expInt64 : 10000 ,
622
+ expectError : true ,
623
623
},
624
624
{
625
- "round Gi to GiB " ,
626
- "10000Gi " ,
627
- 10000 ,
628
- false ,
625
+ desc : "invalid KiB string " ,
626
+ inputStr : "10KiB " ,
627
+ expInt64 : 10000 ,
628
+ expectError : true ,
629
629
},
630
630
{
631
- "round decimal to GiB " ,
632
- "1.2Gi " ,
633
- 2 ,
634
- false ,
631
+ desc : "invalid GB string " ,
632
+ inputStr : "10GB " ,
633
+ expInt64 : 10000 ,
634
+ expectError : true ,
635
635
},
636
636
{
637
- "round big value to GiB " ,
638
- "8191Pi " ,
639
- 8588886016 ,
640
- false ,
637
+ desc : "round Ki to number " ,
638
+ inputStr : "1Ki " ,
639
+ expInt64 : 1024 ,
640
+ expectError : false ,
641
641
},
642
642
{
643
- "invalid empty string " ,
644
- " " ,
645
- 10000 ,
646
- true ,
643
+ desc : "round k to number " ,
644
+ inputStr : "10k " ,
645
+ expInt64 : 10000 ,
646
+ expectError : false ,
647
647
},
648
648
{
649
- "invalid string" ,
650
- "ew%65" ,
651
- 10000 ,
652
- true ,
649
+ desc : "round Mi to number" ,
650
+ inputStr : "10Mi" ,
651
+ expInt64 : 10485760 ,
652
+ expectError : false ,
653
+ },
654
+ {
655
+ desc : "round M to number" ,
656
+ inputStr : "10M" ,
657
+ expInt64 : 10000000 ,
658
+ expectError : false ,
659
+ },
660
+ {
661
+ desc : "round G to number" ,
662
+ inputStr : "10G" ,
663
+ expInt64 : 10000000000 ,
664
+ expectError : false ,
665
+ },
666
+ {
667
+ desc : "round Gi to number" ,
668
+ inputStr : "100Gi" ,
669
+ expInt64 : 107374182400 ,
670
+ expectError : false ,
671
+ },
672
+ {
673
+ desc : "round decimal to number" ,
674
+ inputStr : "1.2Gi" ,
675
+ expInt64 : 1288490189 ,
676
+ expectError : false ,
677
+ },
678
+ {
679
+ desc : "round big value to number" ,
680
+ inputStr : "8191Pi" ,
681
+ expInt64 : 9222246136947933184 ,
682
+ expectError : false ,
653
683
},
654
684
}
655
685
for _ , tc := range tests {
656
686
t .Run (tc .desc , func (t * testing.T ) {
657
- actualInt64 , err := ConvertGiBStringToInt64 (tc .inputStr )
687
+ actualInt64 , err := ConvertStringToInt64 (tc .inputStr )
658
688
if err != nil && ! tc .expectError {
659
689
t .Errorf ("Got error %v converting string to int64 %s; expect no error" , err , tc .inputStr )
660
690
}
0 commit comments