core: Remove deprecated DataStore option

This commit is contained in:
Marius 2019-08-20 16:16:05 +02:00
parent 647c65a125
commit aa0280d004
13 changed files with 149 additions and 202 deletions

View File

@ -25,35 +25,6 @@ func NewStoreComposer() *StoreComposer {
return &StoreComposer{}
}
// newStoreComposerFromDataStore creates a new store composer and attempts to
// extract the extensions for the provided store. This is intended to be used
// for transitioning from data stores to composers.
func newStoreComposerFromDataStore(store DataStore) *StoreComposer {
composer := NewStoreComposer()
composer.UseCore(store)
if mod, ok := store.(TerminaterDataStore); ok {
composer.UseTerminater(mod)
}
if mod, ok := store.(FinisherDataStore); ok {
composer.UseFinisher(mod)
}
if mod, ok := store.(LockerDataStore); ok {
composer.UseLocker(mod)
}
if mod, ok := store.(GetReaderDataStore); ok {
composer.UseGetReader(mod)
}
if mod, ok := store.(ConcaterDataStore); ok {
composer.UseConcater(mod)
}
if mod, ok := store.(LengthDeferrerDataStore); ok {
composer.UseLengthDeferrer(mod)
}
return composer
}
// Capabilities returns a string representing the provided extensions in a
// human-readable format meant for debugging.
func (store *StoreComposer) Capabilities() string {

View File

@ -39,23 +39,6 @@ func NewStoreComposer() *StoreComposer {
return &StoreComposer{}
}
// newStoreComposerFromDataStore creates a new store composer and attempts to
// extract the extensions for the provided store. This is intended to be used
// for transitioning from data stores to composers.
func newStoreComposerFromDataStore(store DataStore) *StoreComposer {
composer := NewStoreComposer()
composer.UseCore(store)
USE_FROM(Terminater)
USE_FROM(Finisher)
USE_FROM(Locker)
USE_FROM(GetReader)
USE_FROM(Concater)
USE_FROM(LengthDeferrer)
return composer
}
// Capabilities returns a string representing the provided extensions in a
// human-readable format meant for debugging.
func (store *StoreComposer) Capabilities() string {

View File

@ -12,8 +12,8 @@ import (
)
func TestConcat(t *testing.T) {
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore) {
composer := NewStoreComposer()
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
composer = NewStoreComposer()
composer.UseCore(store)
composer.UseConcater(store)
@ -30,8 +30,8 @@ func TestConcat(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "Partial", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore) {
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,
@ -42,7 +42,7 @@ func TestConcat(t *testing.T) {
handler, _ := NewHandler(Config{
BasePath: "files",
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -56,14 +56,14 @@ func TestConcat(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("foo").Return(FileInfo{
IsPartial: true,
}, nil)
handler, _ := NewHandler(Config{
BasePath: "files",
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -80,8 +80,8 @@ func TestConcat(t *testing.T) {
})
})
SubTest(t, "Final", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Final", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
a := assert.New(t)
gomock.InOrder(
@ -107,7 +107,7 @@ func TestConcat(t *testing.T) {
handler, _ := NewHandler(Config{
BasePath: "files",
DataStore: store,
StoreComposer: composer,
NotifyCompleteUploads: true,
})
@ -135,7 +135,7 @@ func TestConcat(t *testing.T) {
a.Equal([]string{"a", "b"}, info.PartialUploads)
})
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("foo").Return(FileInfo{
IsFinal: true,
PartialUploads: []string{"a", "b"},
@ -145,7 +145,7 @@ func TestConcat(t *testing.T) {
handler, _ := NewHandler(Config{
BasePath: "files",
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -163,7 +163,7 @@ func TestConcat(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "CreateWithUnfinishedFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "CreateWithUnfinishedFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
// This upload is still unfinished (mismatching offset and size) and
// will therefore cause the POST request to fail.
store.EXPECT().GetInfo("c").Return(FileInfo{
@ -174,7 +174,7 @@ func TestConcat(t *testing.T) {
handler, _ := NewHandler(Config{
BasePath: "files",
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -187,7 +187,7 @@ func TestConcat(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "CreateExceedingMaxSizeFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "CreateExceedingMaxSizeFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("huge").Return(FileInfo{
Size: 1000,
Offset: 1000,
@ -196,7 +196,7 @@ func TestConcat(t *testing.T) {
handler, _ := NewHandler(Config{
MaxSize: 100,
BasePath: "files",
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -209,7 +209,7 @@ func TestConcat(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "UploadToFinalFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "UploadToFinalFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("foo").Return(FileInfo{
Size: 10,
Offset: 0,
@ -217,7 +217,7 @@ func TestConcat(t *testing.T) {
}, nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -233,9 +233,9 @@ func TestConcat(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "InvalidConcatHeaderFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "InvalidConcatHeaderFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{

View File

@ -9,13 +9,10 @@ import (
// Config provides a way to configure the Handler depending on your needs.
type Config struct {
// DataStore implementation used to store and retrieve the single uploads.
// The usage of this field is deprecated and should be avoided in favor of
// StoreComposer.
DataStore DataStore
// StoreComposer points to the store composer from which the core data store
// and optional dependencies should be taken. May only be nil if DataStore is
// set.
// TODO: Remove pointer?
StoreComposer *StoreComposer
// MaxSize defines how many bytes may be stored in one single upload. If its
// value is is 0 or smaller no limit will be enforced.
@ -69,10 +66,7 @@ func (config *Config) validate() error {
config.isAbs = uri.IsAbs()
if config.StoreComposer == nil {
config.StoreComposer = newStoreComposerFromDataStore(config.DataStore)
config.DataStore = nil
} else if config.DataStore != nil {
return errors.New("tusd: either StoreComposer or DataStore may be set in Config, but not both")
return errors.New("tusd: StoreComposer must no be nil")
}
if config.StoreComposer.Core == nil {

View File

@ -23,8 +23,11 @@ func (store zeroStore) GetInfo(id string) (FileInfo, error) {
func TestConfig(t *testing.T) {
a := assert.New(t)
composer := NewStoreComposer()
composer.UseCore(zeroStore{})
config := Config{
DataStore: zeroStore{},
StoreComposer: composer,
BasePath: "files",
}
@ -43,16 +46,3 @@ func TestConfigEmptyCore(t *testing.T) {
a.Error(config.validate())
}
func TestConfigStoreAndComposer(t *testing.T) {
a := assert.New(t)
composer := NewStoreComposer()
composer.UseCore(zeroStore{})
config := Config{
StoreComposer: composer,
DataStore: zeroStore{},
}
a.Error(config.validate())
}

View File

@ -9,9 +9,9 @@ import (
)
func TestCORS(t *testing.T) {
SubTest(t, "Preflight", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Preflight", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -29,9 +29,9 @@ func TestCORS(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "Request", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Request", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -48,9 +48,9 @@ func TestCORS(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "AppendHeaders", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "AppendHeaders", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
req, _ := http.NewRequest("OPTIONS", "", nil)

View File

@ -20,7 +20,7 @@ func (reader *closingStringReader) Close() error {
}
func TestGet(t *testing.T) {
SubTest(t, "Download", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Download", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
reader := &closingStringReader{
Reader: strings.NewReader("hello"),
}
@ -43,7 +43,7 @@ func TestGet(t *testing.T) {
locker.EXPECT().UnlockUpload("yes"),
)
composer := NewStoreComposer()
composer = NewStoreComposer()
composer.UseCore(store)
composer.UseGetReader(store)
composer.UseLocker(locker)
@ -69,13 +69,13 @@ func TestGet(t *testing.T) {
}
})
SubTest(t, "EmptyDownload", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "EmptyDownload", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 0,
}, nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -90,8 +90,8 @@ func TestGet(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore) {
composer := NewStoreComposer()
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
composer = NewStoreComposer()
composer.UseCore(store)
handler, _ := NewUnroutedHandler(Config{
@ -105,7 +105,7 @@ func TestGet(t *testing.T) {
}).Run(http.HandlerFunc(handler.GetFile), t)
})
SubTest(t, "InvalidFileType", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "InvalidFileType", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 0,
MetaData: map[string]string{
@ -114,7 +114,7 @@ func TestGet(t *testing.T) {
}, nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -130,7 +130,7 @@ func TestGet(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "NotWhitelistedFileType", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "NotWhitelistedFileType", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 0,
MetaData: map[string]string{
@ -140,7 +140,7 @@ func TestGet(t *testing.T) {
}, nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{

View File

@ -10,7 +10,7 @@ import (
)
func TestHead(t *testing.T) {
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
locker := NewMockLocker(ctrl)
@ -28,7 +28,7 @@ func TestHead(t *testing.T) {
locker.EXPECT().UnlockUpload("yes"),
)
composer := NewStoreComposer()
composer = NewStoreComposer()
composer.UseCore(store)
composer.UseLocker(locker)
@ -58,11 +58,11 @@ func TestHead(t *testing.T) {
}
})
SubTest(t, "UploadNotFoundFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "UploadNotFoundFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("no").Return(FileInfo{}, os.ErrNotExist)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
res := (&httpTest{
@ -82,14 +82,14 @@ func TestHead(t *testing.T) {
}
})
SubTest(t, "DeferLengthHeader", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "DeferLengthHeader", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
SizeIsDeferred: true,
Size: 0,
}, nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -105,7 +105,7 @@ func TestHead(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "NoDeferLengthHeader", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "NoDeferLengthHeader", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
SizeIsDeferred: false,
@ -114,7 +114,7 @@ func TestHead(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{

View File

@ -8,8 +8,8 @@ import (
)
func TestOptions(t *testing.T) {
SubTest(t, "Discovery", func(t *testing.T, store *MockFullDataStore) {
composer := NewStoreComposer()
SubTest(t, "Discovery", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
composer = NewStoreComposer()
composer.UseCore(store)
handler, _ := NewHandler(Config{
@ -29,9 +29,9 @@ func TestOptions(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "InvalidVersion", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "InvalidVersion", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{

View File

@ -16,7 +16,7 @@ import (
)
func TestPatch(t *testing.T) {
SubTest(t, "UploadChunk", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "UploadChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
ID: "yes",
@ -28,7 +28,7 @@ func TestPatch(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
NotifyCompleteUploads: true,
})
@ -57,7 +57,7 @@ func TestPatch(t *testing.T) {
a.Equal(int64(10), info.Offset)
})
SubTest(t, "MethodOverriding", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "MethodOverriding", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
ID: "yes",
@ -68,7 +68,7 @@ func TestPatch(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -88,14 +88,14 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "UploadChunkToFinished", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "UploadChunkToFinished", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 20,
Size: 20,
}, nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -114,11 +114,11 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "UploadNotFoundFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "UploadNotFoundFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("no").Return(FileInfo{}, os.ErrNotExist)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -133,13 +133,13 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "MissmatchingOffsetFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "MissmatchingOffsetFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 5,
}, nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -154,14 +154,14 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "ExceedingMaxSizeFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "ExceedingMaxSizeFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().GetInfo("yes").Return(FileInfo{
Offset: 5,
Size: 10,
}, nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -177,9 +177,9 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "InvalidContentTypeFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "InvalidContentTypeFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -195,9 +195,9 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "InvalidOffsetFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "InvalidOffsetFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -213,7 +213,7 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "OverflowWithoutLength", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "OverflowWithoutLength", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
// In this test we attempt to upload more than 15 bytes to an upload
// which has only space for 15 bytes (offset of 5 and size of 20).
// The request does not contain the Content-Length header and the handler
@ -232,7 +232,7 @@ func TestPatch(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
// Wrap the string.Reader in a NopCloser to hide its type. else
@ -257,7 +257,7 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "DeclareLengthOnFinalChunk", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "DeclareLengthOnFinalChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
ID: "yes",
@ -271,7 +271,7 @@ func TestPatch(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
MaxSize: 20,
})
@ -294,7 +294,7 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "DeclareLengthAfterFinalChunk", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "DeclareLengthAfterFinalChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
ID: "yes",
@ -307,7 +307,7 @@ func TestPatch(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
MaxSize: 20,
})
@ -326,7 +326,7 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "DeclareLengthOnNonFinalChunk", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "DeclareLengthOnNonFinalChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
ID: "yes",
@ -347,7 +347,7 @@ func TestPatch(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
MaxSize: 20,
})
@ -383,7 +383,7 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "Locker", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Locker", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
locker := NewMockLocker(ctrl)
@ -398,7 +398,7 @@ func TestPatch(t *testing.T) {
locker.EXPECT().UnlockUpload("yes").Return(nil),
)
composer := NewStoreComposer()
composer = NewStoreComposer()
composer.UseCore(store)
composer.UseLocker(locker)
@ -419,7 +419,7 @@ func TestPatch(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "NotifyUploadProgress", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "NotifyUploadProgress", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
ID: "yes",
@ -430,7 +430,7 @@ func TestPatch(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
NotifyUploadProgress: true,
})
@ -486,7 +486,7 @@ func TestPatch(t *testing.T) {
a.False(more)
})
SubTest(t, "StopUpload", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "StopUpload", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
gomock.InOrder(
store.EXPECT().GetInfo("yes").Return(FileInfo{
ID: "yes",
@ -498,7 +498,7 @@ func TestPatch(t *testing.T) {
)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
NotifyUploadProgress: true,
})

View File

@ -13,7 +13,7 @@ import (
)
func TestPost(t *testing.T) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{
@ -23,7 +23,7 @@ func TestPost(t *testing.T) {
}).Return("foo", nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "https://buy.art/files/",
NotifyCreatedUploads: true,
})
@ -52,7 +52,7 @@ func TestPost(t *testing.T) {
a.Equal(int64(300), info.Size)
})
SubTest(t, "CreateEmptyUpload", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "CreateEmptyUpload", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 0,
MetaData: map[string]string{},
@ -61,7 +61,7 @@ func TestPost(t *testing.T) {
store.EXPECT().FinishUpload("foo").Return(nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "https://buy.art/files/",
NotifyCompleteUploads: true,
})
@ -88,10 +88,10 @@ func TestPost(t *testing.T) {
a.Equal(int64(0), info.Offset)
})
SubTest(t, "CreateExceedingMaxSizeFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "CreateExceedingMaxSizeFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
MaxSize: 400,
DataStore: store,
StoreComposer: composer,
BasePath: "/files/",
})
@ -107,9 +107,9 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "InvalidUploadLengthFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "InvalidUploadLengthFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -123,9 +123,9 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "UploadLengthAndUploadDeferLengthFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "UploadLengthAndUploadDeferLengthFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -140,9 +140,9 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "NeitherUploadLengthNorUploadDeferLengthFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "NeitherUploadLengthNorUploadDeferLengthFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -155,9 +155,9 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "InvalidUploadDeferLengthFail", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "InvalidUploadDeferLengthFail", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
})
(&httpTest{
@ -171,15 +171,15 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "ForwardHeaders", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "IgnoreXForwarded", func(t *testing.T, store *MockFullDataStore) {
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)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "/files/",
})
@ -198,14 +198,14 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "RespectXForwarded", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "RespectXForwarded", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "/files/",
RespectForwardedHeaders: true,
})
@ -225,14 +225,14 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "RespectForwarded", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "RespectForwarded", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "/files/",
RespectForwardedHeaders: true,
})
@ -253,14 +253,14 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "FilterForwardedProtocol", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "FilterForwardedProtocol", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "/files/",
RespectForwardedHeaders: true,
})
@ -281,8 +281,8 @@ func TestPost(t *testing.T) {
})
})
SubTest(t, "WithUpload", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "WithUpload", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
locker := NewMockLocker(ctrl)
@ -300,7 +300,7 @@ func TestPost(t *testing.T) {
locker.EXPECT().UnlockUpload("foo"),
)
composer := NewStoreComposer()
composer = NewStoreComposer()
composer.UseCore(store)
composer.UseLocker(locker)
@ -326,14 +326,14 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "CreateExceedingUploadSize", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "CreateExceedingUploadSize", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "/files/",
})
@ -349,14 +349,14 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "IncorrectContentType", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "IncorrectContentType", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
store.EXPECT().NewUpload(FileInfo{
Size: 300,
MetaData: map[string]string{},
}).Return("foo", nil)
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "/files/",
})
@ -377,9 +377,9 @@ func TestPost(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "UploadToFinalUpload", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "UploadToFinalUpload", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
handler, _ := NewHandler(Config{
DataStore: store,
StoreComposer: composer,
BasePath: "/files/",
})

View File

@ -3,10 +3,12 @@ package handler_test
import (
"testing"
"github.com/tus/tusd/pkg/handler"
"github.com/golang/mock/gomock"
)
func SubTest(t *testing.T, name string, runTest func(*testing.T, *MockFullDataStore)) {
func SubTest(t *testing.T, name string, runTest func(*testing.T, *MockFullDataStore, *handler.StoreComposer)) {
t.Run(name, func(subT *testing.T) {
//subT.Parallel()
@ -14,7 +16,14 @@ func SubTest(t *testing.T, name string, runTest func(*testing.T, *MockFullDataSt
defer ctrl.Finish()
store := NewMockFullDataStore(ctrl)
composer := handler.NewStoreComposer()
composer.UseCore(store)
composer.UseTerminater(store)
composer.UseFinisher(store)
composer.UseGetReader(store)
composer.UseConcater(store)
composer.UseLengthDeferrer(store)
runTest(subT, store)
runTest(subT, store, composer)
})
}

View File

@ -11,8 +11,8 @@ import (
)
func TestTerminate(t *testing.T) {
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore) {
composer := NewStoreComposer()
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
composer = NewStoreComposer()
composer.UseCore(store)
composer.UseTerminater(store)
@ -29,7 +29,7 @@ func TestTerminate(t *testing.T) {
}).Run(handler, t)
})
SubTest(t, "Termination", func(t *testing.T, store *MockFullDataStore) {
SubTest(t, "Termination", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
locker := NewMockLocker(ctrl)
@ -44,7 +44,7 @@ func TestTerminate(t *testing.T) {
locker.EXPECT().UnlockUpload("foo"),
)
composer := NewStoreComposer()
composer = NewStoreComposer()
composer.UseCore(store)
composer.UseTerminater(store)
composer.UseLocker(locker)
@ -73,8 +73,8 @@ func TestTerminate(t *testing.T) {
a.Equal(int64(10), info.Size)
})
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore) {
composer := NewStoreComposer()
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
composer = NewStoreComposer()
composer.UseCore(store)
handler, _ := NewUnroutedHandler(Config{