add more tests to cover areas for weird object names (#13873)

continuation of #13858 to add more tests and also validate the 
written object data.
This commit is contained in:
Harshavardhana 2021-12-09 17:52:53 -08:00 committed by GitHub
parent b9f0046ee7
commit 5b7c00ff52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@
package cmd
import (
"bytes"
"context"
"io/ioutil"
"net/http/httptest"
@ -312,6 +313,7 @@ func testStorageAPIAppendFile(t *testing.T, storage StorageAPI) {
t.Fatalf("unexpected error %v", err)
}
testData := []byte("foo")
testCases := []struct {
volumeName string
objectName string
@ -319,12 +321,18 @@ func testStorageAPIAppendFile(t *testing.T, storage StorageAPI) {
expectErr bool
ignoreIfWindows bool
}{
{"foo", "myobject", []byte("foo"), false, false},
{"foo", "myobject", []byte{}, false, false},
{"foo", "myobject", testData, false, false},
{"foo", "myobject-0byte", []byte{}, false, false},
// volume not found error.
{"bar", "myobject", []byte{}, true, false},
// Weird '\n' in object name
{"foo", "newline\n", []byte{}, false, true},
{"bar", "myobject", testData, true, false},
// Test some weird characters over the wire.
{"foo", "newline\n", testData, false, true},
{"foo", "newline\t", testData, false, true},
{"foo", "newline \n", testData, false, true},
{"foo", "newline$$$\n", testData, false, true},
{"foo", "newline%%%\n", testData, false, true},
{"foo", "newline \t % $ & * ^ # @ \n", testData, false, true},
{"foo", "\n\tnewline \t % $ & * ^ # @ \n", testData, false, true},
}
for i, testCase := range testCases {
@ -337,6 +345,17 @@ func testStorageAPIAppendFile(t *testing.T, storage StorageAPI) {
if expectErr != testCase.expectErr {
t.Fatalf("case %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
}
if !testCase.expectErr {
data, err := storage.ReadAll(context.Background(), testCase.volumeName, testCase.objectName)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(data, testCase.data) {
t.Fatalf("case %v: expected %v, got %v", i+1, testCase.data, data)
}
}
}
}