testutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testutil provides test utilities, fixtures, and helpers for SCRIBE tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertBodyContains

func AssertBodyContains(t *testing.T, resp *httptest.ResponseRecorder, substring string)

AssertBodyContains checks that the response body contains a string.

func AssertContentType

func AssertContentType(t *testing.T, resp *httptest.ResponseRecorder, expected string)

AssertContentType checks that the response has the expected content type.

func AssertError

func AssertError(t *testing.T, err error)

AssertError checks that an error is not nil.

func AssertJSONArrayResponse

func AssertJSONArrayResponse(t *testing.T, resp *httptest.ResponseRecorder) []any

AssertJSONArrayResponse checks that the response is a valid JSON array.

func AssertJSONField

func AssertJSONField(t *testing.T, data map[string]any, field string, expected any)

AssertJSONField checks that a JSON response has a field with expected value.

func AssertJSONResponse

func AssertJSONResponse(t *testing.T, resp *httptest.ResponseRecorder) map[string]any

AssertJSONResponse checks that the response is valid JSON.

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError checks that an error is nil.

func AssertStatusCode

func AssertStatusCode(t *testing.T, resp *httptest.ResponseRecorder, expected int)

AssertStatusCode checks that the response has the expected status code.

func CleanupTestDB

func CleanupTestDB(t *testing.T, db *sqlite.Database)

CleanupTestDB closes and cleans up the test database.

func GetLogCount

func GetLogCount(t *testing.T, db *sqlite.Database) int

GetLogCount returns the number of logs in the database.

func MakeJSONRequest

func MakeJSONRequest(t *testing.T, method, url string, data any) *http.Request

MakeJSONRequest creates an HTTP request with JSON body.

func MakeRequest

func MakeRequest(method, url string, body io.Reader) *http.Request

MakeRequest creates an HTTP request for testing.

func NewTestLog

func NewTestLog() *entities.Log

NewTestLog creates a test log with sensible defaults.

func NewTestLogBatch

func NewTestLogBatch(count int) []*entities.Log

NewTestLogBatch creates multiple test logs.

func NewTestLogMinimal

func NewTestLogMinimal() *entities.Log

NewTestLogMinimal creates a minimal valid log (only required fields).

func NewTestLogWithBody

func NewTestLogWithBody(body map[string]any) *entities.Log

NewTestLogWithBody creates a test log with specific body.

func NewTestLogWithOptions

func NewTestLogWithOptions(opts TestLogOptions) *entities.Log

NewTestLogWithOptions creates a test log with custom options.

func NewTestLogWithSeverity

func NewTestLogWithSeverity(severity valueobjects.Severity) *entities.Log

NewTestLogWithSeverity creates a test log with specific severity.

func NewTestLogWithTitle

func NewTestLogWithTitle(title string) *entities.Log

NewTestLogWithTitle creates a test log with specific title.

func SetupTestDB

func SetupTestDB(t *testing.T) *sqlite.Database

SetupTestDB creates an in-memory SQLite database for testing.

func TruncateLogs

func TruncateLogs(t *testing.T, db *sqlite.Database)

TruncateLogs removes all logs from the test database.

Types

type TestLogOptions

type TestLogOptions struct {
	Severity    valueobjects.Severity
	Title       string
	Description string
	Source      string
	Color       valueobjects.Color
	Body        map[string]any
}

TestLogOptions allows customization of test logs.

Jump to

Keyboard shortcuts

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