-
Notifications
You must be signed in to change notification settings - Fork 14
/
mock_fs_test.go
91 lines (76 loc) · 2.05 KB
/
mock_fs_test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package storage_test
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/Shopify/go-storage"
)
func Test_mockFS_Attributes(t *testing.T) {
ctx := context.Background()
fs := storage.NewMockFS()
path := "foo"
options := &storage.ReaderOptions{}
attrs := &storage.Attributes{}
fs.On("Attributes", ctx, path, options).Return(attrs, nil)
attrs2, err := fs.Attributes(ctx, path, options)
assert.NoError(t, err)
assert.Equal(t, attrs, attrs2)
fs.AssertExpectations(t)
}
func Test_mockFS_Create(t *testing.T) {
ctx := context.Background()
fs := storage.NewMockFS()
path := "foo"
options := &storage.WriterOptions{}
w := &os.File{}
fs.On("Create", ctx, path, options).Return(w, nil)
w2, err := fs.Create(ctx, path, options)
assert.NoError(t, err)
assert.Equal(t, w, w2)
fs.AssertExpectations(t)
}
func Test_mockFS_Delete(t *testing.T) {
ctx := context.Background()
fs := storage.NewMockFS()
path := "foo"
fs.On("Delete", ctx, path).Return(nil)
err := fs.Delete(ctx, path)
assert.NoError(t, err)
fs.AssertExpectations(t)
}
func Test_mockFS_Open(t *testing.T) {
ctx := context.Background()
fs := storage.NewMockFS()
path := "foo"
options := &storage.ReaderOptions{}
file := &storage.File{}
fs.On("Open", ctx, path, options).Return(file, nil)
file2, err := fs.Open(ctx, path, options)
assert.NoError(t, err)
assert.Equal(t, file, file2)
fs.AssertExpectations(t)
}
func Test_mockFS_URL(t *testing.T) {
ctx := context.Background()
fs := storage.NewMockFS()
path := "foo"
options := &storage.SignedURLOptions{}
url := "url"
fs.On("URL", ctx, path, options).Return(url, nil)
url2, err := fs.URL(ctx, path, options)
assert.NoError(t, err)
assert.Equal(t, url, url2)
fs.AssertExpectations(t)
}
func Test_mockFS_Walk(t *testing.T) {
ctx := context.Background()
fs := storage.NewMockFS()
path := "foo"
fn := func(_ string) error { return nil }
fs.On("Walk", ctx, path, mock.Anything).Return(nil)
err := fs.Walk(ctx, path, fn)
assert.NoError(t, err)
fs.AssertExpectations(t)
}