aboutsummaryrefslogtreecommitdiff
path: root/hotline/mocks_test.go
blob: bd17b3be467dfa56b7fe141a2d8e7db90dfbbae8 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package hotline

// In-package copies of the mocks these tests need. They cannot use hotline/hltest — importing it
// from an in-package test would create an import cycle through hotline — so the mocks used by
// in-package tests live here. Cross-package consumers use hotline/hltest instead; keep the two in
// sync (the conformance assertions in both files catch signature drift).

import (
	"io"
	"io/fs"
	"path/filepath"
	"time"

	"github.com/stretchr/testify/mock"
)

type MockFileStore struct {
	mock.Mock
}

var _ FileStore = (*MockFileStore)(nil)

func (mfs *MockFileStore) Mkdir(name string, perm fs.FileMode) error {
	args := mfs.Called(name, perm)
	return args.Error(0)
}

func (mfs *MockFileStore) Stat(name string) (fs.FileInfo, error) {
	args := mfs.Called(name)
	if args.Get(0) == nil {
		return nil, args.Error(1)
	}
	return args.Get(0).(fs.FileInfo), args.Error(1)
}

func (mfs *MockFileStore) Open(name string) (io.ReadCloser, error) {
	args := mfs.Called(name)
	f, _ := args.Get(0).(io.ReadCloser)
	return f, args.Error(1)
}

func (mfs *MockFileStore) ReadDir(name string) ([]fs.DirEntry, error) {
	args := mfs.Called(name)
	entries, _ := args.Get(0).([]fs.DirEntry)
	return entries, args.Error(1)
}

func (mfs *MockFileStore) ReadLink(name string) (string, error) {
	args := mfs.Called(name)
	return args.String(0), args.Error(1)
}

func (mfs *MockFileStore) Walk(root string, fn filepath.WalkFunc) error {
	args := mfs.Called(root, fn)
	return args.Error(0)
}

func (mfs *MockFileStore) OpenFile(name string, flag int, perm fs.FileMode) (io.WriteCloser, error) {
	args := mfs.Called(name, flag, perm)
	f, _ := args.Get(0).(io.WriteCloser)
	return f, args.Error(1)
}

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

func (mfs *MockFileStore) RemoveAll(name string) error {
	args := mfs.Called(name)
	return args.Error(0)
}

func (mfs *MockFileStore) Remove(name string) error {
	args := mfs.Called(name)
	return args.Error(0)
}

func (mfs *MockFileStore) Create(name string) (io.WriteCloser, error) {
	args := mfs.Called(name)
	f, _ := args.Get(0).(io.WriteCloser)
	return f, 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)
}

func (mfs *MockFileStore) Rename(oldpath, newpath string) error {
	args := mfs.Called(oldpath, newpath)
	return args.Error(0)
}

func (mfs *MockFileStore) ReadFile(name string) ([]byte, error) {
	args := mfs.Called(name)
	return args.Get(0).([]byte), args.Error(1)
}

type MockFileInfo struct {
	mock.Mock
}

var _ fs.FileInfo = (*MockFileInfo)(nil)

func (mfi *MockFileInfo) Name() string {
	args := mfi.Called()
	return args.String(0)
}

func (mfi *MockFileInfo) Size() int64 {
	args := mfi.Called()
	return args.Get(0).(int64)
}

func (mfi *MockFileInfo) Mode() fs.FileMode {
	args := mfi.Called()
	return args.Get(0).(fs.FileMode)
}

func (mfi *MockFileInfo) ModTime() time.Time {
	_ = mfi.Called()
	return time.Now()
}

func (mfi *MockFileInfo) IsDir() bool {
	args := mfi.Called()
	return args.Bool(0)
}

func (mfi *MockFileInfo) Sys() interface{} {
	_ = mfi.Called()
	return nil
}

type MockClientMgr struct {
	mock.Mock
}

var _ ClientManager = (*MockClientMgr)(nil)

func (m *MockClientMgr) List() []*ClientConn {
	args := m.Called()

	return args.Get(0).([]*ClientConn)
}

func (m *MockClientMgr) Get(id ClientID) *ClientConn {
	args := m.Called(id)

	return args.Get(0).(*ClientConn)
}

func (m *MockClientMgr) Add(cc *ClientConn) {
	m.Called(cc)
}

func (m *MockClientMgr) Delete(id ClientID) {
	m.Called(id)
}