core: Move packages into pkg/ and internal/ folders
This commit is contained in:
parent
6f5b74b875
commit
42bfe35457
|
@ -2,27 +2,6 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Find all packages containing Go source code inside the current directory
|
|
||||||
packages=$(find ./ -maxdepth 2 -name '*.go' -printf '%h\n' | sort | uniq)
|
|
||||||
|
|
||||||
# Some packages only support Go1.10+ and therefore we will only run the
|
|
||||||
# corresponding tests on these versions.
|
|
||||||
goversion=$(go version)
|
|
||||||
if [[ "$goversion" == *"go1.5"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.6"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.7"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.8"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.9"* ]]; then
|
|
||||||
|
|
||||||
echo "Skipping tests requiring GCSStore, which is not supported on $goversion"
|
|
||||||
packages=$(echo "$packages" | sed '/gcsstore/d')
|
|
||||||
|
|
||||||
echo "Skipping tests requiring Prometheus, which is not supported on $goversion"
|
|
||||||
packages=$(echo "$packages" | sed '/prometheuscollector/d')
|
|
||||||
else
|
|
||||||
go get -u github.com/prometheus/client_golang/prometheus
|
|
||||||
fi
|
|
||||||
|
|
||||||
install_etcd_pkgs() {
|
install_etcd_pkgs() {
|
||||||
ETCD_VERSION="3.3.10"
|
ETCD_VERSION="3.3.10"
|
||||||
go get -u go.etcd.io/etcd/clientv3
|
go get -u go.etcd.io/etcd/clientv3
|
||||||
|
@ -32,26 +11,14 @@ install_etcd_pkgs() {
|
||||||
export PATH="$PATH:/tmp/etcd-v$ETCD_VERSION-linux-amd64"
|
export PATH="$PATH:/tmp/etcd-v$ETCD_VERSION-linux-amd64"
|
||||||
}
|
}
|
||||||
|
|
||||||
# The etcd 3.3.x package only supports Go1.11+ and therefore
|
|
||||||
# we will only run the corresponding tests on these versions.
|
|
||||||
if [[ "$goversion" == *"go1.5"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.6"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.7"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.8"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.9"* ]] ||
|
|
||||||
[[ "$goversion" == *"go1.10"* ]]; then
|
|
||||||
echo "Skipping tests requiring etcd3locker, which is not supported on $goversion"
|
|
||||||
packages=$(echo "$packages" | sed '/etcd3locker/d')
|
|
||||||
else
|
|
||||||
# Install the etcd packages which are not vendored.
|
|
||||||
install_etcd_pkgs
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install the AWS SDK which is explicitly not vendored
|
# Install the AWS SDK which is explicitly not vendored
|
||||||
go get -u github.com/aws/aws-sdk-go/service/s3
|
go get -u github.com/aws/aws-sdk-go/service/s3
|
||||||
go get -u github.com/aws/aws-sdk-go/aws/...
|
go get -u github.com/aws/aws-sdk-go/aws/...
|
||||||
|
|
||||||
# Test all packages which are allowed on all Go versions
|
go get -u github.com/prometheus/client_golang/prometheus
|
||||||
go test $packages
|
|
||||||
|
|
||||||
go vet $packages
|
# Install the etcd packages which are not vendored.
|
||||||
|
install_etcd_pkgs
|
||||||
|
|
||||||
|
go test ./pkg/...
|
||||||
|
go vet ./pkg/...
|
||||||
|
|
|
@ -3,23 +3,23 @@ package cli
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/filestore"
|
||||||
"github.com/tus/tusd/filestore"
|
"github.com/tus/tusd/pkg/gcsstore"
|
||||||
"github.com/tus/tusd/gcsstore"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
"github.com/tus/tusd/memorylocker"
|
"github.com/tus/tusd/pkg/memorylocker"
|
||||||
"github.com/tus/tusd/s3store"
|
"github.com/tus/tusd/pkg/s3store"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Composer *tusd.StoreComposer
|
var Composer *handler.StoreComposer
|
||||||
|
|
||||||
func CreateComposer() {
|
func CreateComposer() {
|
||||||
// Attempt to use S3 as a backend if the -s3-bucket option has been supplied.
|
// Attempt to use S3 as a backend if the -s3-bucket option has been supplied.
|
||||||
// If not, we default to storing them locally on disk.
|
// If not, we default to storing them locally on disk.
|
||||||
Composer = tusd.NewStoreComposer()
|
Composer = handler.NewStoreComposer()
|
||||||
if Flags.S3Bucket != "" {
|
if Flags.S3Bucket != "" {
|
||||||
s3Config := aws.NewConfig()
|
s3Config := aws.NewConfig()
|
||||||
|
|
||||||
|
|
|
@ -4,17 +4,17 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
|
||||||
"github.com/tus/tusd/cmd/tusd/cli/hooks"
|
"github.com/tus/tusd/cmd/tusd/cli/hooks"
|
||||||
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
var hookHandler hooks.HookHandler = nil
|
var hookHandler hooks.HookHandler = nil
|
||||||
|
|
||||||
type hookDataStore struct {
|
type hookDataStore struct {
|
||||||
tusd.DataStore
|
handler.DataStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store hookDataStore) NewUpload(info tusd.FileInfo) (id string, err error) {
|
func (store hookDataStore) NewUpload(info handler.FileInfo) (id string, err error) {
|
||||||
if output, err := invokeHookSync(hooks.HookPreCreate, info, true); err != nil {
|
if output, err := invokeHookSync(hooks.HookPreCreate, info, true); err != nil {
|
||||||
if hookErr, ok := err.(hooks.HookError); ok {
|
if hookErr, ok := err.(hooks.HookError); ok {
|
||||||
return "", hooks.NewHookError(
|
return "", hooks.NewHookError(
|
||||||
|
@ -36,7 +36,7 @@ func SetupHookMetrics() {
|
||||||
MetricsHookErrorsTotal.WithLabelValues(string(hooks.HookPreCreate)).Add(0)
|
MetricsHookErrorsTotal.WithLabelValues(string(hooks.HookPreCreate)).Add(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupPreHooks(composer *tusd.StoreComposer) error {
|
func SetupPreHooks(composer *handler.StoreComposer) error {
|
||||||
if Flags.FileHooksDir != "" {
|
if Flags.FileHooksDir != "" {
|
||||||
hookHandler = &hooks.FileHook{
|
hookHandler = &hooks.FileHook{
|
||||||
Directory: Flags.FileHooksDir,
|
Directory: Flags.FileHooksDir,
|
||||||
|
@ -66,7 +66,7 @@ func SetupPreHooks(composer *tusd.StoreComposer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupPostHooks(handler *tusd.Handler) {
|
func SetupPostHooks(handler *handler.Handler) {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -83,14 +83,14 @@ func SetupPostHooks(handler *tusd.Handler) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func invokeHookAsync(typ hooks.HookType, info tusd.FileInfo) {
|
func invokeHookAsync(typ hooks.HookType, info handler.FileInfo) {
|
||||||
go func() {
|
go func() {
|
||||||
// Error handling is taken care by the function.
|
// Error handling is taken care by the function.
|
||||||
_, _ = invokeHookSync(typ, info, false)
|
_, _ = invokeHookSync(typ, info, false)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func invokeHookSync(typ hooks.HookType, info tusd.FileInfo, captureOutput bool) ([]byte, error) {
|
func invokeHookSync(typ hooks.HookType, info handler.FileInfo, captureOutput bool) ([]byte, error) {
|
||||||
switch typ {
|
switch typ {
|
||||||
case hooks.HookPostFinish:
|
case hooks.HookPostFinish:
|
||||||
logEv(stdout, "UploadFinished", "id", info.ID, "size", strconv.FormatInt(info.Size, 10))
|
logEv(stdout, "UploadFinished", "id", info.ID, "size", strconv.FormatInt(info.Size, 10))
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileHook struct {
|
type FileHook struct {
|
||||||
|
@ -18,7 +18,7 @@ func (_ FileHook) Setup() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h FileHook) InvokeHook(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, int, error) {
|
func (h FileHook) InvokeHook(typ HookType, info handler.FileInfo, captureOutput bool) ([]byte, int, error) {
|
||||||
hookPath := h.Directory + string(os.PathSeparator) + string(typ)
|
hookPath := h.Directory + string(os.PathSeparator) + string(typ)
|
||||||
cmd := exec.Command(hookPath)
|
cmd := exec.Command(hookPath)
|
||||||
env := os.Environ()
|
env := os.Environ()
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package hooks
|
package hooks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HookHandler interface {
|
type HookHandler interface {
|
||||||
Setup() error
|
Setup() error
|
||||||
InvokeHook(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, int, error)
|
InvokeHook(typ HookType, info handler.FileInfo, captureOutput bool) ([]byte, int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type HookType string
|
type HookType string
|
||||||
|
@ -20,7 +20,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type hookDataStore struct {
|
type hookDataStore struct {
|
||||||
tusd.DataStore
|
handler.DataStore
|
||||||
}
|
}
|
||||||
|
|
||||||
type HookError struct {
|
type HookError struct {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
|
|
||||||
"github.com/sethgrid/pester"
|
"github.com/sethgrid/pester"
|
||||||
)
|
)
|
||||||
|
@ -23,7 +23,7 @@ func (_ HttpHook) Setup() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HttpHook) InvokeHook(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, int, error) {
|
func (h HttpHook) InvokeHook(typ HookType, info handler.FileInfo, captureOutput bool) ([]byte, int, error) {
|
||||||
jsonInfo, err := json.Marshal(info)
|
jsonInfo, err := json.Marshal(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
|
|
@ -4,15 +4,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"plugin"
|
"plugin"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginHookHandler interface {
|
type PluginHookHandler interface {
|
||||||
PreCreate(info tusd.FileInfo) error
|
PreCreate(info handler.FileInfo) error
|
||||||
PostCreate(info tusd.FileInfo) error
|
PostCreate(info handler.FileInfo) error
|
||||||
PostReceive(info tusd.FileInfo) error
|
PostReceive(info handler.FileInfo) error
|
||||||
PostFinish(info tusd.FileInfo) error
|
PostFinish(info handler.FileInfo) error
|
||||||
PostTerminate(info tusd.FileInfo) error
|
PostTerminate(info handler.FileInfo) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type PluginHook struct {
|
type PluginHook struct {
|
||||||
|
@ -41,7 +41,7 @@ func (h *PluginHook) Setup() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h PluginHook) InvokeHook(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, int, error) {
|
func (h PluginHook) InvokeHook(typ HookType, info handler.FileInfo, captureOutput bool) ([]byte, int, error) {
|
||||||
var err error
|
var err error
|
||||||
switch typ {
|
switch typ {
|
||||||
case HookPostFinish:
|
case HookPostFinish:
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
var stdout = log.New(os.Stdout, "[tusd] ", log.Ldate|log.Ltime)
|
var stdout = log.New(os.Stdout, "[tusd] ", log.Ldate|log.Ltime)
|
||||||
var stderr = log.New(os.Stderr, "[tusd] ", log.Ldate|log.Ltime)
|
var stderr = log.New(os.Stderr, "[tusd] ", log.Ldate|log.Ltime)
|
||||||
|
|
||||||
func logEv(logOutput *log.Logger, eventName string, details ...string) {
|
func logEv(logOutput *log.Logger, eventName string, details ...string) {
|
||||||
tusd.LogEvent(logOutput, eventName, details...)
|
handler.LogEvent(logOutput, eventName, details...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package cli
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
"github.com/tus/tusd/prometheuscollector"
|
"github.com/tus/tusd/pkg/prometheuscollector"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
@ -22,7 +22,7 @@ var MetricsHookErrorsTotal = prometheus.NewCounterVec(
|
||||||
[]string{"hooktype"},
|
[]string{"hooktype"},
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupMetrics(handler *tusd.Handler) {
|
func SetupMetrics(handler *handler.Handler) {
|
||||||
prometheus.MustRegister(MetricsOpenConnections)
|
prometheus.MustRegister(MetricsOpenConnections)
|
||||||
prometheus.MustRegister(MetricsHookErrorsTotal)
|
prometheus.MustRegister(MetricsHookErrorsTotal)
|
||||||
prometheus.MustRegister(prometheuscollector.New(handler.Metrics))
|
prometheus.MustRegister(prometheuscollector.New(handler.Metrics))
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Setups the different components, starts a Listener and give it to
|
// Setups the different components, starts a Listener and give it to
|
||||||
|
@ -19,7 +19,7 @@ func Serve() {
|
||||||
stderr.Fatalf("Unable to setup hooks for handler: %s", err)
|
stderr.Fatalf("Unable to setup hooks for handler: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
handler, err := tusd.NewHandler(tusd.Config{
|
handler, err := handler.NewHandler(handler.Config{
|
||||||
MaxSize: Flags.MaxSize,
|
MaxSize: Flags.MaxSize,
|
||||||
BasePath: Flags.Basepath,
|
BasePath: Flags.Basepath,
|
||||||
RespectForwardedHeaders: Flags.BehindProxy,
|
RespectForwardedHeaders: Flags.BehindProxy,
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
package tusd_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/tus/tusd"
|
|
||||||
"github.com/tus/tusd/filestore"
|
|
||||||
"github.com/tus/tusd/memorylocker"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ExampleNewStoreComposer() {
|
|
||||||
composer := tusd.NewStoreComposer()
|
|
||||||
|
|
||||||
fs := filestore.New("./data")
|
|
||||||
fs.UseIn(composer)
|
|
||||||
|
|
||||||
ml := memorylocker.New()
|
|
||||||
ml.UseIn(composer)
|
|
||||||
|
|
||||||
config := tusd.Config{
|
|
||||||
StoreComposer: composer,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, _ = tusd.NewHandler(config)
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
"go.etcd.io/etcd/clientv3/concurrency"
|
"go.etcd.io/etcd/clientv3/concurrency"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func (lock *etcd3Lock) Acquire() error {
|
||||||
// the lock is most likely already taken
|
// the lock is most likely already taken
|
||||||
if err := lock.Mutex.Lock(ctx); err != nil {
|
if err := lock.Mutex.Lock(ctx); err != nil {
|
||||||
if err == context.DeadlineExceeded {
|
if err == context.DeadlineExceeded {
|
||||||
return tusd.ErrFileLocked
|
return handler.ErrFileLocked
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
//
|
//
|
||||||
// The locker will need to be included in composer that is used by tusd:
|
// The locker will need to be included in composer that is used by tusd:
|
||||||
//
|
//
|
||||||
// composer := tusd.NewStoreComposer()
|
// composer := handler.NewStoreComposer()
|
||||||
// locker.UseIn(composer)
|
// locker.UseIn(composer)
|
||||||
//
|
//
|
||||||
// For a shared etcd3 cluster, you may want to modify the prefix that etcd3locker uses:
|
// For a shared etcd3 cluster, you may want to modify the prefix that etcd3locker uses:
|
||||||
|
@ -47,7 +47,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
etcd3 "go.etcd.io/etcd/clientv3"
|
etcd3 "go.etcd.io/etcd/clientv3"
|
||||||
"go.etcd.io/etcd/clientv3/concurrency"
|
"go.etcd.io/etcd/clientv3/concurrency"
|
||||||
)
|
)
|
||||||
|
@ -89,7 +89,7 @@ func NewWithLockerOptions(client *etcd3.Client, opts LockerOptions) (*Etcd3Locke
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseIn adds this locker to the passed composer.
|
// UseIn adds this locker to the passed composer.
|
||||||
func (locker *Etcd3Locker) UseIn(composer *tusd.StoreComposer) {
|
func (locker *Etcd3Locker) UseIn(composer *handler.StoreComposer) {
|
||||||
composer.UseLocker(locker)
|
composer.UseLocker(locker)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEtcd3Locker(t *testing.T) {
|
func TestEtcd3Locker(t *testing.T) {
|
||||||
|
@ -40,11 +40,11 @@ func TestEtcd3Locker(t *testing.T) {
|
||||||
locker, err := NewWithLockerOptions(client, lockerOptions)
|
locker, err := NewWithLockerOptions(client, lockerOptions)
|
||||||
a.NoError(err)
|
a.NoError(err)
|
||||||
a.NoError(locker.LockUpload("one"))
|
a.NoError(locker.LockUpload("one"))
|
||||||
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
|
a.Equal(handler.ErrFileLocked, locker.LockUpload("one"))
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
// test that we can't take over the upload via a different etcd3 session
|
// test that we can't take over the upload via a different etcd3 session
|
||||||
// while an upload is already taking place; testing etcd3 session KeepAlive
|
// while an upload is already taking place; testing etcd3 session KeepAlive
|
||||||
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
|
a.Equal(handler.ErrFileLocked, locker.LockUpload("one"))
|
||||||
a.NoError(locker.UnlockUpload("one"))
|
a.NoError(locker.UnlockUpload("one"))
|
||||||
a.Equal(ErrLockNotHeld, locker.UnlockUpload("one"))
|
a.Equal(ErrLockNotHeld, locker.UnlockUpload("one"))
|
||||||
|
|
||||||
|
@ -52,8 +52,8 @@ func TestEtcd3Locker(t *testing.T) {
|
||||||
locker2, err := NewWithPrefix(client, testPrefix)
|
locker2, err := NewWithPrefix(client, testPrefix)
|
||||||
a.NoError(err)
|
a.NoError(err)
|
||||||
a.NoError(locker2.LockUpload("one"))
|
a.NoError(locker2.LockUpload("one"))
|
||||||
a.Equal(tusd.ErrFileLocked, locker2.LockUpload("one"))
|
a.Equal(handler.ErrFileLocked, locker2.LockUpload("one"))
|
||||||
a.Equal(tusd.ErrFileLocked, locker2.LockUpload("one"))
|
a.Equal(handler.ErrFileLocked, locker2.LockUpload("one"))
|
||||||
a.NoError(locker2.UnlockUpload("one"))
|
a.NoError(locker2.UnlockUpload("one"))
|
||||||
a.Equal(ErrLockNotHeld, locker2.UnlockUpload("one"))
|
a.Equal(ErrLockNotHeld, locker2.UnlockUpload("one"))
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
// Package filestore provide a storage backend based on the local file system.
|
// Package filestore provide a storage backend based on the local file system.
|
||||||
//
|
//
|
||||||
// FileStore is a storage backend used as a tusd.DataStore in tusd.NewHandler.
|
// FileStore is a storage backend used as a handler.DataStore in handler.NewHandler.
|
||||||
// It stores the uploads in a directory specified in two different files: The
|
// It stores the uploads in a directory specified in two different files: The
|
||||||
// `[id].info` files are used to store the fileinfo in JSON format. The
|
// `[id].info` files are used to store the fileinfo in JSON format. The
|
||||||
// `[id].bin` files contain the raw binary data uploaded.
|
// `[id].bin` files contain the raw binary data uploaded.
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
// which are stored on disk. Each of them stores the PID of the process which
|
// which are stored on disk. Each of them stores the PID of the process which
|
||||||
// acquired the lock. This allows locks to be automatically freed when a process
|
// acquired the lock. This allows locks to be automatically freed when a process
|
||||||
// is unable to release it on its own because the process is not alive anymore.
|
// is unable to release it on its own because the process is not alive anymore.
|
||||||
// For more information, consult the documentation for tusd.LockerDataStore
|
// For more information, consult the documentation for handler.LockerDataStore
|
||||||
// interface, which is implemented by FileStore
|
// interface, which is implemented by FileStore
|
||||||
package filestore
|
package filestore
|
||||||
|
|
||||||
|
@ -23,15 +23,15 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/internal/uid"
|
||||||
"github.com/tus/tusd/uid"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
|
|
||||||
"gopkg.in/Acconut/lockfile.v1"
|
"gopkg.in/Acconut/lockfile.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultFilePerm = os.FileMode(0664)
|
var defaultFilePerm = os.FileMode(0664)
|
||||||
|
|
||||||
// See the tusd.DataStore interface for documentation about the different
|
// See the handler.DataStore interface for documentation about the different
|
||||||
// methods.
|
// methods.
|
||||||
type FileStore struct {
|
type FileStore struct {
|
||||||
// Relative or absolute path to store files in. FileStore does not check
|
// Relative or absolute path to store files in. FileStore does not check
|
||||||
|
@ -49,7 +49,7 @@ func New(path string) FileStore {
|
||||||
|
|
||||||
// UseIn sets this store as the core data store in the passed composer and adds
|
// UseIn sets this store as the core data store in the passed composer and adds
|
||||||
// all possible extension to it.
|
// all possible extension to it.
|
||||||
func (store FileStore) UseIn(composer *tusd.StoreComposer) {
|
func (store FileStore) UseIn(composer *handler.StoreComposer) {
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseGetReader(store)
|
composer.UseGetReader(store)
|
||||||
composer.UseTerminater(store)
|
composer.UseTerminater(store)
|
||||||
|
@ -58,7 +58,7 @@ func (store FileStore) UseIn(composer *tusd.StoreComposer) {
|
||||||
composer.UseLengthDeferrer(store)
|
composer.UseLengthDeferrer(store)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store FileStore) NewUpload(info tusd.FileInfo) (id string, err error) {
|
func (store FileStore) NewUpload(info handler.FileInfo) (id string, err error) {
|
||||||
id = uid.Uid()
|
id = uid.Uid()
|
||||||
info.ID = id
|
info.ID = id
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ func (store FileStore) WriteChunk(id string, offset int64, src io.Reader) (int64
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store FileStore) GetInfo(id string) (tusd.FileInfo, error) {
|
func (store FileStore) GetInfo(id string) (handler.FileInfo, error) {
|
||||||
info := tusd.FileInfo{}
|
info := handler.FileInfo{}
|
||||||
data, err := ioutil.ReadFile(store.infoPath(id))
|
data, err := ioutil.ReadFile(store.infoPath(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
@ -170,7 +170,7 @@ func (store FileStore) LockUpload(id string) error {
|
||||||
|
|
||||||
err = lock.TryLock()
|
err = lock.TryLock()
|
||||||
if err == lockfile.ErrBusy {
|
if err == lockfile.ErrBusy {
|
||||||
return tusd.ErrFileLocked
|
return handler.ErrFileLocked
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -218,7 +218,7 @@ func (store FileStore) infoPath(id string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeInfo updates the entire information. Everything will be overwritten.
|
// writeInfo updates the entire information. Everything will be overwritten.
|
||||||
func (store FileStore) writeInfo(id string, info tusd.FileInfo) error {
|
func (store FileStore) writeInfo(id string, info handler.FileInfo) error {
|
||||||
data, err := json.Marshal(info)
|
data, err := json.Marshal(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
|
@ -9,16 +9,16 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Test interface implementation of Filestore
|
// Test interface implementation of Filestore
|
||||||
var _ tusd.DataStore = FileStore{}
|
var _ handler.DataStore = FileStore{}
|
||||||
var _ tusd.GetReaderDataStore = FileStore{}
|
var _ handler.GetReaderDataStore = FileStore{}
|
||||||
var _ tusd.TerminaterDataStore = FileStore{}
|
var _ handler.TerminaterDataStore = FileStore{}
|
||||||
var _ tusd.LockerDataStore = FileStore{}
|
var _ handler.LockerDataStore = FileStore{}
|
||||||
var _ tusd.ConcaterDataStore = FileStore{}
|
var _ handler.ConcaterDataStore = FileStore{}
|
||||||
var _ tusd.LengthDeferrerDataStore = FileStore{}
|
var _ handler.LengthDeferrerDataStore = FileStore{}
|
||||||
|
|
||||||
func TestFilestore(t *testing.T) {
|
func TestFilestore(t *testing.T) {
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
|
@ -29,7 +29,7 @@ func TestFilestore(t *testing.T) {
|
||||||
store := FileStore{tmp}
|
store := FileStore{tmp}
|
||||||
|
|
||||||
// Create new upload
|
// Create new upload
|
||||||
id, err := store.NewUpload(tusd.FileInfo{
|
id, err := store.NewUpload(handler.FileInfo{
|
||||||
Size: 42,
|
Size: 42,
|
||||||
MetaData: map[string]string{
|
MetaData: map[string]string{
|
||||||
"hello": "world",
|
"hello": "world",
|
||||||
|
@ -43,7 +43,7 @@ func TestFilestore(t *testing.T) {
|
||||||
a.NoError(err)
|
a.NoError(err)
|
||||||
a.EqualValues(42, info.Size)
|
a.EqualValues(42, info.Size)
|
||||||
a.EqualValues(0, info.Offset)
|
a.EqualValues(0, info.Offset)
|
||||||
a.Equal(tusd.MetaData{"hello": "world"}, info.MetaData)
|
a.Equal(handler.MetaData{"hello": "world"}, info.MetaData)
|
||||||
|
|
||||||
// Write data to upload
|
// Write data to upload
|
||||||
bytesWritten, err := store.WriteChunk(id, 0, strings.NewReader("hello world"))
|
bytesWritten, err := store.WriteChunk(id, 0, strings.NewReader("hello world"))
|
||||||
|
@ -78,7 +78,7 @@ func TestMissingPath(t *testing.T) {
|
||||||
|
|
||||||
store := FileStore{"./path-that-does-not-exist"}
|
store := FileStore{"./path-that-does-not-exist"}
|
||||||
|
|
||||||
id, err := store.NewUpload(tusd.FileInfo{})
|
id, err := store.NewUpload(handler.FileInfo{})
|
||||||
a.Error(err)
|
a.Error(err)
|
||||||
a.Equal(err.Error(), "upload directory does not exist: ./path-that-does-not-exist")
|
a.Equal(err.Error(), "upload directory does not exist: ./path-that-does-not-exist")
|
||||||
a.Equal(id, "")
|
a.Equal(id, "")
|
||||||
|
@ -90,11 +90,11 @@ func TestFileLocker(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "tusd-file-locker")
|
dir, err := ioutil.TempDir("", "tusd-file-locker")
|
||||||
a.NoError(err)
|
a.NoError(err)
|
||||||
|
|
||||||
var locker tusd.LockerDataStore
|
var locker handler.LockerDataStore
|
||||||
locker = FileStore{dir}
|
locker = FileStore{dir}
|
||||||
|
|
||||||
a.NoError(locker.LockUpload("one"))
|
a.NoError(locker.LockUpload("one"))
|
||||||
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
|
a.Equal(handler.ErrFileLocked, locker.LockUpload("one"))
|
||||||
a.NoError(locker.UnlockUpload("one"))
|
a.NoError(locker.UnlockUpload("one"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ func TestConcatUploads(t *testing.T) {
|
||||||
store := FileStore{tmp}
|
store := FileStore{tmp}
|
||||||
|
|
||||||
// Create new upload to hold concatenated upload
|
// Create new upload to hold concatenated upload
|
||||||
finId, err := store.NewUpload(tusd.FileInfo{Size: 9})
|
finId, err := store.NewUpload(handler.FileInfo{Size: 9})
|
||||||
a.NoError(err)
|
a.NoError(err)
|
||||||
a.NotEqual("", finId)
|
a.NotEqual("", finId)
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ func TestConcatUploads(t *testing.T) {
|
||||||
"ghi",
|
"ghi",
|
||||||
}
|
}
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
id, err := store.NewUpload(tusd.FileInfo{Size: 3})
|
id, err := store.NewUpload(handler.FileInfo{Size: 3})
|
||||||
a.NoError(err)
|
a.NoError(err)
|
||||||
|
|
||||||
n, err := store.WriteChunk(id, 0, strings.NewReader(contents[i]))
|
n, err := store.WriteChunk(id, 0, strings.NewReader(contents[i]))
|
||||||
|
@ -156,7 +156,7 @@ func TestDeclareLength(t *testing.T) {
|
||||||
|
|
||||||
store := FileStore{tmp}
|
store := FileStore{tmp}
|
||||||
|
|
||||||
originalInfo := tusd.FileInfo{Size: 0, SizeIsDeferred: true}
|
originalInfo := handler.FileInfo{Size: 0, SizeIsDeferred: true}
|
||||||
id, err := store.NewUpload(originalInfo)
|
id, err := store.NewUpload(originalInfo)
|
||||||
a.NoError(err)
|
a.NoError(err)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"gopkg.in/h2non/gock.v1"
|
"gopkg.in/h2non/gock.v1"
|
||||||
|
|
||||||
"cloud.google.com/go/storage"
|
"cloud.google.com/go/storage"
|
||||||
. "github.com/tus/tusd/gcsstore"
|
. "github.com/tus/tusd/pkg/gcsstore"
|
||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,11 +22,11 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"cloud.google.com/go/storage"
|
"cloud.google.com/go/storage"
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/internal/uid"
|
||||||
"github.com/tus/tusd/uid"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
// See the tusd.DataStore interface for documentation about the different
|
// See the handler.DataStore interface for documentation about the different
|
||||||
// methods.
|
// methods.
|
||||||
type GCSStore struct {
|
type GCSStore struct {
|
||||||
// Specifies the GCS bucket that uploads will be stored in
|
// Specifies the GCS bucket that uploads will be stored in
|
||||||
|
@ -51,14 +51,14 @@ func New(bucket string, service GCSAPI) GCSStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store GCSStore) UseIn(composer *tusd.StoreComposer) {
|
func (store GCSStore) UseIn(composer *handler.StoreComposer) {
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseTerminater(store)
|
composer.UseTerminater(store)
|
||||||
composer.UseFinisher(store)
|
composer.UseFinisher(store)
|
||||||
composer.UseGetReader(store)
|
composer.UseGetReader(store)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store GCSStore) NewUpload(info tusd.FileInfo) (id string, err error) {
|
func (store GCSStore) NewUpload(info handler.FileInfo) (id string, err error) {
|
||||||
if info.ID == "" {
|
if info.ID == "" {
|
||||||
info.ID = uid.Uid()
|
info.ID = uid.Uid()
|
||||||
}
|
}
|
||||||
|
@ -115,8 +115,8 @@ func (store GCSStore) WriteChunk(id string, offset int64, src io.Reader) (int64,
|
||||||
|
|
||||||
const CONCURRENT_SIZE_REQUESTS = 32
|
const CONCURRENT_SIZE_REQUESTS = 32
|
||||||
|
|
||||||
func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
|
func (store GCSStore) GetInfo(id string) (handler.FileInfo, error) {
|
||||||
info := tusd.FileInfo{}
|
info := handler.FileInfo{}
|
||||||
i := fmt.Sprintf("%s.info", store.keyWithPrefix(id))
|
i := fmt.Sprintf("%s.info", store.keyWithPrefix(id))
|
||||||
|
|
||||||
params := GCSObjectParams{
|
params := GCSObjectParams{
|
||||||
|
@ -128,7 +128,7 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
|
||||||
r, err := store.Service.ReadObject(ctx, params)
|
r, err := store.Service.ReadObject(ctx, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == storage.ErrObjectNotExist {
|
if err == storage.ErrObjectNotExist {
|
||||||
return info, tusd.ErrNotFound
|
return info, handler.ErrNotFound
|
||||||
}
|
}
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store GCSStore) writeInfo(ctx context.Context, id string, info tusd.FileInfo) error {
|
func (store GCSStore) writeInfo(ctx context.Context, id string, info handler.FileInfo) error {
|
||||||
data, err := json.Marshal(info)
|
data, err := json.Marshal(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
|
@ -1,12 +1,12 @@
|
||||||
// Automatically generated by MockGen. DO NOT EDIT!
|
// Automatically generated by MockGen. DO NOT EDIT!
|
||||||
// Source: github.com/tus/tusd/gcsstore (interfaces: GCSReader,GCSAPI)
|
// Source: github.com/tus/tusd/pkg/gcsstore (interfaces: GCSReader,GCSAPI)
|
||||||
|
|
||||||
package gcsstore_test
|
package gcsstore_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
context "context"
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
gcsstore "github.com/tus/tusd/gcsstore"
|
gcsstore "github.com/tus/tusd/pkg/gcsstore"
|
||||||
io "io"
|
io "io"
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,11 +11,11 @@ import (
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/gcsstore"
|
||||||
"github.com/tus/tusd/gcsstore"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
// go:generate mockgen -destination=./gcsstore_mock_test.go -package=gcsstore_test github.com/tus/tusd/gcsstore GCSReader,GCSAPI
|
// go:generate mockgen -destination=./gcsstore_mock_test.go -package=gcsstore_test github.com/tus/tusd/pkg/gcsstore GCSReader,GCSAPI
|
||||||
|
|
||||||
const mockID = "123456789abcdefghijklmnopqrstuvwxyz"
|
const mockID = "123456789abcdefghijklmnopqrstuvwxyz"
|
||||||
const mockBucket = "bucket"
|
const mockBucket = "bucket"
|
||||||
|
@ -23,7 +23,7 @@ const mockSize = 1337
|
||||||
const mockReaderData = "helloworld"
|
const mockReaderData = "helloworld"
|
||||||
|
|
||||||
var mockTusdInfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"MetaData":{"foo":"bar"}}`, mockID, mockSize)
|
var mockTusdInfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"MetaData":{"foo":"bar"}}`, mockID, mockSize)
|
||||||
var mockTusdInfo = tusd.FileInfo{
|
var mockTusdInfo = handler.FileInfo{
|
||||||
ID: mockID,
|
ID: mockID,
|
||||||
Size: mockSize,
|
Size: mockSize,
|
||||||
MetaData: map[string]string{
|
MetaData: map[string]string{
|
||||||
|
@ -201,7 +201,7 @@ func TestGetInfoNotFound(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
_, err := store.GetInfo(mockID)
|
_, err := store.GetInfo(mockID)
|
||||||
assert.Equal(tusd.ErrNotFound, err)
|
assert.Equal(handler.ErrNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockGetReader struct{}
|
type MockGetReader struct{}
|
||||||
|
@ -368,7 +368,7 @@ func TestFinishUpload(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var mockTusdChunk0InfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"Offset":%d,"MetaData":{"foo":"bar"}}`, mockID, mockSize, mockSize/3)
|
var mockTusdChunk0InfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"Offset":%d,"MetaData":{"foo":"bar"}}`, mockID, mockSize, mockSize/3)
|
||||||
var mockTusdChunk1Info = tusd.FileInfo{
|
var mockTusdChunk1Info = handler.FileInfo{
|
||||||
ID: mockID,
|
ID: mockID,
|
||||||
Size: mockSize,
|
Size: mockSize,
|
||||||
Offset: 455,
|
Offset: 455,
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
// StoreComposer represents a composable data store. It consists of the core
|
// StoreComposer represents a composable data store. It consists of the core
|
||||||
// data store and optional extensions. Please consult the package's overview
|
// data store and optional extensions. Please consult the package's overview
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
#define USE_FUNC(TYPE) \
|
#define USE_FUNC(TYPE) \
|
||||||
func (store *StoreComposer) Use ## TYPE(ext TYPE ## DataStore) { \
|
func (store *StoreComposer) Use ## TYPE(ext TYPE ## DataStore) { \
|
|
@ -0,0 +1,23 @@
|
||||||
|
package handler_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tus/tusd/pkg/filestore"
|
||||||
|
"github.com/tus/tusd/pkg/handler"
|
||||||
|
"github.com/tus/tusd/pkg/memorylocker"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleNewStoreComposer() {
|
||||||
|
composer := handler.NewStoreComposer()
|
||||||
|
|
||||||
|
fs := filestore.New("./data")
|
||||||
|
fs.UseIn(composer)
|
||||||
|
|
||||||
|
ml := memorylocker.New()
|
||||||
|
ml.UseIn(composer)
|
||||||
|
|
||||||
|
config := handler.Config{
|
||||||
|
StoreComposer: composer,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = handler.NewHandler(config)
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConcat(t *testing.T) {
|
func TestConcat(t *testing.T) {
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
|
@ -1,11 +1,11 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCORS(t *testing.T) {
|
func TestCORS(t *testing.T) {
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Package tusd provides ways to accept tus 1.0 calls using HTTP.
|
Package handler provides ways to accept tus 1.0 calls using HTTP.
|
||||||
|
|
||||||
tus is a protocol based on HTTP for resumable file uploads. Resumable means that
|
tus is a protocol based on HTTP for resumable file uploads. Resumable means that
|
||||||
an upload can be interrupted at any moment and can be resumed without
|
an upload can be interrupted at any moment and can be resumed without
|
||||||
|
@ -66,4 +66,4 @@ This handler can then be mounted to a specific path, e.g. /files:
|
||||||
|
|
||||||
http.Handle("/files/", http.StripPrefix("/files/", handler))
|
http.Handle("/files/", http.StripPrefix("/files/", handler))
|
||||||
*/
|
*/
|
||||||
package tusd
|
package handler
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
type closingStringReader struct {
|
type closingStringReader struct {
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
|
@ -1,11 +1,11 @@
|
||||||
// Automatically generated by MockGen. DO NOT EDIT!
|
// Automatically generated by MockGen. DO NOT EDIT!
|
||||||
// Source: utils_test.go
|
// Source: utils_test.go
|
||||||
|
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
tusd "github.com/tus/tusd"
|
handler "github.com/tus/tusd/pkg/handler"
|
||||||
io "io"
|
io "io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ func (_m *MockFullDataStore) EXPECT() *_MockFullDataStoreRecorder {
|
||||||
return _m.recorder
|
return _m.recorder
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_m *MockFullDataStore) NewUpload(info tusd.FileInfo) (string, error) {
|
func (_m *MockFullDataStore) NewUpload(info handler.FileInfo) (string, error) {
|
||||||
ret := _m.ctrl.Call(_m, "NewUpload", info)
|
ret := _m.ctrl.Call(_m, "NewUpload", info)
|
||||||
ret0, _ := ret[0].(string)
|
ret0, _ := ret[0].(string)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
|
@ -52,9 +52,9 @@ func (_mr *_MockFullDataStoreRecorder) WriteChunk(arg0, arg1, arg2 interface{})
|
||||||
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteChunk", arg0, arg1, arg2)
|
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteChunk", arg0, arg1, arg2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_m *MockFullDataStore) GetInfo(id string) (tusd.FileInfo, error) {
|
func (_m *MockFullDataStore) GetInfo(id string) (handler.FileInfo, error) {
|
||||||
ret := _m.ctrl.Call(_m, "GetInfo", id)
|
ret := _m.ctrl.Call(_m, "GetInfo", id)
|
||||||
ret0, _ := ret[0].(tusd.FileInfo)
|
ret0, _ := ret[0].(handler.FileInfo)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHead(t *testing.T) {
|
func TestHead(t *testing.T) {
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,10 +1,10 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOptions(t *testing.T) {
|
func TestOptions(t *testing.T) {
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPatch(t *testing.T) {
|
func TestPatch(t *testing.T) {
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPost(t *testing.T) {
|
func TestPost(t *testing.T) {
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,11 +1,11 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
. "github.com/tus/tusd"
|
. "github.com/tus/tusd/pkg/handler"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package tusd_test
|
package handler_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -10,10 +10,10 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate mockgen -package tusd_test -source utils_test.go -aux_files tusd=datastore.go -destination=handler_mock_test.go
|
//go:generate mockgen -package handler_test -source utils_test.go -aux_files tusd=datastore.go -destination=handler_mock_test.go
|
||||||
|
|
||||||
// FullDataStore is an interface combining most interfaces for data stores.
|
// FullDataStore is an interface combining most interfaces for data stores.
|
||||||
// This is used by mockgen(1) to generate a mocked data store used for testing
|
// This is used by mockgen(1) to generate a mocked data store used for testing
|
||||||
|
@ -22,16 +22,16 @@ import (
|
||||||
// locking in every single test which would result in more verbose code.
|
// locking in every single test which would result in more verbose code.
|
||||||
// Therefore it has been moved into its own type definition, the Locker.
|
// Therefore it has been moved into its own type definition, the Locker.
|
||||||
type FullDataStore interface {
|
type FullDataStore interface {
|
||||||
tusd.DataStore
|
handler.DataStore
|
||||||
tusd.TerminaterDataStore
|
handler.TerminaterDataStore
|
||||||
tusd.ConcaterDataStore
|
handler.ConcaterDataStore
|
||||||
tusd.GetReaderDataStore
|
handler.GetReaderDataStore
|
||||||
tusd.FinisherDataStore
|
handler.FinisherDataStore
|
||||||
tusd.LengthDeferrerDataStore
|
handler.LengthDeferrerDataStore
|
||||||
}
|
}
|
||||||
|
|
||||||
type Locker interface {
|
type Locker interface {
|
||||||
tusd.LockerDataStore
|
handler.LockerDataStore
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpTest struct {
|
type httpTest struct {
|
|
@ -13,7 +13,7 @@ package memorylocker
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MemoryLocker persists locks using memory and therefore allowing a simple and
|
// MemoryLocker persists locks using memory and therefore allowing a simple and
|
||||||
|
@ -27,7 +27,7 @@ type MemoryLocker struct {
|
||||||
// NewMemoryLocker creates a new in-memory locker. The DataStore parameter
|
// NewMemoryLocker creates a new in-memory locker. The DataStore parameter
|
||||||
// is only presented for back-wards compatibility and is ignored. Please
|
// is only presented for back-wards compatibility and is ignored. Please
|
||||||
// use the New() function instead.
|
// use the New() function instead.
|
||||||
func NewMemoryLocker(_ tusd.DataStore) *MemoryLocker {
|
func NewMemoryLocker(_ handler.DataStore) *MemoryLocker {
|
||||||
return New()
|
return New()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ func New() *MemoryLocker {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseIn adds this locker to the passed composer.
|
// UseIn adds this locker to the passed composer.
|
||||||
func (locker *MemoryLocker) UseIn(composer *tusd.StoreComposer) {
|
func (locker *MemoryLocker) UseIn(composer *handler.StoreComposer) {
|
||||||
composer.UseLocker(locker)
|
composer.UseLocker(locker)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func (locker *MemoryLocker) LockUpload(id string) error {
|
||||||
|
|
||||||
// Ensure file is not locked
|
// Ensure file is not locked
|
||||||
if _, ok := locker.locks[id]; ok {
|
if _, ok := locker.locks[id]; ok {
|
||||||
return tusd.ErrFileLocked
|
return handler.ErrFileLocked
|
||||||
}
|
}
|
||||||
|
|
||||||
locker.locks[id] = struct{}{}
|
locker.locks[id] = struct{}{}
|
|
@ -5,17 +5,17 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMemoryLocker(t *testing.T) {
|
func TestMemoryLocker(t *testing.T) {
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
|
|
||||||
var locker tusd.LockerDataStore
|
var locker handler.LockerDataStore
|
||||||
locker = New()
|
locker = New()
|
||||||
|
|
||||||
a.NoError(locker.LockUpload("one"))
|
a.NoError(locker.LockUpload("one"))
|
||||||
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
|
a.Equal(handler.ErrFileLocked, locker.LockUpload("one"))
|
||||||
a.NoError(locker.UnlockUpload("one"))
|
a.NoError(locker.UnlockUpload("one"))
|
||||||
a.NoError(locker.UnlockUpload("one"))
|
a.NoError(locker.UnlockUpload("one"))
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
// Using the provided collector, you can easily expose metrics for tusd in the
|
// Using the provided collector, you can easily expose metrics for tusd in the
|
||||||
// Prometheus exposition format (https://prometheus.io/docs/instrumenting/exposition_formats/):
|
// Prometheus exposition format (https://prometheus.io/docs/instrumenting/exposition_formats/):
|
||||||
//
|
//
|
||||||
// handler, err := tusd.NewHandler(…)
|
// handler, err := handler.NewHandler(…)
|
||||||
// collector := prometheuscollector.New(handler.Metrics)
|
// collector := prometheuscollector.New(handler.Metrics)
|
||||||
// prometheus.MustRegister(collector)
|
// prometheus.MustRegister(collector)
|
||||||
package prometheuscollector
|
package prometheuscollector
|
||||||
|
@ -12,7 +12,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
@ -45,11 +45,11 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
metrics tusd.Metrics
|
metrics handler.Metrics
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new collector which read froms the provided Metrics struct.
|
// New creates a new collector which read froms the provided Metrics struct.
|
||||||
func New(metrics tusd.Metrics) Collector {
|
func New(metrics handler.Metrics) Collector {
|
||||||
return Collector{
|
return Collector{
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
}
|
}
|
|
@ -65,7 +65,7 @@
|
||||||
// consistency (https://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html#ConsistencyModel).
|
// consistency (https://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html#ConsistencyModel).
|
||||||
// Therefore, it is required to build additional measurements in order to
|
// Therefore, it is required to build additional measurements in order to
|
||||||
// prevent concurrent access to the same upload resources which may result in
|
// prevent concurrent access to the same upload resources which may result in
|
||||||
// data corruption. See tusd.LockerDataStore for more information.
|
// data corruption. See handler.LockerDataStore for more information.
|
||||||
package s3store
|
package s3store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -80,8 +80,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/internal/uid"
|
||||||
"github.com/tus/tusd/uid"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
|
@ -92,7 +92,7 @@ import (
|
||||||
// ASCII tables which range from 00 to 7F, inclusive.
|
// ASCII tables which range from 00 to 7F, inclusive.
|
||||||
var nonASCIIRegexp = regexp.MustCompile(`([^\x00-\x7F])`)
|
var nonASCIIRegexp = regexp.MustCompile(`([^\x00-\x7F])`)
|
||||||
|
|
||||||
// See the tusd.DataStore interface for documentation about the different
|
// See the handler.DataStore interface for documentation about the different
|
||||||
// methods.
|
// methods.
|
||||||
type S3Store struct {
|
type S3Store struct {
|
||||||
// Bucket used to store the data in, e.g. "tusdstore.example.com"
|
// Bucket used to store the data in, e.g. "tusdstore.example.com"
|
||||||
|
@ -157,7 +157,7 @@ func New(bucket string, service S3API) S3Store {
|
||||||
|
|
||||||
// UseIn sets this store as the core data store in the passed composer and adds
|
// UseIn sets this store as the core data store in the passed composer and adds
|
||||||
// all possible extension to it.
|
// all possible extension to it.
|
||||||
func (store S3Store) UseIn(composer *tusd.StoreComposer) {
|
func (store S3Store) UseIn(composer *handler.StoreComposer) {
|
||||||
composer.UseCore(store)
|
composer.UseCore(store)
|
||||||
composer.UseTerminater(store)
|
composer.UseTerminater(store)
|
||||||
composer.UseFinisher(store)
|
composer.UseFinisher(store)
|
||||||
|
@ -166,7 +166,7 @@ func (store S3Store) UseIn(composer *tusd.StoreComposer) {
|
||||||
composer.UseLengthDeferrer(store)
|
composer.UseLengthDeferrer(store)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store S3Store) NewUpload(info tusd.FileInfo) (id string, err error) {
|
func (store S3Store) NewUpload(info handler.FileInfo) (id string, err error) {
|
||||||
// an upload larger than MaxObjectSize must throw an error
|
// an upload larger than MaxObjectSize must throw an error
|
||||||
if info.Size > store.MaxObjectSize {
|
if info.Size > store.MaxObjectSize {
|
||||||
return "", fmt.Errorf("s3store: upload size of %v bytes exceeds MaxObjectSize of %v bytes", info.Size, store.MaxObjectSize)
|
return "", fmt.Errorf("s3store: upload size of %v bytes exceeds MaxObjectSize of %v bytes", info.Size, store.MaxObjectSize)
|
||||||
|
@ -210,7 +210,7 @@ func (store S3Store) NewUpload(info tusd.FileInfo) (id string, err error) {
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store S3Store) writeInfo(uploadId string, info tusd.FileInfo) error {
|
func (store S3Store) writeInfo(uploadId string, info handler.FileInfo) error {
|
||||||
infoJson, err := json.Marshal(info)
|
infoJson, err := json.Marshal(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -328,7 +328,7 @@ func (store S3Store) WriteChunk(id string, offset int64, src io.Reader) (int64,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store S3Store) GetInfo(id string) (info tusd.FileInfo, err error) {
|
func (store S3Store) GetInfo(id string) (info handler.FileInfo, err error) {
|
||||||
uploadId, _ := splitIds(id)
|
uploadId, _ := splitIds(id)
|
||||||
|
|
||||||
// Get file info stored in separate object
|
// Get file info stored in separate object
|
||||||
|
@ -338,7 +338,7 @@ func (store S3Store) GetInfo(id string) (info tusd.FileInfo, err error) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if isAwsError(err, "NoSuchKey") {
|
if isAwsError(err, "NoSuchKey") {
|
||||||
return info, tusd.ErrNotFound
|
return info, handler.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return info, err
|
return info, err
|
||||||
|
@ -418,7 +418,7 @@ func (store S3Store) GetReader(id string) (io.Reader, error) {
|
||||||
|
|
||||||
if isAwsError(err, "NoSuchUpload") {
|
if isAwsError(err, "NoSuchUpload") {
|
||||||
// Neither the object nor the multipart upload exists, so we return a 404
|
// Neither the object nor the multipart upload exists, so we return a 404
|
||||||
return nil, tusd.ErrNotFound
|
return nil, handler.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
|
@ -1,5 +1,5 @@
|
||||||
// Automatically generated by MockGen. DO NOT EDIT!
|
// Automatically generated by MockGen. DO NOT EDIT!
|
||||||
// Source: github.com/tus/tusd/s3store (interfaces: S3API)
|
// Source: github.com/tus/tusd/pkg/s3store (interfaces: S3API)
|
||||||
|
|
||||||
package s3store
|
package s3store
|
||||||
|
|
|
@ -13,17 +13,17 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd/pkg/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate mockgen -destination=./s3store_mock_test.go -package=s3store github.com/tus/tusd/s3store S3API
|
//go:generate mockgen -destination=./s3store_mock_test.go -package=s3store github.com/tus/tusd/pkg/s3store S3API
|
||||||
|
|
||||||
// Test interface implementations
|
// Test interface implementations
|
||||||
var _ tusd.DataStore = S3Store{}
|
var _ handler.DataStore = S3Store{}
|
||||||
var _ tusd.GetReaderDataStore = S3Store{}
|
var _ handler.GetReaderDataStore = S3Store{}
|
||||||
var _ tusd.TerminaterDataStore = S3Store{}
|
var _ handler.TerminaterDataStore = S3Store{}
|
||||||
var _ tusd.FinisherDataStore = S3Store{}
|
var _ handler.FinisherDataStore = S3Store{}
|
||||||
var _ tusd.ConcaterDataStore = S3Store{}
|
var _ handler.ConcaterDataStore = S3Store{}
|
||||||
|
|
||||||
func TestNewUpload(t *testing.T) {
|
func TestNewUpload(t *testing.T) {
|
||||||
mockCtrl := gomock.NewController(t)
|
mockCtrl := gomock.NewController(t)
|
||||||
|
@ -58,7 +58,7 @@ func TestNewUpload(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
info := tusd.FileInfo{
|
info := handler.FileInfo{
|
||||||
ID: "uploadId",
|
ID: "uploadId",
|
||||||
Size: 500,
|
Size: 500,
|
||||||
MetaData: map[string]string{
|
MetaData: map[string]string{
|
||||||
|
@ -106,7 +106,7 @@ func TestNewUploadWithObjectPrefix(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
info := tusd.FileInfo{
|
info := handler.FileInfo{
|
||||||
ID: "uploadId",
|
ID: "uploadId",
|
||||||
Size: 500,
|
Size: 500,
|
||||||
MetaData: map[string]string{
|
MetaData: map[string]string{
|
||||||
|
@ -131,7 +131,7 @@ func TestNewUploadLargerMaxObjectSize(t *testing.T) {
|
||||||
assert.Equal("bucket", store.Bucket)
|
assert.Equal("bucket", store.Bucket)
|
||||||
assert.Equal(s3obj, store.Service)
|
assert.Equal(s3obj, store.Service)
|
||||||
|
|
||||||
info := tusd.FileInfo{
|
info := handler.FileInfo{
|
||||||
ID: "uploadId",
|
ID: "uploadId",
|
||||||
Size: store.MaxObjectSize + 1,
|
Size: store.MaxObjectSize + 1,
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ func TestGetInfoNotFound(t *testing.T) {
|
||||||
}).Return(nil, awserr.New("NoSuchKey", "The specified key does not exist.", nil))
|
}).Return(nil, awserr.New("NoSuchKey", "The specified key does not exist.", nil))
|
||||||
|
|
||||||
_, err := store.GetInfo("uploadId+multipartId")
|
_, err := store.GetInfo("uploadId+multipartId")
|
||||||
assert.Equal(tusd.ErrNotFound, err)
|
assert.Equal(handler.ErrNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInfo(t *testing.T) {
|
func TestGetInfo(t *testing.T) {
|
||||||
|
@ -243,8 +243,8 @@ func TestGetInfoWithIncompletePart(t *testing.T) {
|
||||||
Bucket: aws.String("bucket"),
|
Bucket: aws.String("bucket"),
|
||||||
Key: aws.String("uploadId.part"),
|
Key: aws.String("uploadId.part"),
|
||||||
}).Return(&s3.GetObjectOutput{
|
}).Return(&s3.GetObjectOutput{
|
||||||
ContentLength: aws.Int64(10),
|
ContentLength: aws.Int64(10),
|
||||||
Body: ioutil.NopCloser(bytes.NewReader([]byte("0123456789"))),
|
Body: ioutil.NopCloser(bytes.NewReader([]byte("0123456789"))),
|
||||||
}, nil),
|
}, nil),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ func TestGetReaderNotFound(t *testing.T) {
|
||||||
|
|
||||||
content, err := store.GetReader("uploadId+multipartId")
|
content, err := store.GetReader("uploadId+multipartId")
|
||||||
assert.Nil(content)
|
assert.Nil(content)
|
||||||
assert.Equal(tusd.ErrNotFound, err)
|
assert.Equal(handler.ErrNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetReaderNotFinished(t *testing.T) {
|
func TestGetReaderNotFinished(t *testing.T) {
|
||||||
|
@ -730,8 +730,8 @@ func TestWriteChunkPrependsIncompletePart(t *testing.T) {
|
||||||
Bucket: aws.String("bucket"),
|
Bucket: aws.String("bucket"),
|
||||||
Key: aws.String("uploadId.part"),
|
Key: aws.String("uploadId.part"),
|
||||||
}).Return(&s3.GetObjectOutput{
|
}).Return(&s3.GetObjectOutput{
|
||||||
ContentLength: aws.Int64(3),
|
ContentLength: aws.Int64(3),
|
||||||
Body: ioutil.NopCloser(bytes.NewReader([]byte("123"))),
|
Body: ioutil.NopCloser(bytes.NewReader([]byte("123"))),
|
||||||
}, nil),
|
}, nil),
|
||||||
s3obj.EXPECT().ListParts(&s3.ListPartsInput{
|
s3obj.EXPECT().ListParts(&s3.ListPartsInput{
|
||||||
Bucket: aws.String("bucket"),
|
Bucket: aws.String("bucket"),
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"folders": [
|
|
||||||
{
|
|
||||||
"path": "."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"settings": {}
|
|
||||||
}
|
|
Loading…
Reference in New Issue