You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.3 KiB
96 lines
3.3 KiB
9 years ago
|
/*
|
||
|
* Minio Cloud Storage, (C) 2015, 2016 Minio, Inc.
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
8 years ago
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
9 years ago
|
|
||
8 years ago
|
// Test for reduceErrs, reduceErr reduces collection
|
||
|
// of errors into a single maximal error with in the list.
|
||
9 years ago
|
func TestReduceErrs(t *testing.T) {
|
||
8 years ago
|
// List all of all test cases to validate various cases of reduce errors.
|
||
9 years ago
|
testCases := []struct {
|
||
8 years ago
|
errs []error
|
||
|
ignoredErrs []error
|
||
|
err error
|
||
9 years ago
|
}{
|
||
8 years ago
|
// Validate if have reduced properly.
|
||
|
{[]error{
|
||
|
errDiskNotFound,
|
||
|
errDiskNotFound,
|
||
|
errDiskFull,
|
||
|
}, []error{}, errDiskNotFound},
|
||
|
// Validate if have no consensus.
|
||
|
{[]error{
|
||
|
errDiskFull,
|
||
|
errDiskNotFound,
|
||
|
nil, nil,
|
||
|
}, []error{}, nil},
|
||
|
// Validate if have consensus and errors ignored.
|
||
|
{[]error{
|
||
|
errVolumeNotFound,
|
||
|
errVolumeNotFound,
|
||
|
errVolumeNotFound,
|
||
|
errDiskNotFound,
|
||
|
errDiskNotFound,
|
||
|
}, []error{errDiskNotFound}, errVolumeNotFound},
|
||
|
{[]error{}, []error{}, nil},
|
||
9 years ago
|
}
|
||
8 years ago
|
// Validates list of all the testcases for returning valid errors.
|
||
9 years ago
|
for i, testCase := range testCases {
|
||
8 years ago
|
gotErr := reduceErrs(testCase.errs, testCase.ignoredErrs)
|
||
9 years ago
|
if testCase.err != gotErr {
|
||
|
t.Errorf("Test %d : expected %s, got %s", i+1, testCase.err, gotErr)
|
||
|
}
|
||
9 years ago
|
}
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
// TestHashOrder - test order of ints in array
|
||
|
func TestHashOrder(t *testing.T) {
|
||
|
testCases := []struct {
|
||
|
objectName string
|
||
|
hashedOrder []int
|
||
|
}{
|
||
|
// cases which should pass the test.
|
||
|
// passing in valid object name.
|
||
|
{"object", []int{15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}},
|
||
|
{"The Shining Script <v1>.pdf", []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
|
||
|
{"Cost Benefit Analysis (2009-2010).pptx", []int{15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}},
|
||
|
{"117Gn8rfHL2ACARPAhaFd0AGzic9pUbIA/5OCn5A", []int{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2}},
|
||
|
{"SHØRT", []int{11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
|
||
|
{"There are far too many object names, and far too few bucket names!", []int{15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}},
|
||
|
{"a/b/c/", []int{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2}},
|
||
|
{"/a/b/c", []int{7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6}},
|
||
|
{string([]byte{0xff, 0xfe, 0xfd}), []int{15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}},
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
// Tests hashing order to be consistent.
|
||
|
for i, testCase := range testCases {
|
||
|
hashedOrder := hashOrder(testCase.objectName, 16)
|
||
|
if !reflect.DeepEqual(testCase.hashedOrder, hashedOrder) {
|
||
|
t.Errorf("Test case %d: Expected \"%#v\" but failed \"%#v\"", i+1, testCase.hashedOrder, hashedOrder)
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
// Tests hashing order to fail for when order is '-1'.
|
||
|
if hashedOrder := hashOrder("This will fail", -1); hashedOrder != nil {
|
||
|
t.Errorf("Test: Expect \"nil\" but failed \"%#v\"", hashedOrder)
|
||
9 years ago
|
}
|
||
|
}
|