diff --git a/cmd/storage-rest_test.go b/cmd/storage-rest_test.go index 5003ae5bc..4b7264ade 100644 --- a/cmd/storage-rest_test.go +++ b/cmd/storage-rest_test.go @@ -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) + } + } } }