tusd/handler_test.go

46 lines
955 B
Go
Raw Normal View History

2015-12-25 21:33:27 +00:00
package tusd_test
import (
2015-02-17 14:44:12 +00:00
"net/http"
2015-10-06 16:27:40 +00:00
"strings"
2015-02-17 14:44:12 +00:00
"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-10-06 16:27:40 +00:00
func TestMethodOverride(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
store := NewMockFullDataStore(mockCtrl)
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 5,
Size: 20,
}, nil)
store.EXPECT().WriteChunk("yes", int64(5), NewReaderMatcher("hello")).Return(int64(5), nil)
2015-10-06 16:27:40 +00:00
handler, _ := NewHandler(Config{
DataStore: store,
})
(&httpTest{
Name: "Successful request",
Method: "POST",
URL: "yes",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
"Upload-Offset": "5",
2015-11-04 09:56:32 +00:00
"Content-Type": "application/offset+octet-stream",
2015-10-06 16:27:40 +00:00
"X-HTTP-Method-Override": "PATCH",
},
ReqBody: strings.NewReader("hello"),
Code: http.StatusNoContent,
ResHeader: map[string]string{
"Upload-Offset": "10",
},
}).Run(handler, t)
}