|
|
|
@ -19,6 +19,7 @@ package main |
|
|
|
|
import ( |
|
|
|
|
"os" |
|
|
|
|
"path/filepath" |
|
|
|
|
"reflect" |
|
|
|
|
"testing" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -136,3 +137,30 @@ func TestNewXL(t *testing.T) { |
|
|
|
|
t.Fatalf("Unable to initialize erasure, %s", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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}}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|