assert

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Contains = assert.Contains

Contains is assert.Contains.

View Source
var NoError = assert.NoError

NoError is assert.NoError.

View Source
var NotEmpty = assert.NotEmpty

NotEmpty is assert.NotEmpty.

View Source
var NotEqual = assert.NotEqual

NotEqual is assert.NotEqual.

View Source
var True = assert.True

True is assert.True.

Functions

func DoHTTP

func DoHTTP(ctx context.Context, h http.Handler, req *http.Request) *http.Response

DoHTTP just perform a plain request and return the response.

func Equal

func Equal(t *testing.T, a, b interface{})

Equal calls assert.Equal.

func ErrorHasMessage

func ErrorHasMessage(t *testing.T, err error, msg string)

ErrorHasMessage asserts err.Error() contains a msg as substring.

func GQLError

func GQLError(t *testing.T, r *simplejson.JSON, errMsg string)

GQLError asserts the given graphql result contains some error message.

func HTTPGet

func HTTPGet(t *testing.T, h http.Handler, path string, params map[string]string, result interface{})

HTTPGet is a convenient method for HTTP. Prefer to use HTTP direclty in new code.

func HTTPGetError

func HTTPGetError(t *testing.T, h http.Handler, code int, path string, params map[string]string)

HTTPGetError is a convenient method for HTTP. Prefer to use HTTP direclty in new code.

func HTTPPost

func HTTPPost(t *testing.T, h http.Handler, path string, params map[string]string, body, result interface{})

HTTPPost is a convenient method for HTTP. Prefer to use HTTP direclty in new code.

func HTTPPostError

func HTTPPostError(t *testing.T, h http.Handler, code int, path string, params map[string]string, body, result interface{})

HTTPPostError is a convenient method for HTTP. Prefer to use HTTP direclty in new code.

func JSONEqual

func JSONEqual(t *testing.T, actual interface{}, expected interface{})

JSONEqual asserts two objects are equal when converted to JSON.

func JSONGet

func JSONGet(t *testing.T, j *simplejson.JSON, path []string) *simplejson.JSON

JSONGet extract values at path, if nil, failed.

func JSONHasStr

func JSONHasStr(t *testing.T, actual interface{}, needle string)

JSONHasStr asserts the object when converted to json, contains given string. Most useful for error assertion.

func JSONText

func JSONText(t *testing.T, actual interface{}, expected string, opts ...JSONOpt)

JSONText asserts the object has given JSON representation.

func NewRequest

func NewRequest(method, path string) *http.Request

NewRequest creates an HTTP request.

func StrEqual

func StrEqual(t *testing.T, a, b string)

StrEqual is a special equal for string.

Types

type FormDataField

type FormDataField struct {
	FieldValue string
	FileName   string
	File       []byte
}

FormDataField specifies a single form data field.

type HTTPParams

type HTTPParams struct {
	Method          string
	Path            string
	Query           map[string]string
	FormValues      map[string]string
	ExpectedCode    int
	Body            bytes.Buffer
	ContentType     string
	Result          interface{}
	CookieJar       *cookiejar.Jar
	Host            string
	FinalPath       *string
	Header          http.Header
	RequestModifier func(*http.Request)
	Ctx             context.Context
}

HTTPParams encode optional params for HTTP method.

func HTTP

func HTTP(path string) HTTPParams

HTTP starts a http request builder.

func (HTTPParams) Delete

func (p HTTPParams) Delete() HTTPParams

Delete changes method to DELETE.

func (HTTPParams) Do

func (p HTTPParams) Do(t *testing.T, h http.Handler)

Do makes a http request and verify some common behavior.

func (HTTPParams) ExpectCode

func (p HTTPParams) ExpectCode(c int) HTTPParams

ExpectCode sets the expected status code.

func (HTTPParams) File

func (p HTTPParams) File(fieldName, fileName string, fileContent []byte) HTTPParams

File attaches a file to the request.

func (HTTPParams) FormData

func (p HTTPParams) FormData(fields map[string]FormDataField) HTTPParams

FormData attaches form data.

func (HTTPParams) JSON

func (p HTTPParams) JSON(j interface{}) HTTPParams

JSON attaches a json body to the request.

func (HTTPParams) ModifyRequest

func (p HTTPParams) ModifyRequest(modifier func(*http.Request)) HTTPParams

ModifyRequest sets request modifier.

func (HTTPParams) Post

func (p HTTPParams) Post() HTTPParams

Post changes method to POST.

func (HTTPParams) Put

func (p HTTPParams) Put() HTTPParams

Put changes method to PUT.

func (HTTPParams) QueryParam

func (p HTTPParams) QueryParam(key, value string) HTTPParams

QueryParam sets a single query param.

func (HTTPParams) QueryParams

func (p HTTPParams) QueryParams(vs map[string]string) HTTPParams

QueryParams sets multipe query params.

func (HTTPParams) RedirectTo

func (p HTTPParams) RedirectTo(s *string) HTTPParams

RedirectTo returns the final path after redirections.

func (HTTPParams) Return

func (p HTTPParams) Return(r interface{}) HTTPParams

Return sets the result.

func (HTTPParams) SetContext

func (p HTTPParams) SetContext(ctx context.Context) HTTPParams

func (HTTPParams) SetFormBody

func (p HTTPParams) SetFormBody(v url.Values) HTTPParams

SetFormBody attach a post form to the request.

func (HTTPParams) SetHeader

func (p HTTPParams) SetHeader(header http.Header) HTTPParams

SetHeader sets header in request.

func (HTTPParams) SetHost

func (p HTTPParams) SetHost(host string) HTTPParams

SetHost set host in request.

func (HTTPParams) Visit

func (p HTTPParams) Visit(path string) HTTPParams

Visit sets the path.

func (HTTPParams) WithCookieJar

func (p HTTPParams) WithCookieJar(jar *cookiejar.Jar) HTTPParams

WithCookieJar access cookies from the jar.

type JSONOpt

type JSONOpt struct {
	IgnoreArrayOrder []string
}

JSONOpt is options for comparing JSON.

type RequestSummary

type RequestSummary struct {
	Header http.Header
	Method string
	URL    string
}

RequestSummary is a summary of http.Request.

func NewRequestSummary

func NewRequestSummary(req *http.Request) RequestSummary

NewRequestSummary creates a RequestSummary.

Jump to

Keyboard shortcuts

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