X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/003a743e6767b3041c3a8321566c3586d73b399a..4fad3266d27d3d193c6e25298c6085dbf8a6b610:/hotline/file_store.go diff --git a/hotline/file_store.go b/hotline/file_store.go index e9d083f..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 @@ -40,6 +41,14 @@ 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 } @@ -72,3 +81,13 @@ 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) +}