handler: Add tests for empty metadata pairs

This commit is contained in:
Marius 2020-07-15 17:30:17 +02:00
parent 59c3d42f8f
commit 26b84bcb1c
2 changed files with 11 additions and 9 deletions

View File

@ -26,8 +26,8 @@ func TestHead(t *testing.T) {
Offset: 11, Offset: 11,
Size: 44, Size: 44,
MetaData: map[string]string{ MetaData: map[string]string{
"name": "lunrjs.png", "name": "lunrjs.png",
"type": "image/png", "empty": "",
}, },
}, nil), }, nil),
lock.EXPECT().Unlock().Return(nil), lock.EXPECT().Unlock().Return(nil),
@ -57,8 +57,8 @@ func TestHead(t *testing.T) {
// Since the order of a map is not guaranteed in Go, we need to be prepared // Since the order of a map is not guaranteed in Go, we need to be prepared
// for the case, that the order of the metadata may have been changed // for the case, that the order of the metadata may have been changed
if v := res.Header().Get("Upload-Metadata"); v != "name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n" && if v := res.Header().Get("Upload-Metadata"); v != "name bHVucmpzLnBuZw==,empty " &&
v != "type aW1hZ2UvcG5n,name bHVucmpzLnBuZw==" { v != "empty ,name bHVucmpzLnBuZw==" {
t.Errorf("Expected valid metadata (got '%s')", v) t.Errorf("Expected valid metadata (got '%s')", v)
} }
}) })

View File

@ -23,16 +23,18 @@ func TestPost(t *testing.T) {
store.EXPECT().NewUpload(context.Background(), FileInfo{ store.EXPECT().NewUpload(context.Background(), FileInfo{
Size: 300, Size: 300,
MetaData: map[string]string{ MetaData: map[string]string{
"foo": "hello", "foo": "hello",
"bar": "world", "bar": "world",
"empty": "",
}, },
}).Return(upload, nil), }).Return(upload, nil),
upload.EXPECT().GetInfo(context.Background()).Return(FileInfo{ upload.EXPECT().GetInfo(context.Background()).Return(FileInfo{
ID: "foo", ID: "foo",
Size: 300, Size: 300,
MetaData: map[string]string{ MetaData: map[string]string{
"foo": "hello", "foo": "hello",
"bar": "world", "bar": "world",
"empty": "",
}, },
}, nil), }, nil),
) )
@ -52,7 +54,7 @@ func TestPost(t *testing.T) {
"Tus-Resumable": "1.0.0", "Tus-Resumable": "1.0.0",
"Upload-Length": "300", "Upload-Length": "300",
// Invalid Base64-encoded values should be ignored // Invalid Base64-encoded values should be ignored
"Upload-Metadata": "foo aGVsbG8=, bar d29ybGQ=, hah INVALID", "Upload-Metadata": "foo aGVsbG8=, bar d29ybGQ=, hah INVALID, empty",
}, },
Code: http.StatusCreated, Code: http.StatusCreated,
ResHeader: map[string]string{ ResHeader: map[string]string{