mirror of
https://github.com/pgsty/minio.git
synced 2026-07-25 06:56:18 +03:00
xl/utils: getPartSizeFromIdx should return error. (#3669)
This commit is contained in:
+26
-2
@@ -353,9 +353,33 @@ func TestGetPartSizeFromIdx(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
s := getPartSizeFromIdx(testCase.totalSize, testCase.partSize, testCase.partIndex)
|
||||
if s != testCase.expectedSize {
|
||||
s, err := getPartSizeFromIdx(testCase.totalSize, testCase.partSize, testCase.partIndex)
|
||||
if err != nil {
|
||||
t.Errorf("Test %d: Expected to pass but failed. %s", i+1, err)
|
||||
}
|
||||
if err == nil && s != testCase.expectedSize {
|
||||
t.Errorf("Test %d: The calculated part size is incorrect: expected = %d, found = %d\n", i+1, testCase.expectedSize, s)
|
||||
}
|
||||
}
|
||||
|
||||
testCasesFailure := []struct {
|
||||
totalSize int64
|
||||
partSize int64
|
||||
partIndex int
|
||||
err error
|
||||
}{
|
||||
// partSize is 0, error.
|
||||
{10, 0, 1, errPartSizeZero},
|
||||
{10, 1, 0, errPartSizeIndex},
|
||||
}
|
||||
|
||||
for i, testCaseFailure := range testCasesFailure {
|
||||
_, err := getPartSizeFromIdx(testCaseFailure.totalSize, testCaseFailure.partSize, testCaseFailure.partIndex)
|
||||
if err == nil {
|
||||
t.Errorf("Test %d: Expected to failed but passed. %s", i+1, err)
|
||||
}
|
||||
if err != nil && errorCause(err) != testCaseFailure.err {
|
||||
t.Errorf("Test %d: Expected err %s, but got %s", i+1, testCaseFailure.err, errorCause(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user