2015-02-09 18:37:06 +00:00
|
|
|
package tusd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type postStore struct {
|
|
|
|
t *testing.T
|
|
|
|
zeroStore
|
|
|
|
}
|
|
|
|
|
2015-02-16 16:53:50 +00:00
|
|
|
func (s postStore) NewUpload(info FileInfo) (string, error) {
|
|
|
|
if info.Size != 300 {
|
|
|
|
s.t.Errorf("Expected size to be 300 (got %v)", info.Size)
|
2015-02-09 18:37:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 16:53:50 +00:00
|
|
|
metaData := info.MetaData
|
2015-02-09 18:37:06 +00:00
|
|
|
if len(metaData) != 2 {
|
|
|
|
s.t.Errorf("Expected two elements in metadata")
|
|
|
|
}
|
|
|
|
|
|
|
|
if v := metaData["foo"]; v != "hello" {
|
|
|
|
s.t.Errorf("Expected foo element to be 'hello' but got %s", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v := metaData["bar"]; v != "world" {
|
|
|
|
s.t.Errorf("Expected bar element to be 'world' but got %s", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return "foo", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPost(t *testing.T) {
|
|
|
|
handler, _ := NewHandler(Config{
|
|
|
|
MaxSize: 400,
|
|
|
|
BasePath: "files",
|
|
|
|
DataStore: postStore{
|
|
|
|
t: t,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2015-02-17 14:44:12 +00:00
|
|
|
(&httpTest{
|
|
|
|
Name: "Successful request",
|
|
|
|
Method: "POST",
|
|
|
|
ReqHeader: map[string]string{
|
|
|
|
"TUS-Resumable": "1.0.0",
|
|
|
|
"Entity-Length": "300",
|
|
|
|
"Metadata": "foo aGVsbG8=, bar d29ybGQ=",
|
|
|
|
},
|
|
|
|
Code: http.StatusCreated,
|
|
|
|
ResHeader: map[string]string{
|
|
|
|
"Location": "http://tus.io/files/foo",
|
|
|
|
},
|
|
|
|
}).Run(handler, t)
|
2015-02-09 18:37:06 +00:00
|
|
|
|
2015-02-17 14:44:12 +00:00
|
|
|
(&httpTest{
|
|
|
|
Name: "Exceeding MaxSize",
|
|
|
|
Method: "POST",
|
|
|
|
ReqHeader: map[string]string{
|
|
|
|
"TUS-Resumable": "1.0.0",
|
|
|
|
"Entity-Length": "500",
|
|
|
|
"Metadata": "foo aGVsbG8=, bar d29ybGQ=",
|
|
|
|
},
|
|
|
|
Code: http.StatusRequestEntityTooLarge,
|
|
|
|
}).Run(handler, t)
|
2015-02-09 18:37:06 +00:00
|
|
|
}
|