testutil

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHTTPStubs = []HTTPStub{
	{
		"GET", "/get", map[string]string{"param1": "a", "param2": "日本語"},
		nil, nil,
		201, nil, nil,
		HTTPStubOptions{},
	},
	{
		"POST", "/post", nil,
		map[string][]string{"Test-Req-Header": {"test1", "test2"}, "Test-Req-Header2": {"foo; bar"}}, &shortHTTPBody1a,
		200, map[string][]string{"Test-Res-Header": {"test1", "test2"}, "Test-Res-Header2": {"foo; bar"}}, &shortHTTPBody1b,
		HTTPStubOptions{},
	},
	{
		"POST", "/post/large", nil,
		nil, &largeHTTPBody1a,
		200, nil, &largeHTTPBody1b,
		HTTPStubOptions{ChunkResponseBodyPer: 1024},
	},
}
View Source
var DefaultHTTPTestCases = []HTTPTestCase{
	{
		"GET", "/get?param1=a&param2=日本語",
		nil, nil,
		201, nil, nil,
		HTTPTestCaseOptions{},
	},
	{
		"POST", "/post",
		map[string][]string{"Test-Req-Header": {"test1", "test2"}, "Test-Req-Header2": {"foo; bar"}}, &shortHTTPBody1a,
		200, map[string][]string{"Test-Res-Header": {"test1", "test2"}, "Test-Res-Header2": {"foo; bar"}}, &shortHTTPBody1b,
		HTTPTestCaseOptions{},
	},
	{
		"POST", "/post/large",
		nil, &largeHTTPBody1a,
		200, nil, &largeHTTPBody1b,
		HTTPTestCaseOptions{},
	},
}

Functions

func Context

func Context(t *testing.T) context.Context

func NewHTTPStubServer

func NewHTTPStubServer(t *testing.T, patterns ...HTTPStub) (*httptest.Server, int)

func RandomBytes

func RandomBytes(len int) []byte

Types

type HTTPStub

type HTTPStub struct {
	Method         string
	Path           string
	QueryParams    map[string]string
	RequestHeaders map[string][]string
	RequestBody    *[]byte

	StatusCode      int
	ResponseHeaders map[string][]string
	ResponseBody    *[]byte

	Options HTTPStubOptions
}

func (*HTTPStub) String

func (p *HTTPStub) String() string

type HTTPStubOptions

type HTTPStubOptions struct {
	// If not zero, chunk response body per this bytes
	ChunkResponseBodyPer int
}

HTTPStubOptions is an options that usually not need to set

type HTTPTestCase

type HTTPTestCase struct {
	Method         string
	Path           string
	RequestHeaders map[string][]string
	RequestBody    *[]byte

	ExpectedStatus  int
	ExpectedHeaders map[string][]string
	ExpectedBody    *[]byte

	Options HTTPTestCaseOptions
}

func (*HTTPTestCase) AssertResponse

func (c *HTTPTestCase) AssertResponse(t *testing.T, res *http.Response)

func (*HTTPTestCase) Do

func (c *HTTPTestCase) Do(t *testing.T, httpClient *http.Client, port int)

func (*HTTPTestCase) String

func (c *HTTPTestCase) String() string

func (*HTTPTestCase) ToRequest

func (c *HTTPTestCase) ToRequest(t *testing.T, port int) *http.Request

type HTTPTestCaseOptions

type HTTPTestCaseOptions struct{}

HTTPTestCaseOptions is an options that usually not need to set

Jump to

Keyboard shortcuts

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