tusd/get_test.go

59 lines
1.1 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"
"strings"
"testing"
2015-12-25 21:33:27 +00:00
"github.com/golang/mock/gomock"
2015-12-25 21:33:27 +00:00
. "github.com/tus/tusd"
2015-02-09 18:37:06 +00:00
)
2015-07-28 12:58:52 +00:00
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) {
SubTest(t, "Successful download", func(t *testing.T, store *MockFullDataStore) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 5,
Size: 20,
MetaData: map[string]string{
"filename": "file.jpg\"evil",
},
}, nil),
store.EXPECT().GetReader("yes").Return(reader, nil),
)
handler, _ := NewHandler(Config{
DataStore: store,
})
(&httpTest{
Method: "GET",
URL: "yes",
Code: http.StatusOK,
ResBody: "hello",
ResHeader: map[string]string{
"Content-Length": "5",
"Content-Disposition": `inline;filename="file.jpg\"evil"`,
},
}).Run(handler, t)
if !reader.closed {
t.Error("expected reader to be closed")
}
2015-02-09 18:37:06 +00:00
})
}