2019-09-10 14:19:49 +00:00
|
|
|
package filelocker
|
|
|
|
|
|
|
|
import (
|
2022-03-19 22:21:17 +00:00
|
|
|
"context"
|
2019-09-10 14:19:49 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-03-08 12:03:18 +00:00
|
|
|
"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)
|
|
|
|
|
2022-03-19 22:21:17 +00:00
|
|
|
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)
|
2022-03-19 22:21:17 +00:00
|
|
|
a.Equal(handler.ErrFileLocked, lock2.Lock(context.TODO(), nil))
|
2019-09-10 14:19:49 +00:00
|
|
|
|
|
|
|
a.NoError(lock1.Unlock())
|
|
|
|
}
|