tusd/terminate_test.go

84 lines
1.4 KiB
Go
Raw Normal View History

2015-12-25 21:33:27 +00:00
package tusd_test
2015-02-28 13:47:39 +00:00
import (
"net/http"
"testing"
2015-12-25 21:33:27 +00:00
. "github.com/tus/tusd"
2016-03-12 21:24:57 +00:00
"github.com/stretchr/testify/assert"
2015-02-28 13:47:39 +00:00
)
type terminateStore struct {
t *testing.T
zeroStore
}
2016-03-12 21:24:57 +00:00
func (s terminateStore) GetInfo(id string) (FileInfo, error) {
return FileInfo{
ID: id,
Size: 10,
}, nil
}
2015-02-28 13:47:39 +00:00
func (s terminateStore) Terminate(id string) error {
if id != "foo" {
s.t.Fatal("unexpected id")
}
return nil
}
func TestTerminate(t *testing.T) {
handler, _ := NewHandler(Config{
DataStore: terminateStore{
t: t,
},
2016-03-12 21:24:57 +00:00
NotifyTerminatedUploads: true,
2015-02-28 13:47:39 +00:00
})
2016-03-12 21:24:57 +00:00
c := make(chan FileInfo, 1)
handler.TerminatedUploads = c
(&httpTest{
Name: "Successful OPTIONS request",
Method: "OPTIONS",
URL: "",
ResHeader: map[string]string{
"Tus-Extension": "creation,termination",
},
Code: http.StatusNoContent,
}).Run(handler, t)
2015-02-28 13:47:39 +00:00
(&httpTest{
Name: "Successful request",
Method: "DELETE",
URL: "foo",
ReqHeader: map[string]string{
2015-03-23 17:15:05 +00:00
"Tus-Resumable": "1.0.0",
2015-02-28 13:47:39 +00:00
},
Code: http.StatusNoContent,
}).Run(handler, t)
2016-03-12 21:24:57 +00:00
info := <-c
a := assert.New(t)
a.Equal("foo", info.ID)
a.Equal(int64(10), info.Size)
2015-02-28 13:47:39 +00:00
}
func TestTerminateNotImplemented(t *testing.T) {
handler, _ := NewHandler(Config{
DataStore: zeroStore{},
})
(&httpTest{
Name: "TerminaterDataStore not implemented",
Method: "DELETE",
URL: "foo",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
},
Code: http.StatusMethodNotAllowed,
}).Run(handler, t)
}