From 00d1ef67636df59460bd4e060f6da4b0c9bcb24c Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sun, 15 Aug 2021 10:39:43 -0700 Subject: Tests and minor fixes --- hotline/file_store.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 hotline/file_store.go (limited to 'hotline/file_store.go') diff --git a/hotline/file_store.go b/hotline/file_store.go new file mode 100644 index 0000000..81c1f05 --- /dev/null +++ b/hotline/file_store.go @@ -0,0 +1,46 @@ +package hotline + +import ( + "github.com/stretchr/testify/mock" + "os" +) + +var FS FileStore + +type FileStore interface { + Mkdir(name string, perm os.FileMode) error + + Stat(name string) (os.FileInfo, error) + // TODO: implement + + //Rename(oldpath string, newpath string) error + //RemoveAll(path string) error +} + +type OSFileStore struct{} + +func (fs OSFileStore) Mkdir(name string, perm os.FileMode) error { + return os.Mkdir(name, perm) +} + +func (fs OSFileStore) Stat(name string) (os.FileInfo, error) { + return os.Stat(name) +} + +type MockFileStore struct { + mock.Mock +} + +func (mfs MockFileStore) Mkdir(name string, perm os.FileMode) error { + args := mfs.Called(name, perm) + return args.Error(0) +} + +func (mfs MockFileStore) Stat(name string) (os.FileInfo, error) { + args := mfs.Called(name) + if args.Get(0) == nil { + return nil, args.Error(1) + + } + return args.Get(0).(os.FileInfo), args.Error(1) +} -- cgit