testing

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertJSON

func AssertJSON(t *testing.T, expected, actual any)

AssertJSON asserts that two JSON values are equal.

func AssertStatusCode

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

AssertStatusCode asserts that the response has the expected status code.

func DecodeJSON

func DecodeJSON(t *testing.T, resp *httptest.ResponseRecorder, v any)

DecodeJSON decodes JSON from a response body.

func RunTableTests

func RunTableTests[I, O any](t *testing.T, tests []TableTest, fn func(I) (O, error))

RunTableTests runs a series of table-driven tests.

Types

type TableTest

type TableTest struct {
	Name     string
	Input    any
	Expected any
	WantErr  bool
}

TableTest represents a table-driven test case.

type TestServer

type TestServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

TestServer wraps httptest.Server with additional utilities.

func NewTestServer

func NewTestServer(t *testing.T, handler http.Handler) *TestServer

NewTestServer creates a new test server.

func (*TestServer) Request

func (ts *TestServer) Request(method, path string, body any) *httptest.ResponseRecorder

Request sends an HTTP request to the test server.

Jump to

Keyboard shortcuts

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