-
Notifications
You must be signed in to change notification settings - Fork 14
/
mock_fs.go
71 lines (55 loc) · 1.45 KB
/
mock_fs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package storage
import (
"context"
"io"
"github.com/stretchr/testify/mock"
)
// NewMockFS creates an FS where each method can be mocked.
// To be used in tests.
func NewMockFS() *MockFS {
return &MockFS{}
}
type MockFS struct {
mock.Mock
}
func (m *MockFS) Walk(ctx context.Context, path string, fn WalkFn) error {
args := m.Called(ctx, path, fn)
return args.Error(0)
}
func (m *MockFS) Open(ctx context.Context, path string, options *ReaderOptions) (*File, error) {
args := m.Called(ctx, path, options)
file := args.Get(0)
err := args.Error(1)
if file == nil {
return nil, err
}
return file.(*File), err
}
func (m *MockFS) Attributes(ctx context.Context, path string, options *ReaderOptions) (*Attributes, error) {
args := m.Called(ctx, path, options)
attrs := args.Get(0)
err := args.Error(1)
if attrs == nil {
return nil, err
}
return attrs.(*Attributes), err
}
func (m *MockFS) Create(ctx context.Context, path string, options *WriterOptions) (io.WriteCloser, error) {
args := m.Called(ctx, path, options)
w := args.Get(0)
err := args.Error(1)
if w == nil {
return nil, err
}
return w.(io.WriteCloser), err
}
func (m *MockFS) Delete(ctx context.Context, path string) error {
args := m.Called(ctx, path)
return args.Error(0)
}
func (m *MockFS) URL(ctx context.Context, path string, options *SignedURLOptions) (string, error) {
args := m.Called(ctx, path, options)
url := args.String(0)
err := args.Error(1)
return url, err
}