tusd/get_test.go

70 lines
1.1 KiB
Go
Raw Permalink Normal View History

2015-12-25 21:33:27 +00:00
package tusd_test
2015-02-09 18:37:06 +00:00
import (
"io"
"net/http"
"os"
"strings"
"testing"
2015-12-25 21:33:27 +00:00
. "github.com/tus/tusd"
2015-02-09 18:37:06 +00:00
)
type getStore struct {
zeroStore
}
func (s getStore) GetInfo(id string) (FileInfo, error) {
if id != "yes" {
return FileInfo{}, os.ErrNotExist
}
return FileInfo{
Offset: 5,
Size: 20,
MetaData: map[string]string{
"filename": "file.jpg\"evil",
},
2015-02-09 18:37:06 +00:00
}, nil
}
func (s getStore) GetReader(id string) (io.Reader, error) {
2015-07-28 12:58:52 +00:00
return reader, nil
}
type closingStringReader struct {
*strings.Reader
closed bool
}
func (reader *closingStringReader) Close() error {
reader.closed = true
return nil
}
var reader = &closingStringReader{
Reader: strings.NewReader("hello"),
2015-02-09 18:37:06 +00:00
}
2015-02-12 15:05:54 +00:00
func TestGet(t *testing.T) {
2015-02-09 18:37:06 +00:00
handler, _ := NewHandler(Config{
DataStore: getStore{},
})
2015-02-17 14:44:12 +00:00
(&httpTest{
Name: "Successful download",
Method: "GET",
URL: "yes",
Code: http.StatusOK,
ResBody: "hello",
ResHeader: map[string]string{
"Content-Length": "5",
"Content-Disposition": `inline;filename="file.jpg\"evil"`,
2015-02-17 14:44:12 +00:00
},
}).Run(handler, t)
2015-07-28 12:58:52 +00:00
if !reader.closed {
t.Error("expected reader to be closed")
}
2015-02-09 18:37:06 +00:00
}