testutil

package
v0.0.0-...-01b663c Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testutil provides helpers for unit and integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertJSONEqual

func AssertJSONEqual(t *testing.T, expected, actual string)

AssertJSONEqual unmarshals and compares two JSON strings.

func LoadTestAudio

func LoadTestAudio(t *testing.T, filename string) []byte

LoadTestAudio loads an audio sample from the repository's test data directory.

func NewMockLLMBackend

func NewMockLLMBackend(name string, response *llm.LLMResponse) llm.LLMBackend

NewMockLLMBackend creates a mock LLM backend with a fixed response.

func NewTestLogger

func NewTestLogger() *logrus.Logger

NewTestLogger creates a logger suitable for tests.

func RepoRoot

func RepoRoot(t *testing.T) string

RepoRoot returns the repository root directory.

Types

type MockLLMBackend

type MockLLMBackend struct {
	Name       string
	Response   *llm.LLMResponse
	ProcessErr error
	HealthErr  error
}

MockLLMBackend is a configurable in-memory LLM backend for unit tests.

func (*MockLLMBackend) GetCapabilities

func (b *MockLLMBackend) GetCapabilities() llm.Capabilities

func (*MockLLMBackend) GetName

func (b *MockLLMBackend) GetName() string

func (*MockLLMBackend) HealthCheck

func (b *MockLLMBackend) HealthCheck(ctx context.Context) error

func (*MockLLMBackend) Process

func (b *MockLLMBackend) Process(ctx context.Context, req *llm.LLMRequest) (*llm.LLMResponse, error)

type TestServer

type TestServer struct {
	Server *httptest.Server
	Client *http.Client
	Config *config.Config
	Mux    *http.ServeMux
}

TestServer is a lightweight integration test harness based on httptest.Server.

It intentionally does not depend on application packages to avoid import cycles in unit tests. Tests can register handlers on Mux and issue requests via DoRequest.

func NewTestServer

func NewTestServer(t *testing.T) *TestServer

NewTestServer creates a new TestServer backed by an http.ServeMux.

func (*TestServer) Cleanup

func (ts *TestServer) Cleanup()

Cleanup closes the underlying server. It is safe to call multiple times.

func (*TestServer) DoRequest

func (ts *TestServer) DoRequest(method, path string, body any) (*http.Response, error)

DoRequest issues an HTTP request against the test server.

Directories

Path Synopsis
Package integrationtest provides Lingualink-specific integration test helpers.
Package integrationtest provides Lingualink-specific integration test helpers.

Jump to

Keyboard shortcuts

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