aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-01-30 20:59:35 -0800
committerJeff Halter <jeff.d.halter@gmail.com>2022-01-30 20:59:35 -0800
commitd492c46d7e2087114d25f64823de9027592d5fc4 (patch)
treecbe5440d759088fb1599e0582e211fb1c7f35b17 /hotline
parent92a7e455a347e5be7fb69b6846b9f27ca698ae12 (diff)
Start moving file io into mockable interface
Diffstat (limited to 'hotline')
-rw-r--r--hotline/file_store.go16
-rw-r--r--hotline/server.go6
2 files changed, 15 insertions, 7 deletions
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)
+}
diff --git a/hotline/server.go b/hotline/server.go
index 2ee31cf..30121a6 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -413,7 +413,7 @@ func (s *Server) loadAccounts(userDir string) error {
}
for _, file := range matches {
- fh, err := os.Open(file)
+ fh, err := FS.Open(file)
if err != nil {
return err
}
@@ -431,7 +431,7 @@ func (s *Server) loadAccounts(userDir string) error {
}
func (s *Server) loadConfig(path string) error {
- fh, err := os.Open(path)
+ fh, err := FS.Open(path)
if err != nil {
return err
}
@@ -830,7 +830,7 @@ func (s *Server) TransferFile(conn net.Conn) error {
return err
}
- file, err := os.Open(path)
+ file, err := FS.Open(path)
if err != nil {
return err
}