Skip to content

Commit 5e233e2

Browse files
authored
Merge pull request #1131 from sunnylovestiramisu/addTests
Add more unit tests for hyperdisk feature
2 parents b4f0a48 + 2626489 commit 5e233e2

File tree

3 files changed

+64
-52
lines changed

3 files changed

+64
-52
lines changed

pkg/common/parameters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
158158
}
159159
p.ProvisionedIOPSOnCreate = paramProvisionedIOPSOnCreate
160160
case ParameterKeyProvisionedThroughputOnCreate:
161-
paramProvisionedThroughputOnCreate, err := ConvertMiBStringToInt64(v)
161+
paramProvisionedThroughputOnCreate, err := ConvertMiStringToInt64(v)
162162
if err != nil {
163163
return p, fmt.Errorf("parameters contain invalid provisionedThroughputOnCreate parameter: %w", err)
164164
}

pkg/common/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ func ConvertStringToInt64(str string) (int64, error) {
260260
return volumehelpers.RoundUpToB(quantity)
261261
}
262262

263-
// ConvertMiBStringToInt64 converts a GiB string to int64
264-
func ConvertMiBStringToInt64(str string) (int64, error) {
263+
// ConvertMiStringToInt64 converts a GiB string to int64
264+
func ConvertMiStringToInt64(str string) (int64, error) {
265265
quantity, err := resource.ParseQuantity(str)
266266
if err != nil {
267267
return -1, err

pkg/common/utils_test.go

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,13 @@ func TestConvertStringToInt64(t *testing.T) {
612612
{
613613
desc: "invalid empty string",
614614
inputStr: "",
615-
expInt64: 10000,
615+
expInt64: 0,
616616
expectError: true,
617617
},
618618
{
619619
desc: "invalid string",
620620
inputStr: "ew%65",
621-
expInt64: 10000,
621+
expInt64: 0,
622622
expectError: true,
623623
},
624624
{
@@ -630,7 +630,7 @@ func TestConvertStringToInt64(t *testing.T) {
630630
{
631631
desc: "invalid GB string",
632632
inputStr: "10GB",
633-
expInt64: 10000,
633+
expInt64: 0,
634634
expectError: true,
635635
},
636636
{
@@ -698,83 +698,95 @@ func TestConvertStringToInt64(t *testing.T) {
698698
}
699699
}
700700

701-
func TestConvertMiBStringToInt64(t *testing.T) {
701+
func TestConvertMiStringToInt64(t *testing.T) {
702702
tests := []struct {
703703
desc string
704704
inputStr string
705705
expInt64 int64
706706
expectError bool
707707
}{
708708
{
709-
"valid number string",
710-
"10000",
711-
1,
712-
false,
709+
desc: "valid number string",
710+
inputStr: "10000",
711+
expInt64: 1,
712+
expectError: false,
713713
},
714714
{
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,
719719
},
720720
{
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,
725725
},
726726
{
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,
731731
},
732732
{
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,
737737
},
738738
{
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,
743743
},
744744
{
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,
749749
},
750750
{
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,
755755
},
756756
{
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,
761761
},
762762
{
763-
"invalid empty string",
764-
"",
765-
10000,
766-
true,
763+
desc: "invalid empty string",
764+
inputStr: "",
765+
expInt64: 0,
766+
expectError: true,
767767
},
768768
{
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,
773785
},
774786
}
775787
for _, tc := range tests {
776788
t.Run(tc.desc, func(t *testing.T) {
777-
actualInt64, err := ConvertMiBStringToInt64(tc.inputStr)
789+
actualInt64, err := ConvertMiStringToInt64(tc.inputStr)
778790
if err != nil && !tc.expectError {
779791
t.Errorf("Got error %v converting string to int64 %s; expect no error", err, tc.inputStr)
780792
}

0 commit comments

Comments
 (0)