aboutsummaryrefslogtreecommitdiff
path: root/hotline/file_store.go
blob: c1c392905c3704791014653d9937f993114af541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
	Open(name string) (*os.File, error)
	Symlink(oldname, newname string) error

	// TODO: implement these
	//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)
}

func (fs OSFileStore) Open(name string) (*os.File, error) {
	return os.Open(name)
}

func (fs OSFileStore) Symlink(oldname, newname string) error {
	return os.Symlink(oldname, newname)
}

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)
}

func (mfs MockFileStore) Open(name string) (*os.File, error) {
	args := mfs.Called(name)
	return args.Get(0).(*os.File), args.Error(1)
}

func (mfs MockFileStore) Symlink(oldname, newname string) error {
	args := mfs.Called(oldname, newname)
	return args.Error(0)
}