]>
Commit | Line | Data |
---|---|---|
00d1ef67 JH |
1 | package hotline |
2 | ||
3 | import ( | |
4 | "github.com/stretchr/testify/mock" | |
5 | "os" | |
6 | ) | |
7 | ||
8 | var FS FileStore | |
9 | ||
10 | type FileStore interface { | |
11 | Mkdir(name string, perm os.FileMode) error | |
00d1ef67 | 12 | Stat(name string) (os.FileInfo, error) |
d492c46d | 13 | Open(name string) (*os.File, error) |
decc2fbf JH |
14 | Symlink(oldname, newname string) error |
15 | ||
d492c46d | 16 | // TODO: implement these |
00d1ef67 JH |
17 | //Rename(oldpath string, newpath string) error |
18 | //RemoveAll(path string) error | |
19 | } | |
20 | ||
21 | type OSFileStore struct{} | |
22 | ||
23 | func (fs OSFileStore) Mkdir(name string, perm os.FileMode) error { | |
24 | return os.Mkdir(name, perm) | |
25 | } | |
26 | ||
27 | func (fs OSFileStore) Stat(name string) (os.FileInfo, error) { | |
28 | return os.Stat(name) | |
29 | } | |
30 | ||
d492c46d JH |
31 | func (fs OSFileStore) Open(name string) (*os.File, error) { |
32 | return os.Open(name) | |
33 | } | |
34 | ||
decc2fbf JH |
35 | func (fs OSFileStore) Symlink(oldname, newname string) error { |
36 | return os.Symlink(oldname, newname) | |
37 | } | |
38 | ||
00d1ef67 JH |
39 | type MockFileStore struct { |
40 | mock.Mock | |
41 | } | |
42 | ||
43 | func (mfs MockFileStore) Mkdir(name string, perm os.FileMode) error { | |
44 | args := mfs.Called(name, perm) | |
45 | return args.Error(0) | |
46 | } | |
47 | ||
48 | func (mfs MockFileStore) Stat(name string) (os.FileInfo, error) { | |
49 | args := mfs.Called(name) | |
d492c46d | 50 | if args.Get(0) == nil { |
00d1ef67 JH |
51 | return nil, args.Error(1) |
52 | ||
53 | } | |
54 | return args.Get(0).(os.FileInfo), args.Error(1) | |
55 | } | |
d492c46d JH |
56 | |
57 | func (mfs MockFileStore) Open(name string) (*os.File, error) { | |
58 | args := mfs.Called(name) | |
59 | return args.Get(0).(*os.File), args.Error(1) | |
60 | } | |
decc2fbf JH |
61 | |
62 | func (mfs MockFileStore) Symlink(oldname, newname string) error { | |
63 | args := mfs.Called(oldname, newname) | |
64 | return args.Error(0) | |
65 | } |