Documentation
¶
Overview ¶
Package testutil provides shared test helpers: ephemeral SQLite databases with migrations applied, a MockProvider for the LLM interface, and a FakeTelegram httptest server that captures bot API calls. Production code never imports this package.
Index ¶
- func MockResponseJSON(body string) llm.Response
- func NewDB(t *testing.T) *sql.DB
- func SeedDefaultCategories(t *testing.T, q *sqlcgen.Queries) []sqlcgen.Category
- func SeedLLMConfig(t *testing.T, q *sqlcgen.Queries, provider, model string) sqlcgen.LlmConfig
- func SeedOwner(t *testing.T, q *sqlcgen.Queries) sqlcgen.Owner
- func SeedTelegramConfig(t *testing.T, q *sqlcgen.Queries, chatID int64) sqlcgen.TelegramConfig
- type FakeCall
- type FakeTelegram
- type MockProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MockResponseJSON ¶
MockResponseJSON wraps a raw JSON body in an llm.Response. Convenience for the most common assertion shape — canned parse output.
func NewDB ¶
NewDB returns a fresh *sql.DB with all migrations applied, on a temp file in t.TempDir(). The database is closed via t.Cleanup. Production-equivalent: WAL, foreign keys on, single-writer connection (matches db.Open).
func SeedDefaultCategories ¶
SeedDefaultCategories inserts the same 8 categories the production first-run setup creates: Food, Transport, Utilities, Housing, Health, Entertainment, Shopping, Other. Returns them in display order.
func SeedLLMConfig ¶
SeedLLMConfig inserts a usable llm_config row with the given provider and model. The encrypted-key column gets a non-empty placeholder so LLMEngine doesn't bail with errLLMNotConfigured — but tests using a MockProvider override never decrypt this value.
func SeedOwner ¶
SeedOwner inserts the singleton owner row with usable defaults. Returns the freshly-loaded Owner so the test has the post-insert state (including the auto-defaulted trash_retention_days and dashboard_url).
func SeedTelegramConfig ¶
SeedTelegramConfig inserts a usable telegram_config row paired to the given chat ID. The bot_token column gets a placeholder.
Types ¶
type FakeTelegram ¶
type FakeTelegram struct {
Server *httptest.Server
Calls []FakeCall
// contains filtered or unexported fields
}
FakeTelegram is an httptest.Server that mimics the Telegram Bot API for the methods the bot uses. Every captured call is appended to Calls so tests can assert outbound sendMessage / editMessageText / getFile / answerCallbackQuery payloads.
Constructor wires it as the BaseURL of a *telegram.Client; the client's callJSON path then hits the fake instead of api.telegram.org.
func NewFakeTelegram ¶
func NewFakeTelegram(t *testing.T) *FakeTelegram
NewFakeTelegram starts the httptest server. Always call Close in t.Cleanup (already wired here).
func (*FakeTelegram) Captured ¶
func (f *FakeTelegram) Captured() []FakeCall
Captured returns a snapshot of all calls so far, in order.
func (*FakeTelegram) CountCalls ¶
func (f *FakeTelegram) CountCalls(method string) int
CountCalls returns how many calls landed for the given method name.
func (*FakeTelegram) LastEditMessage ¶
func (f *FakeTelegram) LastEditMessage() map[string]any
LastEditMessage returns the most recent editMessageText body, or nil.
func (*FakeTelegram) LastSendMessage ¶
func (f *FakeTelegram) LastSendMessage() map[string]any
LastSendMessage returns the most recent sendMessage body, or nil.
func (*FakeTelegram) WithFile ¶
func (f *FakeTelegram) WithFile(fileID, mime string, body []byte)
WithFile registers binary content for a given file_id. The dispatcher's getFile + downloadFile sequence will return these bytes when the test pushes a Photo or Document Update with this file_id.
type MockProvider ¶
type MockProvider struct {
NameStr string
Resp llm.Response
Err error
Calls []llm.Request
// contains filtered or unexported fields
}
MockProvider implements llm.Provider with canned responses for tests. All Complete calls are recorded in Calls (mutex-guarded) so tests can assert what the dispatcher actually sent — system prompt content, images attached, model selected, etc.
Inject via DispatcherOpts.LLMProvider or Handler.LLMProvider.
func (*MockProvider) CallCount ¶
func (m *MockProvider) CallCount() int
CallCount returns the number of Complete invocations.
func (*MockProvider) LastCall ¶
func (m *MockProvider) LastCall() llm.Request
LastCall returns the most recently recorded Request, or zero value if none.
func (*MockProvider) Name ¶
func (m *MockProvider) Name() string