From d492c46d7e2087114d25f64823de9027592d5fc4 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sun, 30 Jan 2022 20:59:35 -0800 Subject: Start moving file io into mockable interface --- hotline/file_store.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'hotline/file_store.go') diff --git a/hotline/file_store.go b/hotline/file_store.go index 81c1f05..b56d9a1 100644 --- a/hotline/file_store.go +++ b/hotline/file_store.go @@ -9,10 +9,9 @@ var FS FileStore type FileStore interface { Mkdir(name string, perm os.FileMode) error - Stat(name string) (os.FileInfo, error) - // TODO: implement - + Open(name string) (*os.File, error) + // TODO: implement these //Rename(oldpath string, newpath string) error //RemoveAll(path string) error } @@ -27,6 +26,10 @@ func (fs OSFileStore) Stat(name string) (os.FileInfo, error) { return os.Stat(name) } +func (fs OSFileStore) Open(name string) (*os.File, error) { + return os.Open(name) +} + type MockFileStore struct { mock.Mock } @@ -38,9 +41,14 @@ func (mfs MockFileStore) Mkdir(name string, perm os.FileMode) error { func (mfs MockFileStore) Stat(name string) (os.FileInfo, error) { args := mfs.Called(name) - if args.Get(0) == nil { + if args.Get(0) == nil { return nil, args.Error(1) } return args.Get(0).(os.FileInfo), args.Error(1) } + +func (mfs MockFileStore) Open(name string) (*os.File, error) { + args := mfs.Called(name) + return args.Get(0).(*os.File), args.Error(1) +} -- cgit