core: Refactor DataStore

This commit is contained in:
Marius 2019-08-25 22:10:55 +02:00
parent 5acc586800
commit 5004d3ca4d
8 changed files with 377 additions and 212 deletions

View File

@ -32,13 +32,27 @@ func TestConcat(t *testing.T) {
SubTest(t, "Partial", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
IsPartial: true,
IsFinal: false,
PartialUploads: nil,
MetaData: make(map[string]string),
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 300,
IsPartial: true,
IsFinal: false,
PartialUploads: nil,
MetaData: make(map[string]string),
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
IsPartial: true,
IsFinal: false,
PartialUploads: nil,
MetaData: make(map[string]string),
}, nil),
)
handler, _ := NewHandler(Config{
BasePath: "files",
@ -57,9 +71,17 @@ func TestConcat(t *testing.T) {
})
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("foo").Return(FileInfo{
IsPartial: true,
}, nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetUpload("foo").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
IsPartial: true,
}, nil),
)
handler, _ := NewHandler(Config{
BasePath: "files",
@ -84,13 +106,21 @@ func TestConcat(t *testing.T) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
uploadA := NewMockFullUpload(ctrl)
uploadB := NewMockFullUpload(ctrl)
uploadC := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("a").Return(FileInfo{
store.EXPECT().GetUpload("a").Return(uploadA, nil),
uploadA.EXPECT().GetInfo().Return(FileInfo{
IsPartial: true,
Size: 5,
Offset: 5,
}, nil),
store.EXPECT().GetInfo("b").Return(FileInfo{
store.EXPECT().GetUpload("b").Return(uploadB, nil),
uploadB.EXPECT().GetInfo().Return(FileInfo{
IsPartial: true,
Size: 5,
Offset: 5,
@ -101,7 +131,15 @@ func TestConcat(t *testing.T) {
IsFinal: true,
PartialUploads: []string{"a", "b"},
MetaData: make(map[string]string),
}).Return("foo", nil),
}).Return(uploadC, nil),
uploadC.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 10,
IsPartial: false,
IsFinal: true,
PartialUploads: []string{"a", "b"},
MetaData: make(map[string]string),
}, nil),
store.EXPECT().ConcatUploads("foo", []string{"a", "b"}).Return(nil),
)
@ -136,12 +174,20 @@ func TestConcat(t *testing.T) {
})
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("foo").Return(FileInfo{
IsFinal: true,
PartialUploads: []string{"a", "b"},
Size: 10,
Offset: 10,
}, nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetUpload("foo").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
IsFinal: true,
PartialUploads: []string{"a", "b"},
Size: 10,
Offset: 10,
}, nil),
)
handler, _ := NewHandler(Config{
BasePath: "files",
@ -164,13 +210,21 @@ func TestConcat(t *testing.T) {
})
SubTest(t, "CreateWithUnfinishedFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
// This upload is still unfinished (mismatching offset and size) and
// will therefore cause the POST request to fail.
store.EXPECT().GetInfo("c").Return(FileInfo{
IsPartial: true,
Size: 5,
Offset: 3,
}, nil)
gomock.InOrder(
store.EXPECT().GetUpload("c").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "c",
IsPartial: true,
Size: 5,
Offset: 3,
}, nil),
)
handler, _ := NewHandler(Config{
BasePath: "files",
@ -188,10 +242,18 @@ func TestConcat(t *testing.T) {
})
SubTest(t, "CreateExceedingMaxSizeFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("huge").Return(FileInfo{
Size: 1000,
Offset: 1000,
}, nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetUpload("huge").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "huge",
Size: 1000,
Offset: 1000,
}, nil),
)
handler, _ := NewHandler(Config{
MaxSize: 100,
@ -210,11 +272,19 @@ func TestConcat(t *testing.T) {
})
SubTest(t, "UploadToFinalFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("foo").Return(FileInfo{
Size: 10,
Offset: 0,
IsFinal: true,
}, nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetUpload("foo").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 10,
Offset: 0,
IsFinal: true,
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,

View File

@ -1,93 +0,0 @@
package handler_test
import (
"net/http"
"testing"
"github.com/golang/mock/gomock"
. "github.com/tus/tusd/pkg/handler"
"github.com/stretchr/testify/assert"
)
func TestTerminate(t *testing.T) {
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
composer = NewStoreComposer()
composer.UseCore(store)
composer.UseTerminater(store)
handler, _ := NewHandler(Config{
StoreComposer: composer,
})
(&httpTest{
Method: "OPTIONS",
Code: http.StatusOK,
ResHeader: map[string]string{
"Tus-Extension": "creation,creation-with-upload,termination",
},
}).Run(handler, t)
})
SubTest(t, "Termination", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
locker := NewMockLocker(ctrl)
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{
StoreComposer: composer,
NotifyTerminatedUploads: true,
})
c := make(chan FileInfo, 1)
handler.TerminatedUploads = c
(&httpTest{
Method: "DELETE",
URL: "foo",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
},
Code: http.StatusNoContent,
}).Run(handler, t)
info := <-c
a := assert.New(t)
a.Equal("foo", info.ID)
a.Equal(int64(10), info.Size)
})
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
composer = NewStoreComposer()
composer.UseCore(store)
handler, _ := NewUnroutedHandler(Config{
StoreComposer: composer,
})
(&httpTest{
Method: "DELETE",
URL: "foo",
ReqHeader: map[string]string{
"Tus-Resumable": "1.0.0",
},
Code: http.StatusNotImplemented,
}).Run(http.HandlerFunc(handler.DelFile), t)
})
}

