testutil

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package testutil holds shared test helpers — fixture builders, fake HTTP recorders, and time-freezing utilities — used across unit, attack, compliance, and integration test suites.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertStatus

func AssertStatus(t *testing.T, resp *http.Response, expected int)

AssertStatus checks the HTTP status code.

func AuthRequest

func AuthRequest(t *testing.T, client *http.Client, method, url, accessToken string, body interface{}) *http.Response

AuthRequest makes an authenticated request with a Bearer token.

func ContainerRuntimeAvailable added in v1.0.3

func ContainerRuntimeAvailable() bool

ContainerRuntimeAvailable reports whether a container daemon answered.

It never blocks longer than the detection budget, and the answer is computed once per test binary.

func ContainerRuntimeHost added in v1.0.3

func ContainerRuntimeHost() string

ContainerRuntimeHost returns the DOCKER_HOST of the daemon that answered, or "" when none did. DOCKER_HOST is exported to the process as a side effect of the first call, so testcontainers picks up the same daemon this probed.

func DecodeJSON

func DecodeJSON(t *testing.T, resp *http.Response) map[string]interface{}

DecodeJSON reads and decodes JSON from an http.Response body. Closes the body.

func ExtractCookies

func ExtractCookies(resp *http.Response) map[string]*http.Cookie

ExtractCookies returns a map of cookie name -> cookie from the response.

func LoginUser

func LoginUser(t *testing.T, client *http.Client, baseURL, email, password string) (map[string]interface{}, []*http.Cookie)

LoginUser logs in and returns the response + cookies.

func NoRedirectClient

func NoRedirectClient() *http.Client

NoRedirectClient returns an HTTP client that doesn't follow redirects.

func RefreshTokens

func RefreshTokens(t *testing.T, client *http.Client, baseURL string, cookies []*http.Cookie) (map[string]interface{}, []*http.Cookie)

RefreshTokens refreshes using cookies, returns new response + cookies.

func RegisterUser

func RegisterUser(t *testing.T, client *http.Client, baseURL, email, password string) map[string]interface{}

RegisterUser registers a test user and returns the response.

func RequireContainerRuntime added in v1.0.3

func RequireContainerRuntime(t *testing.T)

RequireContainerRuntime points DOCKER_HOST at a container daemon that answers, or skips the test.

Skipping rather than failing keeps a runtime-free machine distinguishable from a broken repository; the canonical coverage run refuses to start without a runtime (cov_require_runtime), so nothing is silently skipped there. The skip message carries the full probe trace, because "no container runtime" and "the runtime you have is wedged" need different fixes and an operator cannot tell them apart from the outcome alone.

Types

This section is empty.

Jump to

Keyboard shortcuts

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