X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/aebc4d3647b9823ae8cbb57b21b1af83bfd011fb..5d7865ce3db756ab378728e478cb846d302a7c17:/hotline/file_store.go?ds=sidebyside diff --git a/hotline/file_store.go b/hotline/file_store.go index f528c36..2ba9d7a 100644 --- a/hotline/file_store.go +++ b/hotline/file_store.go @@ -2,17 +2,18 @@ package hotline import ( "github.com/stretchr/testify/mock" + "io/fs" "os" ) -var FS FileStore - type FileStore interface { Mkdir(name string, perm os.FileMode) error Stat(name string) (os.FileInfo, error) Open(name string) (*os.File, error) Symlink(oldname, newname string) error - + Remove(name string) error + Create(name string) (*os.File, error) + WriteFile(name string, data []byte, perm fs.FileMode) error // TODO: implement these // Rename(oldpath string, newpath string) error // RemoveAll(path string) error @@ -36,6 +37,18 @@ func (fs *OSFileStore) Symlink(oldname, newname string) error { return os.Symlink(oldname, newname) } +func (fs *OSFileStore) Remove(name string) error { + return os.Remove(name) +} + +func (fs *OSFileStore) Create(name string) (*os.File, error) { + return os.Create(name) +} + +func (fs *OSFileStore) WriteFile(name string, data []byte, perm fs.FileMode) error { + return os.WriteFile(name, data, perm) +} + type MockFileStore struct { mock.Mock } @@ -63,3 +76,18 @@ func (mfs *MockFileStore) Symlink(oldname, newname string) error { args := mfs.Called(oldname, newname) return args.Error(0) } + +func (mfs *MockFileStore) Remove(name string) error { + args := mfs.Called(name) + return args.Error(0) +} + +func (mfs *MockFileStore) Create(name string) (*os.File, error) { + args := mfs.Called(name) + return args.Get(0).(*os.File), args.Error(1) +} + +func (mfs *MockFileStore) WriteFile(name string, data []byte, perm fs.FileMode) error { + args := mfs.Called(name, data, perm) + return args.Error(0) +}