]>
Commit | Line | Data |
---|---|---|
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 | |
12 | Stat(name string) (os.FileInfo, error) | |
13 | Open(name string) (*os.File, error) | |
14 | Symlink(oldname, newname string) error | |
15 | ||
16 | // TODO: implement these | |
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 | ||
31 | func (fs OSFileStore) Open(name string) (*os.File, error) { | |
32 | return os.Open(name) | |
33 | } | |
34 | ||
35 | func (fs OSFileStore) Symlink(oldname, newname string) error { | |
36 | return os.Symlink(oldname, newname) | |
37 | } | |
38 | ||
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) | |
50 | if args.Get(0) == nil { | |
51 | return nil, args.Error(1) | |
52 | ||
53 | } | |
54 | return args.Get(0).(os.FileInfo), args.Error(1) | |
55 | } | |
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 | } | |
61 | ||
62 | func (mfs MockFileStore) Symlink(oldname, newname string) error { | |
63 | args := mfs.Called(oldname, newname) | |
64 | return args.Error(0) | |
65 | } |