refactor(store): shared storetest.BaseMock replaces 5 duplicated mocks
New internal/store/storetest/mock.go provides BaseMock implementing the full Store interface with no-op defaults and optional Func field overrides. Each test file embeds BaseMock and shadows only the methods it needs. Removes ~400 lines of duplicated stub methods across 6 test files. Adding a Store method now requires one addition (BaseMock) instead of editing 6 files.
This commit was merged in pull request #107.
This commit is contained in:
@@ -9,22 +9,21 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.lerkolabs.com/lerkolabs/uptop/internal/models"
|
||||
"gitea.lerkolabs.com/lerkolabs/uptop/internal/store"
|
||||
"gitea.lerkolabs.com/lerkolabs/uptop/internal/store/storetest"
|
||||
|
||||
"github.com/charmbracelet/ssh"
|
||||
gossh "golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
// kcMockStore implements only what keyCache and userInvalidatingStore touch;
|
||||
// any other Store method panics via the embedded nil interface.
|
||||
// kcMockStore embeds BaseMock for default no-ops; only GetAllUsers is
|
||||
// overridden because the tests mutate users/err between calls.
|
||||
type kcMockStore struct {
|
||||
store.Store
|
||||
storetest.BaseMock
|
||||
users []models.User
|
||||
err error
|
||||
}
|
||||
|
||||
func (m *kcMockStore) GetAllUsers(_ context.Context) ([]models.User, error) { return m.users, m.err }
|
||||
func (m *kcMockStore) DeleteUser(_ context.Context, _ int) error { return nil }
|
||||
|
||||
func testKey(t *testing.T) (string, ssh.PublicKey) {
|
||||
t.Helper()
|
||||
|
||||
Reference in New Issue
Block a user