Documentation
¶
Overview ¶
Package testutil provides shared test utilities, helpers, and mock implementations used across the Lango test suite.
Index ¶
- func FailBootLoader(err error) func() (*bootstrap.Result, error)
- func FailCfgLoader(err error) func() (*config.Config, error)
- func FakeBootLoader(t testing.TB, cfg *config.Config) func() (*bootstrap.Result, error)
- func FakeCfgLoader(cfg *config.Config) func() (*config.Config, error)
- func NopLogger() *zap.SugaredLogger
- func SkipShort(t testing.TB)
- func TestEntClient(t testing.TB) *ent.Client
- type CLIResult
- type MockAgentRunner
- type MockChannelSender
- type MockCronStore
- func (m *MockCronStore) Create(_ context.Context, job cron.Job) error
- func (m *MockCronStore) CreateCalls() int
- func (m *MockCronStore) Delete(_ context.Context, id string) error
- func (m *MockCronStore) Get(_ context.Context, id string) (*cron.Job, error)
- func (m *MockCronStore) GetByName(_ context.Context, name string) (*cron.Job, error)
- func (m *MockCronStore) HistoryCount() int
- func (m *MockCronStore) JobCount() int
- func (m *MockCronStore) List(_ context.Context) ([]cron.Job, error)
- func (m *MockCronStore) ListAllHistory(_ context.Context, limit int) ([]cron.HistoryEntry, error)
- func (m *MockCronStore) ListEnabled(_ context.Context) ([]cron.Job, error)
- func (m *MockCronStore) ListHistory(_ context.Context, jobID string, limit int) ([]cron.HistoryEntry, error)
- func (m *MockCronStore) SaveHistory(_ context.Context, entry cron.HistoryEntry) error
- func (m *MockCronStore) Update(_ context.Context, job cron.Job) error
- func (m *MockCronStore) Upsert(_ context.Context, job cron.Job) (*cron.Job, bool, error)
- type MockCryptoProvider
- func (m *MockCryptoProvider) Decrypt(_ context.Context, _ string, _ []byte) ([]byte, error)
- func (m *MockCryptoProvider) DecryptCalls() int
- func (m *MockCryptoProvider) Encrypt(_ context.Context, _ string, _ []byte) ([]byte, error)
- func (m *MockCryptoProvider) EncryptCalls() int
- func (m *MockCryptoProvider) Sign(_ context.Context, _ string, _ []byte) ([]byte, error)
- func (m *MockCryptoProvider) SignCalls() int
- type MockEmbeddingProvider
- type MockGraphStore
- func (m *MockGraphStore) AddCalls() int
- func (m *MockGraphStore) AddTriple(_ context.Context, t graph.Triple) error
- func (m *MockGraphStore) AddTriples(_ context.Context, triples []graph.Triple) error
- func (m *MockGraphStore) AllTriples(_ context.Context) ([]graph.Triple, error)
- func (m *MockGraphStore) ClearAll(_ context.Context) error
- func (m *MockGraphStore) Close() error
- func (m *MockGraphStore) Count(_ context.Context) (int, error)
- func (m *MockGraphStore) PredicateStats(_ context.Context) (map[string]int, error)
- func (m *MockGraphStore) QueryByObject(_ context.Context, object string) ([]graph.Triple, error)
- func (m *MockGraphStore) QueryBySubject(_ context.Context, subject string) ([]graph.Triple, error)
- func (m *MockGraphStore) QueryBySubjectPredicate(_ context.Context, subject, predicate string) ([]graph.Triple, error)
- func (m *MockGraphStore) RemoveTriple(_ context.Context, t graph.Triple) error
- func (m *MockGraphStore) Traverse(_ context.Context, startNode string, maxDepth int, predicates []string) ([]graph.Triple, error)
- func (m *MockGraphStore) TripleCount() int
- type MockProvider
- func (m *MockProvider) Generate(_ context.Context, params provider.GenerateParams) (iter.Seq2[provider.StreamEvent, error], error)
- func (m *MockProvider) GenerateCalls() int
- func (m *MockProvider) ID() string
- func (m *MockProvider) LastParams() *provider.GenerateParams
- func (m *MockProvider) ListModels(_ context.Context) ([]provider.ModelInfo, error)
- func (m *MockProvider) ListModelsCalls() int
- type MockSessionStore
- func (m *MockSessionStore) AnnotateTimeout(key string, partial string) error
- func (m *MockSessionStore) AnnotateTimeoutCalls() int
- func (m *MockSessionStore) AppendMessage(key string, msg session.Message) error
- func (m *MockSessionStore) AppendMessageCalls() int
- func (m *MockSessionStore) Close() error
- func (m *MockSessionStore) CloseCalls() int
- func (m *MockSessionStore) Create(s *session.Session) error
- func (m *MockSessionStore) CreateCalls() int
- func (m *MockSessionStore) Delete(key string) error
- func (m *MockSessionStore) DeleteCalls() int
- func (m *MockSessionStore) Get(key string) (*session.Session, error)
- func (m *MockSessionStore) GetCalls() int
- func (m *MockSessionStore) GetSalt(name string) ([]byte, error)
- func (m *MockSessionStore) HasSession(key string) bool
- func (m *MockSessionStore) ListSessions(_ context.Context) ([]session.SessionSummary, error)
- func (m *MockSessionStore) SessionCount() int
- func (m *MockSessionStore) SetSalt(name string, salt []byte) error
- func (m *MockSessionStore) Update(s *session.Session) error
- func (m *MockSessionStore) UpdateCalls() int
- type MockTextGenerator
- type SentMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FailBootLoader ¶ added in v0.7.0
FailBootLoader returns a bootLoader func that always returns the given error.
func FailCfgLoader ¶ added in v0.7.0
FailCfgLoader returns a cfgLoader func that always returns the given error.
func FakeBootLoader ¶ added in v0.7.0
FakeBootLoader returns a bootLoader func that creates an in-memory Ent client. The client is closed when the test completes.
func FakeCfgLoader ¶ added in v0.7.0
FakeCfgLoader returns a cfgLoader func that always returns the given config.
func NopLogger ¶
func NopLogger() *zap.SugaredLogger
NopLogger returns a no-op *zap.SugaredLogger suitable for tests.
Types ¶
type CLIResult ¶ added in v0.7.0
CLIResult captures the output of a CLI command execution.
func ExecCmd ¶ added in v0.7.0
ExecCmd executes a cobra command with the given args and captures output. It intercepts os.Stdout via os.Pipe to catch direct fmt.Print* / json.Encoder writes that bypass cobra's OutOrStdout.
NOTE: This function replaces os.Stdout globally and is NOT safe for use with t.Parallel(). Tests using ExecCmd must run sequentially.
type MockAgentRunner ¶
MockAgentRunner is a thread-safe mock for cron.AgentRunner.
func NewMockAgentRunner ¶
func NewMockAgentRunner(response string) *MockAgentRunner
NewMockAgentRunner creates a MockAgentRunner with the given response.
func (*MockAgentRunner) Calls ¶
func (m *MockAgentRunner) Calls() int
Calls returns the number of Run calls.
func (*MockAgentRunner) LastSessionKey ¶
func (m *MockAgentRunner) LastSessionKey() string
LastSessionKey returns the last session key passed to Run.
type MockChannelSender ¶
type MockChannelSender struct {
Err error
// contains filtered or unexported fields
}
MockChannelSender is a thread-safe mock for cron.ChannelSender.
func NewMockChannelSender ¶
func NewMockChannelSender() *MockChannelSender
NewMockChannelSender creates a MockChannelSender.
func (*MockChannelSender) Calls ¶
func (m *MockChannelSender) Calls() int
Calls returns the number of SendMessage calls.
func (*MockChannelSender) Messages ¶
func (m *MockChannelSender) Messages() []SentMessage
Messages returns all sent messages.
func (*MockChannelSender) SendMessage ¶
type MockCronStore ¶
type MockCronStore struct {
CreateErr error
GetErr error
ListErr error
UpdateErr error
DeleteErr error
SaveHistoryErr error
// contains filtered or unexported fields
}
MockCronStore is a thread-safe in-memory mock of cron.Store.
func NewMockCronStore ¶
func NewMockCronStore() *MockCronStore
NewMockCronStore creates an empty MockCronStore.
func (*MockCronStore) CreateCalls ¶
func (m *MockCronStore) CreateCalls() int
CreateCalls returns the number of Create calls.
func (*MockCronStore) HistoryCount ¶
func (m *MockCronStore) HistoryCount() int
HistoryCount returns the number of stored history entries.
func (*MockCronStore) JobCount ¶
func (m *MockCronStore) JobCount() int
JobCount returns the number of stored jobs.
func (*MockCronStore) ListAllHistory ¶
func (m *MockCronStore) ListAllHistory(_ context.Context, limit int) ([]cron.HistoryEntry, error)
func (*MockCronStore) ListEnabled ¶
func (*MockCronStore) ListHistory ¶
func (m *MockCronStore) ListHistory(_ context.Context, jobID string, limit int) ([]cron.HistoryEntry, error)
func (*MockCronStore) SaveHistory ¶
func (m *MockCronStore) SaveHistory(_ context.Context, entry cron.HistoryEntry) error
type MockCryptoProvider ¶
type MockCryptoProvider struct {
SignResult []byte
EncryptResult []byte
DecryptResult []byte
SignErr error
EncryptErr error
DecryptErr error
// contains filtered or unexported fields
}
MockCryptoProvider is a thread-safe mock of security.CryptoProvider.
func NewMockCryptoProvider ¶
func NewMockCryptoProvider() *MockCryptoProvider
NewMockCryptoProvider creates a MockCryptoProvider with default passthrough behavior.
func (*MockCryptoProvider) DecryptCalls ¶
func (m *MockCryptoProvider) DecryptCalls() int
DecryptCalls returns the number of Decrypt calls.
func (*MockCryptoProvider) EncryptCalls ¶
func (m *MockCryptoProvider) EncryptCalls() int
EncryptCalls returns the number of Encrypt calls.
func (*MockCryptoProvider) SignCalls ¶
func (m *MockCryptoProvider) SignCalls() int
SignCalls returns the number of Sign calls.
type MockEmbeddingProvider ¶
type MockEmbeddingProvider struct {
ProviderID string
EmbedDimension int
Vectors [][]float32
EmbedErr error
// contains filtered or unexported fields
}
MockEmbeddingProvider is a thread-safe mock of embedding.EmbeddingProvider.
func NewMockEmbeddingProvider ¶
func NewMockEmbeddingProvider(id string, dims int) *MockEmbeddingProvider
NewMockEmbeddingProvider creates a provider that returns zero vectors of the given dimension.
func (*MockEmbeddingProvider) Dimensions ¶
func (m *MockEmbeddingProvider) Dimensions() int
func (*MockEmbeddingProvider) EmbedCalls ¶
func (m *MockEmbeddingProvider) EmbedCalls() int
EmbedCalls returns the number of Embed calls.
func (*MockEmbeddingProvider) ID ¶
func (m *MockEmbeddingProvider) ID() string
func (*MockEmbeddingProvider) LastTexts ¶
func (m *MockEmbeddingProvider) LastTexts() []string
LastTexts returns the last texts passed to Embed.
type MockGraphStore ¶
type MockGraphStore struct {
AddErr error
QueryErr error
// contains filtered or unexported fields
}
MockGraphStore is a thread-safe in-memory mock of graph.Store.
func NewMockGraphStore ¶
func NewMockGraphStore() *MockGraphStore
NewMockGraphStore creates an empty MockGraphStore.
func (*MockGraphStore) AddCalls ¶
func (m *MockGraphStore) AddCalls() int
AddCalls returns the number of Add calls.
func (*MockGraphStore) AddTriples ¶
func (*MockGraphStore) AllTriples ¶
func (*MockGraphStore) Close ¶
func (m *MockGraphStore) Close() error
func (*MockGraphStore) PredicateStats ¶
func (*MockGraphStore) QueryByObject ¶
func (*MockGraphStore) QueryBySubject ¶
func (*MockGraphStore) QueryBySubjectPredicate ¶
func (*MockGraphStore) RemoveTriple ¶
func (*MockGraphStore) TripleCount ¶
func (m *MockGraphStore) TripleCount() int
TripleCount returns the number of stored triples.
type MockProvider ¶
type MockProvider struct {
// Configurable responses
ProviderID string
Events []provider.StreamEvent
Models []provider.ModelInfo
// Configurable error injection
GenerateErr error
ListModelsErr error
// contains filtered or unexported fields
}
MockProvider is a thread-safe mock implementation of provider.Provider for tests.
func NewMockProvider ¶
func NewMockProvider(id string) *MockProvider
NewMockProvider creates a new MockProvider with the given ID.
func (*MockProvider) Generate ¶
func (m *MockProvider) Generate(_ context.Context, params provider.GenerateParams) (iter.Seq2[provider.StreamEvent, error], error)
func (*MockProvider) GenerateCalls ¶
func (m *MockProvider) GenerateCalls() int
GenerateCalls returns the number of Generate calls.
func (*MockProvider) ID ¶
func (m *MockProvider) ID() string
func (*MockProvider) LastParams ¶
func (m *MockProvider) LastParams() *provider.GenerateParams
LastParams returns the last GenerateParams passed to Generate.
func (*MockProvider) ListModels ¶
func (*MockProvider) ListModelsCalls ¶
func (m *MockProvider) ListModelsCalls() int
ListModelsCalls returns the number of ListModels calls.
type MockSessionStore ¶
type MockSessionStore struct {
// Configurable error injection
CreateErr error
GetErr error
UpdateErr error
DeleteErr error
AppendMessageErr error
AnnotateTimeoutErr error
CloseErr error
GetSaltErr error
SetSaltErr error
// contains filtered or unexported fields
}
MockSessionStore is a thread-safe in-memory implementation of session.Store for use in tests. All error fields can be set to inject failures.
func NewMockSessionStore ¶
func NewMockSessionStore() *MockSessionStore
NewMockSessionStore creates a new MockSessionStore.
func (*MockSessionStore) AnnotateTimeout ¶ added in v0.6.0
func (m *MockSessionStore) AnnotateTimeout(key string, partial string) error
func (*MockSessionStore) AnnotateTimeoutCalls ¶ added in v0.6.0
func (m *MockSessionStore) AnnotateTimeoutCalls() int
AnnotateTimeoutCalls returns the number of AnnotateTimeout calls.
func (*MockSessionStore) AppendMessage ¶
func (m *MockSessionStore) AppendMessage(key string, msg session.Message) error
func (*MockSessionStore) AppendMessageCalls ¶
func (m *MockSessionStore) AppendMessageCalls() int
AppendMessageCalls returns the number of AppendMessage calls.
func (*MockSessionStore) Close ¶
func (m *MockSessionStore) Close() error
func (*MockSessionStore) CloseCalls ¶
func (m *MockSessionStore) CloseCalls() int
CloseCalls returns the number of Close calls.
func (*MockSessionStore) CreateCalls ¶
func (m *MockSessionStore) CreateCalls() int
CreateCalls returns the number of Create calls.
func (*MockSessionStore) Delete ¶
func (m *MockSessionStore) Delete(key string) error
func (*MockSessionStore) DeleteCalls ¶
func (m *MockSessionStore) DeleteCalls() int
DeleteCalls returns the number of Delete calls.
func (*MockSessionStore) GetCalls ¶
func (m *MockSessionStore) GetCalls() int
GetCalls returns the number of Get calls.
func (*MockSessionStore) HasSession ¶
func (m *MockSessionStore) HasSession(key string) bool
HasSession returns true if a session with the given key exists.
func (*MockSessionStore) ListSessions ¶ added in v0.7.0
func (m *MockSessionStore) ListSessions(_ context.Context) ([]session.SessionSummary, error)
func (*MockSessionStore) SessionCount ¶
func (m *MockSessionStore) SessionCount() int
SessionCount returns the number of stored sessions.
func (*MockSessionStore) SetSalt ¶
func (m *MockSessionStore) SetSalt(name string, salt []byte) error
func (*MockSessionStore) UpdateCalls ¶
func (m *MockSessionStore) UpdateCalls() int
UpdateCalls returns the number of Update calls.
type MockTextGenerator ¶
type MockTextGenerator struct {
Response string
Err error
// contains filtered or unexported fields
}
MockTextGenerator is a thread-safe mock for the TextGenerator interface used in memory, graph, and learning packages.
func NewMockTextGenerator ¶
func NewMockTextGenerator(response string) *MockTextGenerator
NewMockTextGenerator creates a MockTextGenerator with the given response.
func (*MockTextGenerator) Calls ¶
func (m *MockTextGenerator) Calls() int
Calls returns the number of GenerateText calls.
func (*MockTextGenerator) GenerateText ¶
func (*MockTextGenerator) LastArgs ¶
func (m *MockTextGenerator) LastArgs() (string, string)
LastArgs returns the last system and user prompts.
type SentMessage ¶
SentMessage records a message sent via MockChannelSender.