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,
Size: 44,
MetaData: map[string]string{
"name": "lunrjs.png",
"type": "image/png",
"name": "lunrjs.png",
"empty": "",
},
}, 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
// 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" &&
v != "type aW1hZ2UvcG5n,name bHVucmpzLnBuZw==" {
if v := res.Header().Get("Upload-Metadata"); v != "name bHVucmpzLnBuZw==,empty " &&
v != "empty ,name bHVucmpzLnBuZw==" {
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{
Size: 300,
MetaData: map[string]string{
"foo": "hello",
"bar": "world",
"foo": "hello",
"bar": "world",
"empty": "",
},
}).Return(upload, nil),
upload.EXPECT().GetInfo(context.Background()).Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{
"foo": "hello",
"bar": "world",
"foo": "hello",
"bar": "world",
"empty": "",
},
}, nil),
)
@ -52,7 +54,7 @@ func TestPost(t *testing.T) {
"Tus-Resumable": "1.0.0",
"Upload-Length": "300",
// 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,
ResHeader: map[string]string{