Add tests for locking in various situations
This commit is contained in:
parent
3b3e3bcef0
commit
5ff46eb2d7
21
get_test.go
21
get_test.go
|
@ -25,7 +25,12 @@ func TestGet(t *testing.T) {
|
||||||
Reader: strings.NewReader("hello"),
|
Reader: strings.NewReader("hello"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
locker := NewMockLocker(ctrl)
|
||||||
|
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
|
locker.EXPECT().LockUpload("yes"),
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
Offset: 5,
|
Offset: 5,
|
||||||
Size: 20,
|
Size: 20,
|
||||||
|
@ -34,21 +39,27 @@ func TestGet(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, nil),
|
}, nil),
|
||||||
store.EXPECT().GetReader("yes").Return(reader, nil),
|
store.EXPECT().GetReader("yes").Return(reader, nil),
|
||||||
|
locker.EXPECT().UnlockUpload("yes"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
composer := NewStoreComposer()
|
||||||
|
composer.UseCore(store)
|
||||||
|
composer.UseGetReader(store)
|
||||||
|
composer.UseLocker(locker)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
URL: "yes",
|
URL: "yes",
|
||||||
Code: http.StatusOK,
|
|
||||||
ResBody: "hello",
|
|
||||||
ResHeader: map[string]string{
|
ResHeader: map[string]string{
|
||||||
"Content-Length": "5",
|
"Content-Length": "5",
|
||||||
"Content-Disposition": `inline;filename="file.jpg\"evil"`,
|
"Content-Disposition": `inline;filename="file.jpg\"evil"`,
|
||||||
},
|
},
|
||||||
|
Code: http.StatusOK,
|
||||||
|
ResBody: "hello",
|
||||||
}).Run(handler, t)
|
}).Run(handler, t)
|
||||||
|
|
||||||
if !reader.closed {
|
if !reader.closed {
|
||||||
|
|
31
head_test.go
31
head_test.go
|
@ -5,22 +5,35 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHead(t *testing.T) {
|
func TestHead(t *testing.T) {
|
||||||
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore) {
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
ctrl := gomock.NewController(t)
|
||||||
Offset: 11,
|
defer ctrl.Finish()
|
||||||
Size: 44,
|
locker := NewMockLocker(ctrl)
|
||||||
MetaData: map[string]string{
|
|
||||||
"name": "lunrjs.png",
|
gomock.InOrder(
|
||||||
"type": "image/png",
|
locker.EXPECT().LockUpload("yes"),
|
||||||
},
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
}, nil)
|
Offset: 11,
|
||||||
|
Size: 44,
|
||||||
|
MetaData: map[string]string{
|
||||||
|
"name": "lunrjs.png",
|
||||||
|
"type": "image/png",
|
||||||
|
},
|
||||||
|
}, nil),
|
||||||
|
locker.EXPECT().UnlockUpload("yes"),
|
||||||
|
)
|
||||||
|
|
||||||
|
composer := NewStoreComposer()
|
||||||
|
composer.UseCore(store)
|
||||||
|
composer.UseLocker(locker)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
res := (&httpTest{
|
res := (&httpTest{
|
||||||
|
|
14
post_test.go
14
post_test.go
|
@ -171,6 +171,10 @@ func TestPost(t *testing.T) {
|
||||||
|
|
||||||
SubTest(t, "WithUpload", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "WithUpload", func(t *testing.T, store *MockFullDataStore) {
|
||||||
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
locker := NewMockLocker(ctrl)
|
||||||
|
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
store.EXPECT().NewUpload(FileInfo{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
|
@ -179,12 +183,18 @@ func TestPost(t *testing.T) {
|
||||||
"bar": "world",
|
"bar": "world",
|
||||||
},
|
},
|
||||||
}).Return("foo", nil),
|
}).Return("foo", nil),
|
||||||
|
locker.EXPECT().LockUpload("foo"),
|
||||||
store.EXPECT().WriteChunk("foo", int64(0), NewReaderMatcher("hello")).Return(int64(5), nil),
|
store.EXPECT().WriteChunk("foo", int64(0), NewReaderMatcher("hello")).Return(int64(5), nil),
|
||||||
|
locker.EXPECT().UnlockUpload("foo"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
composer := NewStoreComposer()
|
||||||
|
composer.UseCore(store)
|
||||||
|
composer.UseLocker(locker)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -29,14 +30,27 @@ func TestTerminate(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
SubTest(t, "Termination", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "Termination", func(t *testing.T, store *MockFullDataStore) {
|
||||||
store.EXPECT().GetInfo("foo").Return(FileInfo{
|
ctrl := gomock.NewController(t)
|
||||||
ID: "foo",
|
defer ctrl.Finish()
|
||||||
Size: 10,
|
locker := NewMockLocker(ctrl)
|
||||||
}, nil)
|
|
||||||
store.EXPECT().Terminate("foo").Return(nil)
|
gomock.InOrder(
|
||||||
|
locker.EXPECT().LockUpload("foo"),
|
||||||
|
store.EXPECT().GetInfo("foo").Return(FileInfo{
|
||||||
|
ID: "foo",
|
||||||
|
Size: 10,
|
||||||
|
}, nil),
|
||||||
|
store.EXPECT().Terminate("foo").Return(nil),
|
||||||
|
locker.EXPECT().UnlockUpload("foo"),
|
||||||
|
)
|
||||||
|
|
||||||
|
composer := NewStoreComposer()
|
||||||
|
composer.UseCore(store)
|
||||||
|
composer.UseTerminater(store)
|
||||||
|
composer.UseLocker(locker)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
NotifyTerminatedUploads: true,
|
NotifyTerminatedUploads: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue