testutil

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package testutil provides centralized test mocks, fixtures, and helpers. All test files should import mocks from here instead of defining their own.

Index

Constants

View Source
const TestUserID int64 = 123

TestUserID is the default user ID for tests.

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to the given value. Useful for optional fields.

func SetupDefaultMocks

func SetupDefaultMocks(s *MockStorage)

SetupDefaultMocks configures mocks with safe defaults for background operations. Call this when testing code that may trigger background loops.

func TestAgentLog

func TestAgentLog() storage.AgentLog

TestAgentLog returns a sample agent log for testing.

func TestConfig

func TestConfig() *config.Config

TestConfig returns a config with sensible test defaults.

func TestConfigWithRAGDisabled

func TestConfigWithRAGDisabled() *config.Config

TestConfigWithRAGDisabled returns a test config with RAG disabled.

func TestDashboardStats

func TestDashboardStats() *storage.DashboardStats

TestDashboardStats returns sample dashboard stats for testing.

func TestEmbedding

func TestEmbedding() []float32

TestEmbedding returns a sample embedding vector for testing.

func TestFacts

func TestFacts() []storage.Fact

TestFacts returns sample facts for testing.

func TestFileProcessor

func TestFileProcessor(t *testing.T, downloader *MockFileDownloader, translator *i18n.Translator) *files.Processor

TestFileProcessor creates a file processor for tests.

func TestLogger

func TestLogger() *slog.Logger

TestLogger returns a discarding logger for tests.

func TestMessage

func TestMessage() storage.Message

TestMessage returns a sample message for testing.

func TestMessages

func TestMessages() []storage.Message

TestMessages returns a conversation history for testing.

func TestProfileFacts

func TestProfileFacts() []storage.Fact

TestProfileFacts returns facts that would be included in a user profile.

func TestStat

func TestStat() storage.Stat

TestStat returns a sample stat for testing.

func TestTopic

func TestTopic() storage.Topic

TestTopic returns a sample topic for testing.

func TestTopics

func TestTopics() []storage.Topic

TestTopics returns multiple sample topics for testing.

func TestTranslator

func TestTranslator(t *testing.T) *i18n.Translator

TestTranslator creates a translator with minimal translations for tests. Use t.TempDir() automatically cleaned up after test.

func TestUser

func TestUser() storage.User

TestUser returns a standard test user.

func TestUsers

func TestUsers() []storage.User

TestUsers returns multiple test users.

Types

type MockBotAPI

type MockBotAPI struct {
	mock.Mock
}

MockBotAPI implements telegram.BotAPI for tests.

func (*MockBotAPI) GetFile

func (*MockBotAPI) GetToken

func (m *MockBotAPI) GetToken() string

func (*MockBotAPI) GetUpdates

func (*MockBotAPI) SendChatAction

func (m *MockBotAPI) SendChatAction(ctx context.Context, req telegram.SendChatActionRequest) error

func (*MockBotAPI) SendMessage

func (*MockBotAPI) SetMessageReaction

func (m *MockBotAPI) SetMessageReaction(ctx context.Context, req telegram.SetMessageReactionRequest) error

func (*MockBotAPI) SetMyCommands

func (m *MockBotAPI) SetMyCommands(ctx context.Context, req telegram.SetMyCommandsRequest) error

func (*MockBotAPI) SetWebhook

func (m *MockBotAPI) SetWebhook(ctx context.Context, req telegram.SetWebhookRequest) error

type MockFileDownloader

type MockFileDownloader struct {
	mock.Mock
}

MockFileDownloader implements telegram.FileDownloader for tests.

func (*MockFileDownloader) DownloadFile

func (m *MockFileDownloader) DownloadFile(ctx context.Context, fileID string) ([]byte, error)

func (*MockFileDownloader) DownloadFileAsBase64

func (m *MockFileDownloader) DownloadFileAsBase64(ctx context.Context, fileID string) (string, error)

type MockOpenRouterClient

type MockOpenRouterClient struct {
	mock.Mock
}

MockOpenRouterClient implements openrouter.Client for tests.

func (*MockOpenRouterClient) CreateChatCompletion

func (*MockOpenRouterClient) CreateEmbeddings

type MockStorage

type MockStorage struct {
	mock.Mock
}

MockStorage implements all storage repository interfaces for tests. This is a composite mock that covers MessageRepository, UserRepository, TopicRepository, FactRepository, FactHistoryRepository, StatsRepository, MemoryBankRepository, MaintenanceRepository, and AgentLogRepository.

func (*MockStorage) AddAgentLog

func (m *MockStorage) AddAgentLog(log storage.AgentLog) error

func (*MockStorage) AddFact

func (m *MockStorage) AddFact(fact storage.Fact) (int64, error)

func (*MockStorage) AddFactHistory

func (m *MockStorage) AddFactHistory(history storage.FactHistory) error

func (*MockStorage) AddMessageToHistory

func (m *MockStorage) AddMessageToHistory(userID int64, message storage.Message) error

func (*MockStorage) AddPerson added in v0.5.1

func (m *MockStorage) AddPerson(person storage.Person) (int64, error)

func (*MockStorage) AddStat

func (m *MockStorage) AddStat(stat storage.Stat) error

func (*MockStorage) AddTopic

func (m *MockStorage) AddTopic(topic storage.Topic) (int64, error)

func (*MockStorage) AddTopicWithoutMessageUpdate

func (m *MockStorage) AddTopicWithoutMessageUpdate(topic storage.Topic) (int64, error)

func (*MockStorage) Checkpoint

func (m *MockStorage) Checkpoint() error

func (*MockStorage) CleanupAgentLogs

func (m *MockStorage) CleanupAgentLogs(keepPerUserPerAgent int) (int64, error)

func (*MockStorage) CleanupFactHistory

func (m *MockStorage) CleanupFactHistory(keepPerUser int) (int64, error)

func (*MockStorage) ClearHistory

func (m *MockStorage) ClearHistory(userID int64) error

func (*MockStorage) CountAgentLogs

func (m *MockStorage) CountAgentLogs() (int64, error)

func (*MockStorage) CountContaminatedTopics

func (m *MockStorage) CountContaminatedTopics(userID int64) (int, error)

func (*MockStorage) CountFactHistory

func (m *MockStorage) CountFactHistory() (int64, error)

func (*MockStorage) CountFactsOnOrphanedTopics

func (m *MockStorage) CountFactsOnOrphanedTopics(userID int64) (int, error)

func (*MockStorage) CountOrphanedTopics

func (m *MockStorage) CountOrphanedTopics(userID int64) (int, error)

func (*MockStorage) CountOverlappingTopics

func (m *MockStorage) CountOverlappingTopics(userID int64) (int, error)

func (*MockStorage) CountPeopleWithoutEmbedding added in v0.5.1

func (m *MockStorage) CountPeopleWithoutEmbedding(userID int64) (int, error)

func (*MockStorage) CreateTopic

func (m *MockStorage) CreateTopic(topic storage.Topic) (int64, error)

func (*MockStorage) DeleteFact

func (m *MockStorage) DeleteFact(userID, id int64) error

func (*MockStorage) DeletePerson added in v0.5.1

func (m *MockStorage) DeletePerson(userID, personID int64) error

func (*MockStorage) DeleteTopic

func (m *MockStorage) DeleteTopic(id int64) error

func (*MockStorage) DeleteTopicCascade

func (m *MockStorage) DeleteTopicCascade(id int64) error

func (*MockStorage) FindPersonByAlias added in v0.5.1

func (m *MockStorage) FindPersonByAlias(userID int64, alias string) ([]storage.Person, error)

func (*MockStorage) FindPersonByName added in v0.5.1

func (m *MockStorage) FindPersonByName(userID int64, name string) (*storage.Person, error)

func (*MockStorage) FindPersonByTelegramID added in v0.5.1

func (m *MockStorage) FindPersonByTelegramID(userID, telegramID int64) (*storage.Person, error)

func (*MockStorage) FindPersonByUsername added in v0.5.1

func (m *MockStorage) FindPersonByUsername(userID int64, username string) (*storage.Person, error)

func (*MockStorage) FixContaminatedTopics

func (m *MockStorage) FixContaminatedTopics(userID int64) (int64, error)

func (*MockStorage) GetAgentLogs

func (m *MockStorage) GetAgentLogs(agentType string, userID int64, limit int) ([]storage.AgentLog, error)

func (*MockStorage) GetAgentLogsExtended

func (m *MockStorage) GetAgentLogsExtended(filter storage.AgentLogFilter, limit, offset int) (storage.AgentLogResult, error)

func (*MockStorage) GetAllFacts

func (m *MockStorage) GetAllFacts() ([]storage.Fact, error)

func (*MockStorage) GetAllPeople added in v0.5.1

func (m *MockStorage) GetAllPeople() ([]storage.Person, error)

func (*MockStorage) GetAllTopics

func (m *MockStorage) GetAllTopics() ([]storage.Topic, error)

func (*MockStorage) GetAllUsers

func (m *MockStorage) GetAllUsers() ([]storage.User, error)

func (*MockStorage) GetContaminatedTopics

func (m *MockStorage) GetContaminatedTopics(userID int64) ([]storage.ContaminatedTopic, error)

func (*MockStorage) GetDBSize

func (m *MockStorage) GetDBSize() (int64, error)

func (*MockStorage) GetDashboardStats

func (m *MockStorage) GetDashboardStats(userID int64) (*storage.DashboardStats, error)

func (*MockStorage) GetFactHistory

func (m *MockStorage) GetFactHistory(userID int64, limit int) ([]storage.FactHistory, error)

func (*MockStorage) GetFactHistoryExtended

func (m *MockStorage) GetFactHistoryExtended(filter storage.FactHistoryFilter, limit, offset int, sortBy, sortDir string) (storage.FactHistoryResult, error)

func (*MockStorage) GetFactStats

func (m *MockStorage) GetFactStats() (storage.FactStats, error)

func (*MockStorage) GetFactStatsByUser

func (m *MockStorage) GetFactStatsByUser(userID int64) (storage.FactStats, error)

func (*MockStorage) GetFacts

func (m *MockStorage) GetFacts(userID int64) ([]storage.Fact, error)

func (*MockStorage) GetFactsAfterID

func (m *MockStorage) GetFactsAfterID(minID int64) ([]storage.Fact, error)

func (*MockStorage) GetFactsByIDs

func (m *MockStorage) GetFactsByIDs(ids []int64) ([]storage.Fact, error)

func (*MockStorage) GetFactsByTopicID

func (m *MockStorage) GetFactsByTopicID(topicID int64) ([]storage.Fact, error)

func (*MockStorage) GetLastTopicEndMessageID

func (m *MockStorage) GetLastTopicEndMessageID(userID int64) (int64, error)

func (*MockStorage) GetMemoryBank

func (m *MockStorage) GetMemoryBank(userID int64) (string, error)

func (*MockStorage) GetMergeCandidates

func (m *MockStorage) GetMergeCandidates(userID int64) ([]storage.MergeCandidate, error)

func (*MockStorage) GetMessagesByIDs

func (m *MockStorage) GetMessagesByIDs(ids []int64) ([]storage.Message, error)

func (*MockStorage) GetMessagesByTopicID

func (m *MockStorage) GetMessagesByTopicID(ctx context.Context, topicID int64) ([]storage.Message, error)

func (*MockStorage) GetMessagesInRange

func (m *MockStorage) GetMessagesInRange(ctx context.Context, userID int64, startID, endID int64) ([]storage.Message, error)

func (*MockStorage) GetOrphanedTopicIDs

func (m *MockStorage) GetOrphanedTopicIDs(userID int64) ([]int64, error)

func (*MockStorage) GetOverlappingTopics

func (m *MockStorage) GetOverlappingTopics(userID int64) ([]storage.OverlappingPair, error)

func (*MockStorage) GetPeople added in v0.5.1

func (m *MockStorage) GetPeople(userID int64) ([]storage.Person, error)

func (*MockStorage) GetPeopleAfterID added in v0.5.1

func (m *MockStorage) GetPeopleAfterID(minID int64) ([]storage.Person, error)

func (*MockStorage) GetPeopleByIDs added in v0.5.1

func (m *MockStorage) GetPeopleByIDs(ids []int64) ([]storage.Person, error)

func (*MockStorage) GetPeopleExtended added in v0.5.1

func (m *MockStorage) GetPeopleExtended(filter storage.PersonFilter, limit, offset int, sortBy, sortDir string) (storage.PersonResult, error)

func (*MockStorage) GetPeopleWithoutEmbedding added in v0.5.1

