testutil

package
v0.0.0-...-2bf20ed Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testutil provides common test utilities and helpers for PromptPipe tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertHTTPStatus

func AssertHTTPStatus(t TestingT, expected, actual int, context string)

AssertHTTPStatus checks the HTTP status code and fails the test if it doesn't match.

func AssertJSONResponse

func AssertJSONResponse(t TestingT, rr *httptest.ResponseRecorder, expectedStatus string) map[string]interface{}

AssertJSONResponse decodes JSON response and validates the status field.

func AssertPromptEquals

func AssertPromptEquals(t TestingT, expected, actual models.Prompt, context string)

AssertPromptEquals compares two Prompt structs for equality in tests.

func AssertResponseCount

func AssertResponseCount(t TestingT, store store.Store, expected int, context string)

AssertResponseCount validates the number of responses in store matches expected.

func CreateHTTPRequest

func CreateHTTPRequest(t TestingT, method, url string, body interface{}) *http.Request

CreateHTTPRequest creates an HTTP request with optional JSON body for testing.

func CreateJSONRequest

func CreateJSONRequest(t TestingT, method, url, jsonBody string) *http.Request

CreateJSONRequest creates an HTTP request with a JSON string body for testing. This is a convenience wrapper around CreateHTTPRequest for JSON string bodies.

func MustMarshalJSON

func MustMarshalJSON(t TestingT, v interface{}) []byte

MustMarshalJSON marshals an object to JSON and fails test on error.

func MustUnmarshalJSON

func MustUnmarshalJSON(t TestingT, data []byte, target interface{})

MustUnmarshalJSON unmarshals JSON data into target and fails test on error.

func NewTestServer

func NewTestServer() *api.Server

NewTestServer creates a test API server with in-memory dependencies. This centralizes the test server creation logic used across multiple test files.

func SeedTestData

func SeedTestData(t TestingT, store store.Store)

SeedTestData adds sample data to the store for testing.

Types

type TestingT

type TestingT interface {
	Helper()
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
}

TestingT defines the interface that testing types must implement. This allows both *testing.T and mock implementations to be used.

Jump to

Keyboard shortcuts

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