Documentation
¶
Overview ¶
Package testutil provides shared test utilities for the httpc library.
Index ¶
- Constants
- func AssertCookieValid(t *testing.T, cookie *http.Cookie, name, value string)
- func AssertError(t *testing.T, err error, msgAndArgs ...interface{})
- func AssertNoError(t *testing.T, err error, msgAndArgs ...interface{})
- func AssertStatusCode(t *testing.T, got, expected int)
- func NewJSONTestServer(t *testing.T, response interface{}, statusCode int) *httptest.Server
- func NewSlowTestServer(delay time.Duration) *httptest.Server
- func NewTestServer(handler http.HandlerFunc) *httptest.Server
- func NonRetryableStatusCodes() []int
- func RetryableStatusCodes() []int
- type StatusCodeTest
Constants ¶
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
const ( DefaultNumGoroutines = 50 DefaultOpsPerGoroutine = 20 HighConcurrencyGoroutines = 100 )
Concurrency test parameters
const ( SmallResponseBody = 1024 // 1KB MediumResponseBody = 1024 * 100 // 100KB LargeResponseBody = 1024 * 1024 // 1MB )
Response sizes for tests
const ( SmallFileSize = 10240 // 10KB MediumFileSize = 1024 * 100 // 100KB LargeFileSize = 1024 * 1024 // 1MB )
File size constants
Variables ¶
This section is empty.
Functions ¶
func AssertCookieValid ¶
AssertCookieValid validates a cookie meets basic requirements.
func AssertError ¶
AssertError asserts that an error occurred.
func AssertNoError ¶
AssertNoError asserts that no error occurred.
func AssertStatusCode ¶
AssertStatusCode asserts the HTTP status code matches expected.
func NewJSONTestServer ¶
NewJSONTestServer creates a server that responds with JSON.
func NewSlowTestServer ¶
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 ¶
StatusCodeTest represents a test case for status code handling.
func AllStatusCodeTests ¶
func AllStatusCodeTests() []StatusCodeTest
AllStatusCodeTests returns all status code test cases.