tusd/pkg/filelocker/filelocker_test.go

34 lines
648 B
Go
Raw Permalink Normal View History

2019-09-10 14:19:49 +00:00
package filelocker
import (
"context"
2019-09-10 14:19:49 +00:00
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tus/tusd/v2/pkg/handler"
2019-09-10 14:19:49 +00:00
)
var _ handler.Locker = &FileLocker{}
func TestFileLocker(t *testing.T) {
a := assert.New(t)
dir, err := ioutil.TempDir("", "tusd-file-locker")
a.NoError(err)
locker := FileLocker{dir}
lock1, err := locker.NewLock("one")
a.NoError(err)
a.NoError(lock1.Lock(context.TODO(), nil))
a.Equal(handler.ErrFileLocked, lock1.Lock(context.TODO(), nil))
2019-09-10 14:19:49 +00:00
lock2, err := locker.NewLock("one")
a.NoError(err)
a.Equal(handler.ErrFileLocked, lock2.Lock(context.TODO(), nil))
2019-09-10 14:19:49 +00:00
a.NoError(lock1.Unlock())
}