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

@ -27,7 +27,7 @@ func TestHead(t *testing.T) {
Size: 44,
MetaData: map[string]string{
"name": "lunrjs.png",
"type": "image/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

@ -25,6 +25,7 @@ func TestPost(t *testing.T) {
MetaData: map[string]string{
"foo": "hello",
"bar": "world",
"empty": "",
},
}).Return(upload, nil),
upload.EXPECT().GetInfo(context.Background()).Return(FileInfo{
@ -33,6 +34,7 @@ func TestPost(t *testing.T) {
MetaData: map[string]string{
"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{