testutil

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Resolve

func Resolve[T any](h *TestHost) T

Resolve retrieves a typed dependency from the container.

Types

type FakeLogger

type FakeLogger struct {
	Entries []string
}

FakeLogger collects log entries for test assertions.

func NewFakeLogger

func NewFakeLogger() *FakeLogger

NewFakeLogger creates a FakeLogger.

func (*FakeLogger) AssertLogged

func (l *FakeLogger) AssertLogged(t *testing.T, msg string)

AssertLogged fails the test if msg was not logged.

type TestContext

type TestContext struct {
	Ctx  context.Context
	Vars map[string]any
}

TestContext holds a context and variable map for test use.

func NewTestContext

func NewTestContext() *TestContext

NewTestContext creates a TestContext with a background context.

type TestHost

type TestHost struct {
	Container *di.Container
	Server    *httptest.Server
	Client    *http.Client
	// contains filtered or unexported fields
}

TestHost provides a DI container and test HTTP server.

func NewTestHost

func NewTestHost(setup func(b *di.Builder, app *srv.Server)) *TestHost

NewTestHost creates a TestHost with a DI container and test server.

func (*TestHost) Close

func (h *TestHost) Close()

Close shuts down the test server and runs cleanup functions.

func (*TestHost) Get

func (h *TestHost) Get(path string) *TestResponse

Get issues a GET request and returns a TestResponse.

func (*TestHost) Post

func (h *TestHost) Post(path string, contentType string, body io.Reader) *TestResponse

Post issues a POST request and returns a TestResponse.

func (*TestHost) URL

func (h *TestHost) URL(path string) string

URL returns the full URL for the given path.

type TestResponse

type TestResponse struct {
	StatusCode int
	Body       []byte
	Headers    http.Header
	Error      error
}

TestResponse holds an HTTP response for test assertions.

func (*TestResponse) Decode

func (r *TestResponse) Decode(v any) error

Decode unmarshals the response body into v.

func (*TestResponse) String

func (r *TestResponse) String() string

String returns the response body as a string.

Jump to

Keyboard shortcuts

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