testkit

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute[Body any](t testing.TB, tc *TestCase) *netkit.Response[netkit.InternalBody[Body]]

Execute performs HTTP request to the target server The request URL must contain remote server address Parse the response to internal structure

func TestGin

func TestGin[Body any](t testing.TB, tc *TestCase, engine *gin.Engine) *netkit.Response[netkit.InternalBody[Body]]

TestGin executes test case with gin engine Parse the response to internal structure

Types

type Assertion

type Assertion struct {
	StatusCode int
	Verdict    string
}

type ResponseRecorder

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

ResponseRecorder wraps recorder to support CloseNotify

func NewResponseRecorder

func NewResponseRecorder() *ResponseRecorder

NewResponseRecorder returns a new instance

func (*ResponseRecorder) CloseNotify

func (r *ResponseRecorder) CloseNotify() <-chan bool

CloseNotify waits for closed message This is required method for go-gin framework

type TestCase

type TestCase struct {
	Name      string
	Request   *http.Request
	Assertion *Assertion
}

TestCase is a test case for HTTP request

func NewTestCase

func NewTestCase(name string, method string, path string, expectedStatus int, expectedVerdict string) *TestCase

NewTestCase returns a new HTTP test case. Panic if error

func NewUploadTestCase

func NewUploadTestCase(name string, path string, reader io.Reader, fields map[string]string, expectedStatus int, expectedVerdict string) *TestCase

NewUploadTestCase creates new upload test case

func (*TestCase) Execute

func (tc *TestCase) Execute(t testing.TB) *http.Response

Execute performs HTTP request to the target server The request URL must contain remote server address

func (*TestCase) WithBody

func (tc *TestCase) WithBody(body interface{}) *TestCase

WithBody converts input to JSON and sets to request body

func (*TestCase) WithHeader

func (tc *TestCase) WithHeader(k, v string) *TestCase

WithHeader adds header

func (*TestCase) WithQuery

func (tc *TestCase) WithQuery(queries interface{}) *TestCase

WithQuery adds queries parameter. Support map and struct

func (*TestCase) WithToken

func (tc *TestCase) WithToken(token string) *TestCase

WithToken sets bearer token

Jump to

Keyboard shortcuts

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