generated from parrogo/gomod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.go
121 lines (104 loc) · 2.73 KB
/
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package templatedir
import (
"io/fs"
"github.com/parro-it/vs/writefs"
"github.com/stretchr/testify/mock"
)
// FS mocks
type FS struct {
mock.Mock
}
// DoSomething is a method on MyMockedObject that implements some interface
// and just records the activity, and returns what the Mock object tells it to.
//
// In the real object, this method would do something useful, but since this
// is a mocked object - we're just going to stub it out.
//
// NOTE: This method is not being tested here, code that uses this object is.
func (fsys *FS) DoSomething(number int) (bool, error) {
args := fsys.Called(number)
return args.Bool(0), args.Error(1)
}
var (
_ fs.StatFS = &FS{}
_ fs.ReadFileFS = &FS{}
_ fs.SubFS = &FS{}
_ fs.ReadDirFS = &FS{}
_ fs.GlobFS = &FS{}
_ writefs.WriteFS = &FS{}
_ writefs.RemoveFS = &FS{}
_ writefs.MkDirFS = &FS{}
)
// MkDir implements writefs.MkDirFS
func (fsys *FS) MkDir(name string, perm fs.FileMode) error {
args := fsys.Called(name, perm)
return args.Error(0)
}
// Remove implements writefs.RemoveFS
func (fsys *FS) Remove(name string) error {
args := fsys.Called(name)
return args.Error(0)
}
// OpenFile implements writefs.WriteFS
func (fsys *FS) OpenFile(name string, flag int, perm fs.FileMode) (writefs.FileWriter, error) {
args := fsys.Called(name, flag, perm)
res := args.Get(0)
if res == nil {
return nil, args.Error(1)
}
return res.(writefs.FileWriter), args.Error(1)
}
// Stat implements fs.StatFS
func (fsys *FS) Stat(name string) (fs.FileInfo, error) {
args := fsys.Called(name)
res := args.Get(0)
if res == nil {
return nil, args.Error(1)
}
return res.(fs.FileInfo), args.Error(1)
}
// ReadFile implements fs.ReadFileFS
func (fsys *FS) ReadFile(name string) ([]byte, error) {
args := fsys.Called(name)
res := args.Get(0)
if res == nil {
return nil, args.Error(1)
}
return res.([]byte), args.Error(1)
}
// Sub implements fs.SubFS
func (fsys *FS) Sub(dir string) (fs.FS, error) {
args := fsys.Called(dir)
res := args.Get(0)
if res == nil {
return nil, args.Error(1)
}
return res.(fs.FS), args.Error(1)
}
// Open implements fs.FS
func (fsys *FS) Open(name string) (fs.File, error) {
args := fsys.Called(name)
res := args.Get(0)
if res == nil {
return nil, args.Error(1)
}
return res.(fs.File), args.Error(1)
}
// ReadDir implements fs.ReadDirFS
func (fsys *FS) ReadDir(name string) ([]fs.DirEntry, error) {
args := fsys.Called(name)
res := args.Get(0)
if res == nil {
return nil, args.Error(1)
}
return res.([]fs.DirEntry), args.Error(1)
}
// Glob implements fs.GlobFS
func (fsys *FS) Glob(pattern string) ([]string, error) {
args := fsys.Called(pattern)
res := args.Get(0)
if res == nil {
return nil, args.Error(1)
}
return res.([]string), args.Error(1)
}