View File

@ -14,10 +14,12 @@ func TestHead(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
locker := NewMockLocker(ctrl)
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
locker.EXPECT().LockUpload("yes"),
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
Offset: 11,
Size: 44,
MetaData: map[string]string{
@ -59,7 +61,7 @@ func TestHead(t *testing.T) {
})
SubTest(t, "UploadNotFoundFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("no").Return(FileInfo{}, os.ErrNotExist)
store.EXPECT().GetUpload("no").Return(nil, os.ErrNotExist)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -83,10 +85,17 @@ func TestHead(t *testing.T) {
})
SubTest(t, "DeferLengthHeader", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
SizeIsDeferred: true,
Size: 0,
}, nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
SizeIsDeferred: true,
Size: 0,
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -106,8 +115,13 @@ func TestHead(t *testing.T) {
})
SubTest(t, "NoDeferLengthHeader", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
SizeIsDeferred: false,
Size: 10,
}, nil),

View File

@ -17,14 +17,19 @@ import (
func TestPatch(t *testing.T) {
SubTest(t, "UploadChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 5,
Size: 10,
}, nil),
store.EXPECT().WriteChunk("yes", int64(5), NewReaderMatcher("hello")).Return(int64(5), nil),
store.EXPECT().FinishUpload("yes"),
upload.EXPECT().WriteChunk(int64(5), NewReaderMatcher("hello")).Return(int64(5), nil),
upload.EXPECT().FinishUpload(),
)
handler, _ := NewHandler(Config{
@ -58,13 +63,19 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "MethodOverriding", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 5,
Size: 20,
Size: 10,
}, nil),
store.EXPECT().WriteChunk("yes", int64(5), NewReaderMatcher("hello")).Return(int64(5), nil),
upload.EXPECT().WriteChunk(int64(5), NewReaderMatcher("hello")).Return(int64(5), nil),
upload.EXPECT().FinishUpload(),
)
handler, _ := NewHandler(Config{
@ -89,10 +100,18 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "UploadChunkToFinished", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 20,
Size: 20,
}, nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 20,
Size: 20,
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -115,7 +134,7 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "UploadNotFoundFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("no").Return(FileInfo{}, os.ErrNotExist)
store.EXPECT().GetUpload("no").Return(nil, os.ErrNotExist)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -134,9 +153,17 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "MissmatchingOffsetFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 5,
}, nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 5,
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -155,10 +182,18 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "ExceedingMaxSizeFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 5,
Size: 10,
}, nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 5,
Size: 10,
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -221,14 +256,19 @@ func TestPatch(t *testing.T) {
// is that even if the uploader supplies more than 15 bytes, we only
// pass 15 bytes to the data store and ignore the rest.
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 5,
Size: 20,
}, nil),
store.EXPECT().WriteChunk("yes", int64(5), NewReaderMatcher("hellothisismore")).Return(int64(15), nil),
store.EXPECT().FinishUpload("yes"),
upload.EXPECT().WriteChunk(int64(5), NewReaderMatcher("hellothisismore")).Return(int64(15), nil),
upload.EXPECT().FinishUpload(),
)
handler, _ := NewHandler(Config{
@ -258,16 +298,22 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "DeclareLengthOnFinalChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 5,
Size: 0,
SizeIsDeferred: true,
}, nil),
store.EXPECT().DeclareLength("yes", int64(20)),
store.EXPECT().WriteChunk("yes", int64(5), NewReaderMatcher("hellothisismore")).Return(int64(15), nil),
store.EXPECT().FinishUpload("yes"),
store.EXPECT().AsLengthDeclarableUpload(upload).Return(upload),
upload.EXPECT().DeclareLength(int64(20)),
upload.EXPECT().WriteChunk(int64(5), NewReaderMatcher("hellothisismore")).Return(int64(15), nil),
upload.EXPECT().FinishUpload(),
)
handler, _ := NewHandler(Config{
@ -295,15 +341,21 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "DeclareLengthAfterFinalChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 20,
Size: 0,
SizeIsDeferred: true,
}, nil),
store.EXPECT().DeclareLength("yes", int64(20)),
store.EXPECT().FinishUpload("yes"),
store.EXPECT().AsLengthDeclarableUpload(upload).Return(upload),
upload.EXPECT().DeclareLength(int64(20)),
upload.EXPECT().FinishUpload(),
)
handler, _ := NewHandler(Config{
@ -327,23 +379,32 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "DeclareLengthOnNonFinalChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload1 := NewMockFullUpload(ctrl)
upload2 := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload1, nil),
upload1.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 5,
Size: 0,
SizeIsDeferred: true,
}, nil),
store.EXPECT().DeclareLength("yes", int64(20)),
store.EXPECT().WriteChunk("yes", int64(5), NewReaderMatcher("hello")).Return(int64(5), nil),
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().AsLengthDeclarableUpload(upload1).Return(upload1),
upload1.EXPECT().DeclareLength(int64(20)),
upload1.EXPECT().WriteChunk(int64(5), NewReaderMatcher("hello")).Return(int64(5), nil),
store.EXPECT().GetUpload("yes").Return(upload2, nil),
upload2.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 10,
Size: 20,
SizeIsDeferred: false,
}, nil),
store.EXPECT().WriteChunk("yes", int64(10), NewReaderMatcher("thisismore")).Return(int64(10), nil),
store.EXPECT().FinishUpload("yes"),
upload2.EXPECT().WriteChunk(int64(10), NewReaderMatcher("thisismore")).Return(int64(10), nil),
upload2.EXPECT().FinishUpload(),
)
handler, _ := NewHandler(Config{
@ -387,14 +448,17 @@ func TestPatch(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
locker := NewMockLocker(ctrl)
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
locker.EXPECT().LockUpload("yes").Return(nil),
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 0,
Size: 20,
}, nil),
store.EXPECT().WriteChunk("yes", int64(0), NewReaderMatcher("hello")).Return(int64(5), nil),
upload.EXPECT().WriteChunk(int64(0), NewReaderMatcher("hello")).Return(int64(5), nil),
locker.EXPECT().UnlockUpload("yes").Return(nil),
)
@ -420,13 +484,18 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "NotifyUploadProgress", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 0,
Size: 100,
}, nil),
store.EXPECT().WriteChunk("yes", int64(0), NewReaderMatcher("first second third")).Return(int64(18), nil),
upload.EXPECT().WriteChunk(int64(0), NewReaderMatcher("first second third")).Return(int64(18), nil),
)
handler, _ := NewHandler(Config{
@ -487,14 +556,20 @@ func TestPatch(t *testing.T) {
})
SubTest(t, "StopUpload", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
store.EXPECT().GetUpload("yes").Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "yes",
Offset: 0,
Size: 100,
}, nil),
store.EXPECT().WriteChunk("yes", int64(0), NewReaderMatcher("first ")).Return(int64(6), http.ErrBodyReadAfterClose),
store.EXPECT().Terminate("yes").Return(nil),
upload.EXPECT().WriteChunk(int64(0), NewReaderMatcher("first ")).Return(int64(6), http.ErrBodyReadAfterClose),
store.EXPECT().AsTerminatableUpload(upload).Return(upload),
upload.EXPECT().Terminate(),
)
handler, _ := NewHandler(Config{

View File

@ -14,13 +14,27 @@ import (
func TestPost(t *testing.T) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{
"foo": "hello",
"bar": "world",
},
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{
"foo": "hello",
"bar": "world",
},
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{
"foo": "hello",
"bar": "world",
},
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -53,12 +67,22 @@ func TestPost(t *testing.T) {
})
SubTest(t, "CreateEmptyUpload", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 0,
MetaData: map[string]string{},
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
store.EXPECT().FinishUpload("foo").Return(nil)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 0,
MetaData: map[string]string{},
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 0,
MetaData: map[string]string{},
}, nil),
upload.EXPECT().FinishUpload().Return(nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -173,10 +197,21 @@ func TestPost(t *testing.T) {
SubTest(t, "ForwardHeaders", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
SubTest(t, "IgnoreXForwarded", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{},
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -199,10 +234,21 @@ func TestPost(t *testing.T) {
})
SubTest(t, "RespectXForwarded", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{},
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -226,10 +272,21 @@ func TestPost(t *testing.T) {
})
SubTest(t, "RespectForwarded", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{},
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -254,10 +311,21 @@ func TestPost(t *testing.T) {
})
SubTest(t, "FilterForwardedProtocol", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{},
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -286,6 +354,7 @@ func TestPost(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
locker := NewMockLocker(ctrl)
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
@ -294,9 +363,17 @@ func TestPost(t *testing.T) {
"foo": "hello",
"bar": "world",
},
}).Return("foo", nil),
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{
"foo": "hello",
"bar": "world",
},
}, nil),
locker.EXPECT().LockUpload("foo"),
store.EXPECT().WriteChunk("foo", int64(0), NewReaderMatcher("hello")).Return(int64(5), nil),
upload.EXPECT().WriteChunk(int64(0), NewReaderMatcher("hello")).Return(int64(5), nil),
locker.EXPECT().UnlockUpload("foo"),
)
@ -327,10 +404,21 @@ func TestPost(t *testing.T) {
})
SubTest(t, "CreateExceedingUploadSize", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{},
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,
@ -350,10 +438,21 @@ func TestPost(t *testing.T) {
})
SubTest(t, "IncorrectContentType", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
upload := NewMockFullUpload(ctrl)
gomock.InOrder(
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return(upload, nil),
upload.EXPECT().GetInfo().Return(FileInfo{
ID: "foo",
Size: 300,
MetaData: map[string]string{},
}, nil),
)
handler, _ := NewHandler(Config{
StoreComposer: composer,