testutil

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil provides shared test utilities for the httpc library.

Index

Constants

View Source
const (
	TestTimeoutShort      = 100 * time.Millisecond
	TestTimeoutMedium     = 500 * time.Millisecond
	TestTimeoutLong       = 2 * time.Second
	TestRetryDelay        = 10 * time.Millisecond
	TestBackoffFactor     = 2.0
	TestCacheTTL          = 5 * time.Minute
	TestIdleConnTimeout   = 30 * time.Second
	TestSlowServerDelay   = 200 * time.Millisecond
	TestMiddlewareTimeout = 10 * time.Millisecond
)

Time durations for tests

View Source
const (
	DefaultNumGoroutines      = 50
	DefaultOpsPerGoroutine    = 20
	HighConcurrencyGoroutines = 100
)

Concurrency test parameters

View Source
const (
	SmallResponseBody  = 1024        // 1KB
	MediumResponseBody = 1024 * 100  // 100KB
	LargeResponseBody  = 1024 * 1024 // 1MB
)

Response sizes for tests

View Source
const (
	SmallFileSize  = 10240       // 10KB
	MediumFileSize = 1024 * 100  // 100KB
	LargeFileSize  = 1024 * 1024 // 1MB
)

File size constants

Variables

This section is empty.

Functions

func AssertCookieValid

func AssertCookieValid(t *testing.T, cookie *http.Cookie, name, value string)

AssertCookieValid validates a cookie meets basic requirements.

func AssertError

func AssertError(t *testing.T, err error, msgAndArgs ...interface{})

AssertError asserts that an error occurred.

func AssertNoError

func AssertNoError(t *testing.T, err error, msgAndArgs ...interface{})

AssertNoError asserts that no error occurred.

func AssertStatusCode

func AssertStatusCode(t *testing.T, got, expected int)

AssertStatusCode asserts the HTTP status code matches expected.

func NewJSONTestServer

func NewJSONTestServer(t *testing.T, response interface{}, statusCode int) *httptest.Server

NewJSONTestServer creates a server that responds with JSON.

func NewSlowTestServer

func NewSlowTestServer(delay time.Duration) *httptest.Server

NewSlowTestServer creates a server that delays its response.

func NewTestServer

func NewTestServer(handler http.HandlerFunc) *httptest.Server

NewTestServer creates an httptest.Server with common configuration. The server is returned for convenience.

func NonRetryableStatusCodes

func NonRetryableStatusCodes() []int

NonRetryableStatusCodes returns status codes that should NOT trigger retries.

func RetryableStatusCodes

func RetryableStatusCodes() []int

RetryableStatusCodes returns status codes that should trigger retries.

Types

type StatusCodeTest

type StatusCodeTest struct {
	Name       string
	StatusCode int
	Retryable  bool
}

StatusCodeTest represents a test case for status code handling.

func AllStatusCodeTests

func AllStatusCodeTests() []StatusCodeTest

AllStatusCodeTests returns all status code test cases.

Jump to

Keyboard shortcuts

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