diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2026-07-10 09:45:04 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2026-07-10 09:48:18 -0700 |
| commit | f50aad709075c1f06bfc7285c3185382dfcdcf20 (patch) | |
| tree | f709b2e312505b51236cabea0b06adec265913f7 /hotline/mocks_test.go | |
| parent | 21f24d24fd6f501b32f15a2bef41c89cc461f623 (diff) | |
Move testify mocks out of production files into hotline/hltest
The manager mocks lived in production source so that internal/mobius
tests could import them (test files are not importable across
packages), which pulled testify into the production dependency graph
of hotline importers, counted the mocks against coverage, and put them
in the library's godoc. They now live in hotline/hltest, an
httptest-style test-support package.
The hotline package's own in-package tests cannot import hltest (import
cycle), so the mocks they use are duplicated in mocks_test.go;
conformance assertions in both files catch signature drift.
MockAccountManager was only ever used inside internal/mobius and moves
to a _test.go file there.
Diffstat (limited to 'hotline/mocks_test.go')
| -rw-r--r-- | hotline/mocks_test.go | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/hotline/mocks_test.go b/hotline/mocks_test.go new file mode 100644 index 0000000..bd17b3b --- /dev/null +++ b/hotline/mocks_test.go @@ -0,0 +1,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) +} |