tusd/post_test.go

70 lines
1.4 KiB
Go
Raw Normal View History

2015-12-25 21:33:27 +00:00
package tusd_test
2015-02-09 18:37:06 +00:00
import (
"net/http"
"testing"
2015-12-25 21:33:27 +00:00
. "github.com/tus/tusd"
2015-02-09 18:37:06 +00:00
)
type postStore struct {
t *testing.T
zeroStore
}
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
}
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{
2015-03-23 17:15:05 +00:00
"Tus-Resumable": "1.0.0",
"Upload-Length": "300",
"Upload-Metadata": "foo aGVsbG8=, bar d29ybGQ=",
2015-02-17 14:44:12 +00:00
},
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{
2015-03-23 17:15:05 +00:00
"Tus-Resumable": "1.0.0",
"Upload-Length": "500",
"Upload-Metadata": "foo aGVsbG8=, bar d29ybGQ=",
2015-02-17 14:44:12 +00:00
},
Code: http.StatusRequestEntityTooLarge,
}).Run(handler, t)
2015-02-09 18:37:06 +00:00
}