]>
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 | 14 | Symlink(oldname, newname string) error |
003a743e | 15 | Remove(name string) error |
85767504 | 16 | Create(name string) (*os.File, error) |
d492c46d | 17 | // TODO: implement these |
aebc4d36 JH |
18 | // Rename(oldpath string, newpath string) error |
19 | // RemoveAll(path string) error | |
00d1ef67 JH |
20 | } |
21 | ||
22 | type OSFileStore struct{} | |
23 | ||
aebc4d36 | 24 | func (fs *OSFileStore) Mkdir(name string, perm os.FileMode) error { |
00d1ef67 JH |
25 | return os.Mkdir(name, perm) |
26 | } | |
27 | ||
aebc4d36 | 28 | func (fs *OSFileStore) Stat(name string) (os.FileInfo, error) { |
00d1ef67 JH |
29 | return os.Stat(name) |
30 | } | |
31 | ||
aebc4d36 | 32 | func (fs *OSFileStore) Open(name string) (*os.File, error) { |
d492c46d JH |
33 | return os.Open(name) |
34 | } | |
35 | ||
aebc4d36 | 36 | func (fs *OSFileStore) Symlink(oldname, newname string) error { |
decc2fbf JH |
37 | return os.Symlink(oldname, newname) |
38 | } | |
39 | ||
003a743e JH |
40 | func (fs *OSFileStore) Remove(name string) error { |
41 | return os.Remove(name) | |
42 | } | |
43 | ||
85767504 JH |
44 | func (fs *OSFileStore) Create(name string) (*os.File, error) { |
45 | return os.Create(name) | |
46 | } | |
47 | ||
00d1ef67 JH |
48 | type MockFileStore struct { |
49 | mock.Mock | |
50 | } | |
51 | ||
aebc4d36 | 52 | func (mfs *MockFileStore) Mkdir(name string, perm os.FileMode) error { |
00d1ef67 JH |
53 | args := mfs.Called(name, perm) |
54 | return args.Error(0) | |
55 | } | |
56 | ||
aebc4d36 | 57 | func (mfs *MockFileStore) Stat(name string) (os.FileInfo, error) { |
00d1ef67 | 58 | args := mfs.Called(name) |
d492c46d | 59 | if args.Get(0) == nil { |
00d1ef67 JH |
60 | return nil, args.Error(1) |
61 | ||
62 | } | |
63 | return args.Get(0).(os.FileInfo), args.Error(1) | |
64 | } | |
d492c46d | 65 | |
aebc4d36 | 66 | func (mfs *MockFileStore) Open(name string) (*os.File, error) { |
d492c46d JH |
67 | args := mfs.Called(name) |
68 | return args.Get(0).(*os.File), args.Error(1) | |
69 | } | |
decc2fbf | 70 | |
aebc4d36 | 71 | func (mfs *MockFileStore) Symlink(oldname, newname string) error { |
decc2fbf JH |
72 | args := mfs.Called(oldname, newname) |
73 | return args.Error(0) | |
74 | } | |
003a743e JH |
75 | |
76 | func (mfs *MockFileStore) Remove(name string) error { | |
77 | args := mfs.Called(name) | |
78 | return args.Error(0) | |
79 | } | |
85767504 JH |
80 | |
81 | func (mfs *MockFileStore) Create(name string) (*os.File, error) { | |
82 | args := mfs.Called(name) | |
83 | return args.Get(0).(*os.File), args.Error(1) | |
84 | } |