func (m *MockStorage) GetPeopleWithoutEmbedding(userID int64) ([]storage.Person, error)

func (*MockStorage) GetPerson added in v0.5.1

func (m *MockStorage) GetPerson(userID, personID int64) (*storage.Person, error)

func (*MockStorage) GetRecentHistory

func (m *MockStorage) GetRecentHistory(userID int64, limit int) ([]storage.Message, error)

func (*MockStorage) GetStats

func (m *MockStorage) GetStats() (map[int64]storage.Stat, error)

func (*MockStorage) GetTableSizes

func (m *MockStorage) GetTableSizes() ([]storage.TableSize, error)

func (*MockStorage) GetTopics

func (m *MockStorage) GetTopics(userID int64) ([]storage.Topic, error)

func (*MockStorage) GetTopicsAfterID

func (m *MockStorage) GetTopicsAfterID(minID int64) ([]storage.Topic, error)

func (*MockStorage) GetTopicsByIDs

func (m *MockStorage) GetTopicsByIDs(ids []int64) ([]storage.Topic, error)

func (*MockStorage) GetTopicsExtended

func (m *MockStorage) GetTopicsExtended(filter storage.TopicFilter, limit, offset int, sortBy, sortDir string) (storage.TopicResult, error)

func (*MockStorage) GetTopicsPendingFacts

func (m *MockStorage) GetTopicsPendingFacts(userID int64) ([]storage.Topic, error)

func (*MockStorage) GetUnprocessedMessages

func (m *MockStorage) GetUnprocessedMessages(userID int64) ([]storage.Message, error)

func (*MockStorage) ImportMessage

func (m *MockStorage) ImportMessage(userID int64, message storage.Message) error

func (*MockStorage) MergePeople added in v0.5.1

func (m *MockStorage) MergePeople(userID, targetID, sourceID int64, newBio string, newAliases []string) error

func (*MockStorage) RecalculateTopicRanges

func (m *MockStorage) RecalculateTopicRanges(userID int64) (int, error)

func (*MockStorage) RecalculateTopicSizes

func (m *MockStorage) RecalculateTopicSizes(userID int64) (int, error)

func (*MockStorage) ResetUserData

func (m *MockStorage) ResetUserData(userID int64) error

func (*MockStorage) SetTopicConsolidationChecked

func (m *MockStorage) SetTopicConsolidationChecked(topicID int64, checked bool) error

func (*MockStorage) SetTopicFactsExtracted

func (m *MockStorage) SetTopicFactsExtracted(topicID int64, extracted bool) error

func (*MockStorage) UpdateFact

func (m *MockStorage) UpdateFact(fact storage.Fact) error

func (*MockStorage) UpdateFactHistoryTopic

func (m *MockStorage) UpdateFactHistoryTopic(oldTopicID, newTopicID int64) error

func (*MockStorage) UpdateFactTopic

func (m *MockStorage) UpdateFactTopic(oldTopicID, newTopicID int64) error

func (*MockStorage) UpdateMemoryBank

func (m *MockStorage) UpdateMemoryBank(userID int64, content string) error

func (*MockStorage) UpdateMessageTopic

func (m *MockStorage) UpdateMessageTopic(messageID, topicID int64) error

func (*MockStorage) UpdateMessagesTopicInRange

func (m *MockStorage) UpdateMessagesTopicInRange(ctx context.Context, userID, startMsgID, endMsgID, topicID int64) error

func (*MockStorage) UpdatePerson added in v0.5.1

func (m *MockStorage) UpdatePerson(person storage.Person) error

func (*MockStorage) UpsertUser

func (m *MockStorage) UpsertUser(user storage.User) error

type MockVectorSearcher

type MockVectorSearcher struct {
	mock.Mock
}

MockVectorSearcher implements rag.VectorSearcher for tests.

func (*MockVectorSearcher) FindSimilarFacts

func (m *MockVectorSearcher) FindSimilarFacts(ctx context.Context, userID int64, embedding []float32, threshold float32) ([]storage.Fact, error)

type MockYandexClient

type MockYandexClient struct {
	mock.Mock
}

MockYandexClient implements yandex.SpeechKitClient for tests.

func (*MockYandexClient) Recognize

func (m *MockYandexClient) Recognize(ctx context.Context, audioData []byte) (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL