core: Remove deprecated DataStore option
This commit is contained in:
parent
647c65a125
commit
aa0280d004
|
@ -25,35 +25,6 @@ func NewStoreComposer() *StoreComposer {
|
||||||
return &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
|
// Capabilities returns a string representing the provided extensions in a
|
||||||
// human-readable format meant for debugging.
|
// human-readable format meant for debugging.
|
||||||
func (store *StoreComposer) Capabilities() string {
|
func (store *StoreComposer) Capabilities() string {
|
||||||
|
|
|
@ -39,23 +39,6 @@ func NewStoreComposer() *StoreComposer {
|
||||||
return &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
|
// Capabilities returns a string representing the provided extensions in a
|
||||||
// human-readable format meant for debugging.
|
// human-readable format meant for debugging.
|
||||||
func (store *StoreComposer) Capabilities() string {
|
func (store *StoreComposer) Capabilities() string {
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConcat(t *testing.T) {
|
func TestConcat(t *testing.T) {
|
||||||
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseConcater(store)
|
composer.UseConcater(store)
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ func TestConcat(t *testing.T) {
|
||||||
}).Run(handler, t)
|
}).Run(handler, t)
|
||||||
})
|
})
|
||||||
|
|
||||||
SubTest(t, "Partial", 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) {
|
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
store.EXPECT().NewUpload(FileInfo{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
IsPartial: true,
|
IsPartial: true,
|
||||||
|
@ -41,8 +41,8 @@ func TestConcat(t *testing.T) {
|
||||||
}).Return("foo", nil)
|
}).Return("foo", nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
BasePath: "files",
|
BasePath: "files",
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -56,14 +56,14 @@ func TestConcat(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().GetInfo("foo").Return(FileInfo{
|
||||||
IsPartial: true,
|
IsPartial: true,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
BasePath: "files",
|
BasePath: "files",
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -80,8 +80,8 @@ func TestConcat(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
SubTest(t, "Final", 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) {
|
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
|
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
|
@ -107,7 +107,7 @@ func TestConcat(t *testing.T) {
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
BasePath: "files",
|
BasePath: "files",
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
NotifyCompleteUploads: true,
|
NotifyCompleteUploads: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ func TestConcat(t *testing.T) {
|
||||||
a.Equal([]string{"a", "b"}, info.PartialUploads)
|
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{
|
store.EXPECT().GetInfo("foo").Return(FileInfo{
|
||||||
IsFinal: true,
|
IsFinal: true,
|
||||||
PartialUploads: []string{"a", "b"},
|
PartialUploads: []string{"a", "b"},
|
||||||
|
@ -144,8 +144,8 @@ func TestConcat(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
BasePath: "files",
|
BasePath: "files",
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -163,7 +163,7 @@ func TestConcat(t *testing.T) {
|
||||||
}).Run(handler, 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
|
// This upload is still unfinished (mismatching offset and size) and
|
||||||
// will therefore cause the POST request to fail.
|
// will therefore cause the POST request to fail.
|
||||||
store.EXPECT().GetInfo("c").Return(FileInfo{
|
store.EXPECT().GetInfo("c").Return(FileInfo{
|
||||||
|
@ -173,8 +173,8 @@ func TestConcat(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
BasePath: "files",
|
BasePath: "files",
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -187,16 +187,16 @@ func TestConcat(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().GetInfo("huge").Return(FileInfo{
|
||||||
Size: 1000,
|
Size: 1000,
|
||||||
Offset: 1000,
|
Offset: 1000,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
MaxSize: 100,
|
MaxSize: 100,
|
||||||
BasePath: "files",
|
BasePath: "files",
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -209,7 +209,7 @@ func TestConcat(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().GetInfo("foo").Return(FileInfo{
|
||||||
Size: 10,
|
Size: 10,
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
|
@ -217,7 +217,7 @@ func TestConcat(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -233,9 +233,9 @@ func TestConcat(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
|
|
@ -9,13 +9,10 @@ import (
|
||||||
|
|
||||||
// Config provides a way to configure the Handler depending on your needs.
|
// Config provides a way to configure the Handler depending on your needs.
|
||||||
type Config struct {
|
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
|
// 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
|
// and optional dependencies should be taken. May only be nil if DataStore is
|
||||||
// set.
|
// set.
|
||||||
|
// TODO: Remove pointer?
|
||||||
StoreComposer *StoreComposer
|
StoreComposer *StoreComposer
|
||||||
// MaxSize defines how many bytes may be stored in one single upload. If its
|
// 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.
|
// value is is 0 or smaller no limit will be enforced.
|
||||||
|
@ -69,10 +66,7 @@ func (config *Config) validate() error {
|
||||||
config.isAbs = uri.IsAbs()
|
config.isAbs = uri.IsAbs()
|
||||||
|
|
||||||
if config.StoreComposer == nil {
|
if config.StoreComposer == nil {
|
||||||
config.StoreComposer = newStoreComposerFromDataStore(config.DataStore)
|
return errors.New("tusd: StoreComposer must no be nil")
|
||||||
config.DataStore = nil
|
|
||||||
} else if config.DataStore != nil {
|
|
||||||
return errors.New("tusd: either StoreComposer or DataStore may be set in Config, but not both")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.StoreComposer.Core == nil {
|
if config.StoreComposer.Core == nil {
|
||||||
|
|
|
@ -23,9 +23,12 @@ func (store zeroStore) GetInfo(id string) (FileInfo, error) {
|
||||||
func TestConfig(t *testing.T) {
|
func TestConfig(t *testing.T) {
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
|
|
||||||
|
composer := NewStoreComposer()
|
||||||
|
composer.UseCore(zeroStore{})
|
||||||
|
|
||||||
config := Config{
|
config := Config{
|
||||||
DataStore: zeroStore{},
|
StoreComposer: composer,
|
||||||
BasePath: "files",
|
BasePath: "files",
|
||||||
}
|
}
|
||||||
|
|
||||||
a.Nil(config.validate())
|
a.Nil(config.validate())
|
||||||
|
@ -43,16 +46,3 @@ func TestConfigEmptyCore(t *testing.T) {
|
||||||
|
|
||||||
a.Error(config.validate())
|
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())
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCORS(t *testing.T) {
|
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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -29,9 +29,9 @@ func TestCORS(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -48,9 +48,9 @@ func TestCORS(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
req, _ := http.NewRequest("OPTIONS", "", nil)
|
req, _ := http.NewRequest("OPTIONS", "", nil)
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (reader *closingStringReader) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGet(t *testing.T) {
|
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 := &closingStringReader{
|
||||||
Reader: strings.NewReader("hello"),
|
Reader: strings.NewReader("hello"),
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func TestGet(t *testing.T) {
|
||||||
locker.EXPECT().UnlockUpload("yes"),
|
locker.EXPECT().UnlockUpload("yes"),
|
||||||
)
|
)
|
||||||
|
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseGetReader(store)
|
composer.UseGetReader(store)
|
||||||
composer.UseLocker(locker)
|
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{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -90,8 +90,8 @@ func TestGet(t *testing.T) {
|
||||||
}).Run(handler, t)
|
}).Run(handler, t)
|
||||||
})
|
})
|
||||||
|
|
||||||
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
|
|
||||||
handler, _ := NewUnroutedHandler(Config{
|
handler, _ := NewUnroutedHandler(Config{
|
||||||
|
@ -105,7 +105,7 @@ func TestGet(t *testing.T) {
|
||||||
}).Run(http.HandlerFunc(handler.GetFile), 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{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
MetaData: map[string]string{
|
MetaData: map[string]string{
|
||||||
|
@ -114,7 +114,7 @@ func TestGet(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -130,7 +130,7 @@ func TestGet(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
MetaData: map[string]string{
|
MetaData: map[string]string{
|
||||||
|
@ -140,7 +140,7 @@ func TestGet(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
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, composer *StoreComposer) {
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
locker := NewMockLocker(ctrl)
|
locker := NewMockLocker(ctrl)
|
||||||
|
@ -28,7 +28,7 @@ func TestHead(t *testing.T) {
|
||||||
locker.EXPECT().UnlockUpload("yes"),
|
locker.EXPECT().UnlockUpload("yes"),
|
||||||
)
|
)
|
||||||
|
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseLocker(locker)
|
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)
|
store.EXPECT().GetInfo("no").Return(FileInfo{}, os.ErrNotExist)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
res := (&httpTest{
|
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{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
SizeIsDeferred: true,
|
SizeIsDeferred: true,
|
||||||
Size: 0,
|
Size: 0,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -105,7 +105,7 @@ func TestHead(t *testing.T) {
|
||||||
}).Run(handler, 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(
|
gomock.InOrder(
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
SizeIsDeferred: false,
|
SizeIsDeferred: false,
|
||||||
|
@ -114,7 +114,7 @@ func TestHead(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOptions(t *testing.T) {
|
func TestOptions(t *testing.T) {
|
||||||
SubTest(t, "Discovery", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "Discovery", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
|
@ -29,9 +29,9 @@ func TestOptions(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPatch(t *testing.T) {
|
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(
|
gomock.InOrder(
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
ID: "yes",
|
ID: "yes",
|
||||||
|
@ -28,7 +28,7 @@ func TestPatch(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
NotifyCompleteUploads: true,
|
NotifyCompleteUploads: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func TestPatch(t *testing.T) {
|
||||||
a.Equal(int64(10), info.Offset)
|
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(
|
gomock.InOrder(
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
ID: "yes",
|
ID: "yes",
|
||||||
|
@ -68,7 +68,7 @@ func TestPatch(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -88,14 +88,14 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
Offset: 20,
|
Offset: 20,
|
||||||
Size: 20,
|
Size: 20,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -114,11 +114,11 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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)
|
store.EXPECT().GetInfo("no").Return(FileInfo{}, os.ErrNotExist)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -133,13 +133,13 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
Offset: 5,
|
Offset: 5,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -154,14 +154,14 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
Offset: 5,
|
Offset: 5,
|
||||||
Size: 10,
|
Size: 10,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -177,9 +177,9 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -195,9 +195,9 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -213,7 +213,7 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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
|
// 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).
|
// 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
|
// The request does not contain the Content-Length header and the handler
|
||||||
|
@ -232,7 +232,7 @@ func TestPatch(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Wrap the string.Reader in a NopCloser to hide its type. else
|
// Wrap the string.Reader in a NopCloser to hide its type. else
|
||||||
|
@ -257,7 +257,7 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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(
|
gomock.InOrder(
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
ID: "yes",
|
ID: "yes",
|
||||||
|
@ -271,8 +271,8 @@ func TestPatch(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
MaxSize: 20,
|
MaxSize: 20,
|
||||||
})
|
})
|
||||||
|
|
||||||
body := strings.NewReader("hellothisismore")
|
body := strings.NewReader("hellothisismore")
|
||||||
|
@ -294,7 +294,7 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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(
|
gomock.InOrder(
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
ID: "yes",
|
ID: "yes",
|
||||||
|
@ -307,8 +307,8 @@ func TestPatch(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
MaxSize: 20,
|
MaxSize: 20,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -326,7 +326,7 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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(
|
gomock.InOrder(
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
ID: "yes",
|
ID: "yes",
|
||||||
|
@ -347,8 +347,8 @@ func TestPatch(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
MaxSize: 20,
|
MaxSize: 20,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -383,7 +383,7 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
locker := NewMockLocker(ctrl)
|
locker := NewMockLocker(ctrl)
|
||||||
|
@ -398,7 +398,7 @@ func TestPatch(t *testing.T) {
|
||||||
locker.EXPECT().UnlockUpload("yes").Return(nil),
|
locker.EXPECT().UnlockUpload("yes").Return(nil),
|
||||||
)
|
)
|
||||||
|
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseLocker(locker)
|
composer.UseLocker(locker)
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ func TestPatch(t *testing.T) {
|
||||||
}).Run(handler, 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(
|
gomock.InOrder(
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
ID: "yes",
|
ID: "yes",
|
||||||
|
@ -430,7 +430,7 @@ func TestPatch(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
NotifyUploadProgress: true,
|
NotifyUploadProgress: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -486,7 +486,7 @@ func TestPatch(t *testing.T) {
|
||||||
a.False(more)
|
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(
|
gomock.InOrder(
|
||||||
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
store.EXPECT().GetInfo("yes").Return(FileInfo{
|
||||||
ID: "yes",
|
ID: "yes",
|
||||||
|
@ -498,7 +498,7 @@ func TestPatch(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
NotifyUploadProgress: true,
|
NotifyUploadProgress: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPost(t *testing.T) {
|
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{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
MetaData: map[string]string{
|
MetaData: map[string]string{
|
||||||
|
@ -23,7 +23,7 @@ func TestPost(t *testing.T) {
|
||||||
}).Return("foo", nil)
|
}).Return("foo", nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "https://buy.art/files/",
|
BasePath: "https://buy.art/files/",
|
||||||
NotifyCreatedUploads: true,
|
NotifyCreatedUploads: true,
|
||||||
})
|
})
|
||||||
|
@ -52,7 +52,7 @@ func TestPost(t *testing.T) {
|
||||||
a.Equal(int64(300), info.Size)
|
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{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 0,
|
Size: 0,
|
||||||
MetaData: map[string]string{},
|
MetaData: map[string]string{},
|
||||||
|
@ -61,7 +61,7 @@ func TestPost(t *testing.T) {
|
||||||
store.EXPECT().FinishUpload("foo").Return(nil)
|
store.EXPECT().FinishUpload("foo").Return(nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "https://buy.art/files/",
|
BasePath: "https://buy.art/files/",
|
||||||
NotifyCompleteUploads: true,
|
NotifyCompleteUploads: true,
|
||||||
})
|
})
|
||||||
|
@ -88,11 +88,11 @@ func TestPost(t *testing.T) {
|
||||||
a.Equal(int64(0), info.Offset)
|
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{
|
handler, _ := NewHandler(Config{
|
||||||
MaxSize: 400,
|
MaxSize: 400,
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -107,9 +107,9 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -123,9 +123,9 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -140,9 +140,9 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -155,9 +155,9 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -171,16 +171,16 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, t)
|
}).Run(handler, t)
|
||||||
})
|
})
|
||||||
|
|
||||||
SubTest(t, "ForwardHeaders", 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) {
|
SubTest(t, "IgnoreXForwarded", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
store.EXPECT().NewUpload(FileInfo{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
MetaData: map[string]string{},
|
MetaData: map[string]string{},
|
||||||
}).Return("foo", nil)
|
}).Return("foo", nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -198,14 +198,14 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
MetaData: map[string]string{},
|
MetaData: map[string]string{},
|
||||||
}).Return("foo", nil)
|
}).Return("foo", nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
RespectForwardedHeaders: true,
|
RespectForwardedHeaders: true,
|
||||||
})
|
})
|
||||||
|
@ -225,14 +225,14 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
MetaData: map[string]string{},
|
MetaData: map[string]string{},
|
||||||
}).Return("foo", nil)
|
}).Return("foo", nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
RespectForwardedHeaders: true,
|
RespectForwardedHeaders: true,
|
||||||
})
|
})
|
||||||
|
@ -253,14 +253,14 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
MetaData: map[string]string{},
|
MetaData: map[string]string{},
|
||||||
}).Return("foo", nil)
|
}).Return("foo", nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
RespectForwardedHeaders: true,
|
RespectForwardedHeaders: true,
|
||||||
})
|
})
|
||||||
|
@ -281,8 +281,8 @@ func TestPost(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
SubTest(t, "WithUpload", 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) {
|
SubTest(t, "Create", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
locker := NewMockLocker(ctrl)
|
locker := NewMockLocker(ctrl)
|
||||||
|
@ -300,7 +300,7 @@ func TestPost(t *testing.T) {
|
||||||
locker.EXPECT().UnlockUpload("foo"),
|
locker.EXPECT().UnlockUpload("foo"),
|
||||||
)
|
)
|
||||||
|
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseLocker(locker)
|
composer.UseLocker(locker)
|
||||||
|
|
||||||
|
@ -326,15 +326,15 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
MetaData: map[string]string{},
|
MetaData: map[string]string{},
|
||||||
}).Return("foo", nil)
|
}).Return("foo", nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -349,15 +349,15 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
store.EXPECT().NewUpload(FileInfo{
|
||||||
Size: 300,
|
Size: 300,
|
||||||
MetaData: map[string]string{},
|
MetaData: map[string]string{},
|
||||||
}).Return("foo", nil)
|
}).Return("foo", nil)
|
||||||
|
|
||||||
handler, _ := NewHandler(Config{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
@ -377,10 +377,10 @@ func TestPost(t *testing.T) {
|
||||||
}).Run(handler, 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{
|
handler, _ := NewHandler(Config{
|
||||||
DataStore: store,
|
StoreComposer: composer,
|
||||||
BasePath: "/files/",
|
BasePath: "/files/",
|
||||||
})
|
})
|
||||||
|
|
||||||
(&httpTest{
|
(&httpTest{
|
||||||
|
|
|
@ -3,10 +3,12 @@ package handler_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/tus/tusd/pkg/handler"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"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) {
|
t.Run(name, func(subT *testing.T) {
|
||||||
//subT.Parallel()
|
//subT.Parallel()
|
||||||
|
|
||||||
|
@ -14,7 +16,14 @@ func SubTest(t *testing.T, name string, runTest func(*testing.T, *MockFullDataSt
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
||||||
store := NewMockFullDataStore(ctrl)
|
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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTerminate(t *testing.T) {
|
func TestTerminate(t *testing.T) {
|
||||||
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseTerminater(store)
|
composer.UseTerminater(store)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func TestTerminate(t *testing.T) {
|
||||||
}).Run(handler, 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)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
locker := NewMockLocker(ctrl)
|
locker := NewMockLocker(ctrl)
|
||||||
|
@ -44,7 +44,7 @@ func TestTerminate(t *testing.T) {
|
||||||
locker.EXPECT().UnlockUpload("foo"),
|
locker.EXPECT().UnlockUpload("foo"),
|
||||||
)
|
)
|
||||||
|
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseTerminater(store)
|
composer.UseTerminater(store)
|
||||||
composer.UseLocker(locker)
|
composer.UseLocker(locker)
|
||||||
|
@ -73,8 +73,8 @@ func TestTerminate(t *testing.T) {
|
||||||
a.Equal(int64(10), info.Size)
|
a.Equal(int64(10), info.Size)
|
||||||
})
|
})
|
||||||
|
|
||||||
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore) {
|
SubTest(t, "NotProvided", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
|
||||||
composer := NewStoreComposer()
|
composer = NewStoreComposer()
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
|
|
||||||
handler, _ := NewUnroutedHandler(Config{
|
handler, _ := NewUnroutedHandler(Config{
|
||||||
|
|
Loading…
Reference in New Issue