@@ -612,13 +612,13 @@ func TestConvertStringToInt64(t *testing.T) {
612
612
{
613
613
desc : "invalid empty string" ,
614
614
inputStr : "" ,
615
- expInt64 : 10000 ,
615
+ expInt64 : 0 ,
616
616
expectError : true ,
617
617
},
618
618
{
619
619
desc : "invalid string" ,
620
620
inputStr : "ew%65" ,
621
- expInt64 : 10000 ,
621
+ expInt64 : 0 ,
622
622
expectError : true ,
623
623
},
624
624
{
@@ -630,7 +630,7 @@ func TestConvertStringToInt64(t *testing.T) {
630
630
{
631
631
desc : "invalid GB string" ,
632
632
inputStr : "10GB" ,
633
- expInt64 : 10000 ,
633
+ expInt64 : 0 ,
634
634
expectError : true ,
635
635
},
636
636
{
@@ -698,83 +698,95 @@ func TestConvertStringToInt64(t *testing.T) {
698
698
}
699
699
}
700
700
701
- func TestConvertMiBStringToInt64 (t * testing.T ) {
701
+ func TestConvertMiStringToInt64 (t * testing.T ) {
702
702
tests := []struct {
703
703
desc string
704
704
inputStr string
705
705
expInt64 int64
706
706
expectError bool
707
707
}{
708
708
{
709
- "valid number string" ,
710
- "10000" ,
711
- 1 ,
712
- false ,
709
+ desc : "valid number string" ,
710
+ inputStr : "10000" ,
711
+ expInt64 : 1 ,
712
+ expectError : false ,
713
713
},
714
714
{
715
- "round Ki to MiB" ,
716
- "1000Ki" ,
717
- 1 ,
718
- false ,
715
+ desc : "round Ki to MiB" ,
716
+ inputStr : "1000Ki" ,
717
+ expInt64 : 1 ,
718
+ expectError : false ,
719
719
},
720
720
{
721
- "round k to MiB" ,
722
- "1000k" ,
723
- 1 ,
724
- false ,
721
+ desc : "round k to MiB" ,
722
+ inputStr : "1000k" ,
723
+ expInt64 : 1 ,
724
+ expectError : false ,
725
725
},
726
726
{
727
- "round Mi to MiB" ,
728
- "1000Mi" ,
729
- 1000 ,
730
- false ,
727
+ desc : "round Mi to MiB" ,
728
+ inputStr : "1000Mi" ,
729
+ expInt64 : 1000 ,
730
+ expectError : false ,
731
731
},
732
732
{
733
- "round M to MiB" ,
734
- "1000M" ,
735
- 954 ,
736
- false ,
733
+ desc : "round M to MiB" ,
734
+ inputStr : "1000M" ,
735
+ expInt64 : 954 ,
736
+ expectError : false ,
737
737
},
738
738
{
739
- "round G to MiB" ,
740
- "1000G" ,
741
- 953675 ,
742
- false ,
739
+ desc : "round G to MiB" ,
740
+ inputStr : "1000G" ,
741
+ expInt64 : 953675 ,
742
+ expectError : false ,
743
743
},
744
744
{
745
- "round Gi to MiB" ,
746
- "10000Gi" ,
747
- 10240000 ,
748
- false ,
745
+ desc : "round Gi to MiB" ,
746
+ inputStr : "10000Gi" ,
747
+ expInt64 : 10240000 ,
748
+ expectError : false ,
749
749
},
750
750
{
751
- "round decimal to MiB" ,
752
- "1.2Gi" ,
753
- 1229 ,
754
- false ,
751
+ desc : "round decimal to MiB" ,
752
+ inputStr : "1.2Gi" ,
753
+ expInt64 : 1229 ,
754
+ expectError : false ,
755
755
},
756
756
{
757
- "round big value to MiB" ,
758
- "8191Pi" ,
759
- 8795019280384 ,
760
- false ,
757
+ desc : "round big value to MiB" ,
758
+ inputStr : "8191Pi" ,
759
+ expInt64 : 8795019280384 ,
760
+ expectError : false ,
761
761
},
762
762
{
763
- "invalid empty string" ,
764
- "" ,
765
- 10000 ,
766
- true ,
763
+ desc : "invalid empty string" ,
764
+ inputStr : "" ,
765
+ expInt64 : 0 ,
766
+ expectError : true ,
767
767
},
768
768
{
769
- "invalid string" ,
770
- "ew%65" ,
771
- 10000 ,
772
- true ,
769
+ desc : "invalid KiB string" ,
770
+ inputStr : "10KiB" ,
771
+ expInt64 : 10000 ,
772
+ expectError : true ,
773
+ },
774
+ {
775
+ desc : "invalid GB string" ,
776
+ inputStr : "10GB" ,
777
+ expInt64 : 0 ,
778
+ expectError : true ,
779
+ },
780
+ {
781
+ desc : "invalid string" ,
782
+ inputStr : "ew%65" ,
783
+ expInt64 : 0 ,
784
+ expectError : true ,
773
785
},
774
786
}
775
787
for _ , tc := range tests {
776
788
t .Run (tc .desc , func (t * testing.T ) {
777
- actualInt64 , err := ConvertMiBStringToInt64 (tc .inputStr )
789
+ actualInt64 , err := ConvertMiStringToInt64 (tc .inputStr )
778
790
if err != nil && ! tc .expectError {
779
791
t .Errorf ("Got error %v converting string to int64 %s; expect no error" , err , tc .inputStr )
780
792
}
0 commit comments