testutil

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package testutil provides shared test utilities, helpers, and mock implementations used across the Lango test suite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FailBootLoader added in v0.7.0

func FailBootLoader(err error) func() (*bootstrap.Result, error)

FailBootLoader returns a bootLoader func that always returns the given error.

func FailCfgLoader added in v0.7.0

func FailCfgLoader(err error) func() (*config.Config, error)

FailCfgLoader returns a cfgLoader func that always returns the given error.

func FakeBootLoader added in v0.7.0

func FakeBootLoader(t testing.TB, cfg *config.Config) func() (*bootstrap.Result, error)

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

func FakeCfgLoader(cfg *config.Config) func() (*config.Config, error)

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.

func SkipShort

func SkipShort(t testing.TB)

SkipShort skips the test when running with -short flag.

func TestEntClient

func TestEntClient(t testing.TB) *ent.Client

TestEntClient returns an in-memory Ent client with auto-migration. The client is automatically closed when the test completes.

Types

type CLIResult added in v0.7.0

type CLIResult struct {
	Stdout string
	Stderr string
	Err    error
}

CLIResult captures the output of a CLI command execution.

func ExecCmd added in v0.7.0

func ExecCmd(t testing.TB, cmd *cobra.Command, args ...string) CLIResult

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.

func ExecCmdOK added in v0.7.0

func ExecCmdOK(t testing.TB, cmd *cobra.Command, args ...string) CLIResult

ExecCmdOK executes a cobra command and asserts it succeeds.

type MockAgentRunner

type MockAgentRunner struct {
	Response string
	Err      error
	// contains filtered or unexported fields
}

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.

func (*MockAgentRunner) Run

func (m *MockAgentRunner) Run(_ context.Context, sessionKey string, _ string) (string, error)

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

func (m *MockChannelSender) SendMessage(_ context.Context, channel string, message string) error

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) Create

func (m *MockCronStore) Create(_ context.Context, job cron.Job) error

func (*MockCronStore) CreateCalls

func (m *MockCronStore) CreateCalls() int

CreateCalls returns the number of Create calls.

func (*MockCronStore) Delete

func (m *MockCronStore) Delete(_ context.Context, id string) error

func (*MockCronStore) Get

func (m *MockCronStore) Get(_ context.Context, id string) (*cron.Job, error)

func (*MockCronStore) GetByName

func (m *MockCronStore) GetByName(_ context.Context, name string) (*cron.Job, error)

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) List

func (m *MockCronStore) List(_ context.Context) ([]cron.Job, error)

func (*MockCronStore) ListAllHistory

func (m *MockCronStore) ListAllHistory(_ context.Context, limit int) ([]cron.HistoryEntry, error)

func (*MockCronStore) ListEnabled

func (m *MockCronStore) ListEnabled(_ context.Context) ([]cron.Job, error)

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

func (*MockCronStore) Update

func (m *MockCronStore) Update(_ context.Context, job cron.Job) error

func (*MockCronStore) Upsert added in v0.6.0

func (m *MockCronStore) Upsert(_ context.Context, job cron.Job) (*cron.Job, bool, 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) Decrypt

func (m *MockCryptoProvider) Decrypt(_ context.Context, _ string, _ []byte) ([]byte, error)

func (*MockCryptoProvider) DecryptCalls

func (m *MockCryptoProvider) DecryptCalls() int

DecryptCalls returns the number of Decrypt calls.

func (*MockCryptoProvider) Encrypt

func (m *MockCryptoProvider) Encrypt(_ context.Context, _ string, _ []byte) ([]byte, error)

func (*MockCryptoProvider) EncryptCalls

func (m *MockCryptoProvider) EncryptCalls() int

EncryptCalls returns the number of Encrypt calls.

func (*MockCryptoProvider) Sign

func (m *MockCryptoProvider) Sign(_ context.Context, _ string, _ []byte) ([]byte, error)

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) Embed

func (m *MockEmbeddingProvider) Embed(_ context.Context, texts []string) ([][]float32, error)

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) AddTriple

func (m *MockGraphStore) AddTriple(_ context.Context, t graph.Triple) error

func (*MockGraphStore) AddTriples

func (m *MockGraphStore) AddTriples(_ context.Context, triples []graph.Triple) error

func (*MockGraphStore) AllTriples

func (m *MockGraphStore) AllTriples(_ context.Context) ([]graph.Triple, error)

func (*MockGraphStore) ClearAll

func (m *MockGraphStore) ClearAll(_ context.Context) error

func (*MockGraphStore) Close

func (m *MockGraphStore) Close() error

func (*MockGraphStore) Count

func (m *MockGraphStore) Count(_ context.Context) (int, error)

func (*MockGraphStore) PredicateStats

func (m *MockGraphStore) PredicateStats(_ context.Context) (map[string]int, error)

func (*MockGraphStore) QueryByObject

func (m *MockGraphStore) QueryByObject(_ context.Context, object string) ([]graph.Triple, error)

func (*MockGraphStore) QueryBySubject

func (m *MockGraphStore) QueryBySubject(_ context.Context, subject string) ([]graph.Triple, error)

func (*MockGraphStore) QueryBySubjectPredicate

func (m *MockGraphStore) QueryBySubjectPredicate(_ context.Context, subject, predicate string) ([]graph.Triple, error)

func (*MockGraphStore) RemoveTriple

func (m *MockGraphStore) RemoveTriple(_ context.Context, t graph.Triple) error

func (*MockGraphStore) Traverse

func (m *MockGraphStore) Traverse(_ context.Context, startNode string, maxDepth int, predicates []string) ([]graph.Triple, error)

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 (*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 (m *MockProvider) ListModels(_ context.Context) ([]provider.ModelInfo, error)

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) Create

func (m *MockSessionStore) Create(s *session.Session) error

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) Get

func (m *MockSessionStore) Get(key string) (*session.Session, error)

func (*MockSessionStore) GetCalls

func (m *MockSessionStore) GetCalls() int

GetCalls returns the number of Get calls.

func (*MockSessionStore) GetSalt

func (m *MockSessionStore) GetSalt(name string) ([]byte, error)

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) Update

func (m *MockSessionStore) Update(s *session.Session) 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 (m *MockTextGenerator) GenerateText(_ context.Context, systemPrompt, userPrompt string) (string, error)

func (*MockTextGenerator) LastArgs

func (m *MockTextGenerator) LastArgs() (string, string)

LastArgs returns the last system and user prompts.

type SentMessage

type SentMessage struct {
	Channel string
	Message string
}

SentMessage records a message sent via MockChannelSender.

Jump to

Keyboard shortcuts

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