@@ -578,83 +578,113 @@ func TestSnapshotStorageLocations(t *testing.T) {
578578 }
579579}
580580
581- func TestConvertGiBStringToInt64 (t * testing.T ) {
581+ func TestConvertStringToInt64 (t * testing.T ) {
582582 tests := []struct {
583583 desc string
584584 inputStr string
585585 expInt64 int64
586586 expectError bool
587587 }{
588588 {
589- "valid number string" ,
590- "10000" ,
591- 1 ,
592- false ,
589+ desc : "valid number string" ,
590+ inputStr : "10000" ,
591+ expInt64 : 10000 ,
592+ expectError : false ,
593593 },
594594 {
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 ,
599599 },
600600 {
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 ,
605605 },
606606 {
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 ,
611611 },
612612 {
613- "round M to GiB " ,
614- "1000M " ,
615- 1 ,
616- false ,
613+ desc : "invalid empty string " ,
614+ inputStr : " " ,
615+ expInt64 : 10000 ,
616+ expectError : true ,
617617 },
618618 {
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 ,
623623 },
624624 {
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 ,
629629 },
630630 {
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 ,
635635 },
636636 {
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 ,
641641 },
642642 {
643- "invalid empty string " ,
644- " " ,
645- 10000 ,
646- true ,
643+ desc : "round k to number " ,
644+ inputStr : "10k " ,
645+ expInt64 : 10000 ,
646+ expectError : false ,
647647 },
648648 {
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 ,
653683 },
654684 }
655685 for _ , tc := range tests {
656686 t .Run (tc .desc , func (t * testing.T ) {
657- actualInt64 , err := ConvertGiBStringToInt64 (tc .inputStr )
687+ actualInt64 , err := ConvertStringToInt64 (tc .inputStr )
658688 if err != nil && ! tc .expectError {
659689 t .Errorf ("Got error %v converting string to int64 %s; expect no error" , err , tc .inputStr )
660690 }
0 commit comments