test: Add context to mockfs.NewFs #3257 #4685

This commit is contained in:
Nick Craig-Wood 2020-11-05 16:00:08 +00:00
parent d846210978
commit d69b96a94c
7 changed files with 12 additions and 12 deletions

View File

@ -23,9 +23,9 @@ func mockNewFs(t *testing.T) (func(), func(ctx context.Context, path string) (fs
called++
switch path {
case "mock:/":
return mockfs.NewFs("mock", "/"), nil
return mockfs.NewFs(ctx, "mock", "/"), nil
case "mock:/file.txt", "mock:file.txt":
return mockfs.NewFs("mock", "/"), fs.ErrorIsFile
return mockfs.NewFs(ctx, "mock", "/"), fs.ErrorIsFile
case "mock:/error":
return nil, errSentinel
}
@ -124,7 +124,7 @@ func TestPut(t *testing.T) {
cleanup, create := mockNewFs(t)
defer cleanup()
f := mockfs.NewFs("mock", "/alien")
f := mockfs.NewFs(context.Background(), "mock", "/alien")
assert.Equal(t, 0, c.Entries())
@ -155,7 +155,7 @@ func TestPin(t *testing.T) {
defer cleanup()
// Test pinning and unpinning non existent
f := mockfs.NewFs("mock", "/alien")
f := mockfs.NewFs(context.Background(), "mock", "/alien")
Pin(f)
Unpin(f)

View File

@ -14,7 +14,7 @@ import (
func TestFingerprint(t *testing.T) {
ctx := context.Background()
f := mockfs.NewFs("test", "root")
f := mockfs.NewFs(ctx, "test", "root")
f.SetHashes(hash.NewHashSet(hash.MD5))
for i, test := range []struct {

View File

@ -17,9 +17,9 @@ import (
)
func TestDoMultiThreadCopy(t *testing.T) {
f := mockfs.NewFs("potato", "")
f := mockfs.NewFs(context.Background(), "potato", "")
src := mockobject.New("file.txt").WithContent([]byte(random.String(100)), mockobject.SeekModeNone)
srcFs := mockfs.NewFs("sausage", "")
srcFs := mockfs.NewFs(context.Background(), "sausage", "")
src.SetFs(srcFs)
oldStreams := fs.Config.MultiThreadStreams

View File

@ -11,7 +11,7 @@ import (
)
func mockNewFs(t *testing.T) func() {
f := mockfs.NewFs("mock", "mock")
f := mockfs.NewFs(context.Background(), "mock", "mock")
cache.Put("/", f)
return func() {
cache.Clear()

View File

@ -709,7 +709,7 @@ func TestListR(t *testing.T) {
mockobject.Object("dir/b"),
mockobject.Object("dir/c"),
}
f := mockfs.NewFs("mock", "/")
f := mockfs.NewFs(context.Background(), "mock", "/")
var got []string
clearCallback := func() {
got = nil

View File

@ -25,12 +25,12 @@ type Fs struct {
var ErrNotImplemented = errors.New("not implemented")
// NewFs returns a new mock Fs
func NewFs(name, root string) *Fs {
func NewFs(ctx context.Context, name, root string) *Fs {
f := &Fs{
name: name,
root: root,
}
f.features = (&fs.Features{}).Fill(f)
f.features = (&fs.Features{}).Fill(ctx, f)
return f
}

View File

@ -137,7 +137,7 @@ func TestFileOpenReadUnknownSize(t *testing.T) {
assert.Equal(t, int64(-1), o.Size())
// add it to a mock fs
f := mockfs.NewFs("test", "root")
f := mockfs.NewFs(context.Background(), "test", "root")
f.AddObject(o)
testObj, err := f.NewObject(ctx, remote)
require.NoError(t, err)