httpexpect

package
v0.0.0-...-f7b84e4 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

A helper utilities for testing `http.HandlerFunc`

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expectation

type Expectation struct {
	// contains filtered or unexported fields
}

func Delete

func Delete(t TestingT, handler http.HandlerFunc) *Expectation

func Get

func Get(t TestingT, handler http.HandlerFunc) *Expectation
Example
stubHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	_, _ = w.Write([]byte(`{"bool":  true, "number": 1337, "string":  "str", "object": {}, "array": []}`))
})

t := &testing.T{}

Get(t, stubHandler).Status(http.StatusOK).JSONObject().Bool("bool").True()
Output:

func Head(t TestingT, handler http.HandlerFunc) *Expectation

func Patch

func Patch(t TestingT, handler http.HandlerFunc) *Expectation

func Post

func Post(t TestingT, handler http.HandlerFunc) *Expectation

func Put

func Put(t TestingT, handler http.HandlerFunc) *Expectation

func (*Expectation) Header

func (e *Expectation) Header(key string) *JSONArray

func (*Expectation) JSONArray

func (e *Expectation) JSONArray() *JSONArray

func (*Expectation) JSONObject

func (e *Expectation) JSONObject() *JSONObject

func (*Expectation) NoContent

func (e *Expectation) NoContent() *Expectation

func (*Expectation) Require

func (e *Expectation) Require() *Expectation

func (*Expectation) Status

func (e *Expectation) Status(status int) *Expectation

func (*Expectation) WithContext

func (e *Expectation) WithContext(ctx context.Context) *Expectation

func (*Expectation) WithExtraHeader

func (e *Expectation) WithExtraHeader(key, value string) *Expectation

func (*Expectation) WithJSON

func (e *Expectation) WithJSON(data any) *Expectation

func (*Expectation) WithMiddlewares

func (e *Expectation) WithMiddlewares(middlewares ...func(http.Handler) http.Handler) *Expectation

func (*Expectation) WithPlainText

func (e *Expectation) WithPlainText(data []byte) *Expectation

func (*Expectation) WithQuery

func (e *Expectation) WithQuery(query string) *Expectation

func (*Expectation) WithoutBody

func (e *Expectation) WithoutBody() *Expectation

type JSONArray

type JSONArray struct {
	// contains filtered or unexported fields
}

func (*JSONArray) Array

func (a *JSONArray) Array(idx int) *JSONArray

func (*JSONArray) Bool

func (a *JSONArray) Bool(idx int) *JSONBool

func (*JSONArray) Len

func (a *JSONArray) Len() *JSONNumber

func (*JSONArray) Null

func (a *JSONArray) Null(idx int)

func (*JSONArray) Number

func (a *JSONArray) Number(idx int) *JSONNumber

func (*JSONArray) Object

func (a *JSONArray) Object(idx int) *JSONObject

func (*JSONArray) String

func (a *JSONArray) String(idx int) *JSONString

type JSONArrayType

type JSONArrayType = []interface{}

type JSONBool

type JSONBool struct {
	// contains filtered or unexported fields
}

func (*JSONBool) Equal

func (b *JSONBool) Equal(value bool)

func (*JSONBool) False

func (b *JSONBool) False()

func (*JSONBool) True

func (b *JSONBool) True()

func (*JSONBool) Value

func (b *JSONBool) Value() bool

type JSONNumber

type JSONNumber struct {
	// contains filtered or unexported fields
}

func (*JSONNumber) Equal

func (n *JSONNumber) Equal(value float64)

func (*JSONNumber) EqualDelta

func (n *JSONNumber) EqualDelta(value, delta float64)

func (*JSONNumber) Value

func (n *JSONNumber) Value() float64

type JSONObject

type JSONObject struct {
	// contains filtered or unexported fields
}

func (*JSONObject) Array

func (o *JSONObject) Array(key string) *JSONArray

func (*JSONObject) Bool

func (o *JSONObject) Bool(key string) *JSONBool

func (*JSONObject) HasKey

func (o *JSONObject) HasKey(key string) *JSONObject

func (*JSONObject) Null

func (o *JSONObject) Null(key string)

func (*JSONObject) Number

func (o *JSONObject) Number(key string) *JSONNumber

func (*JSONObject) Object

func (o *JSONObject) Object(key string) *JSONObject

func (*JSONObject) String

func (o *JSONObject) String(key string) *JSONString

type JSONObjectType

type JSONObjectType = map[string]interface{}

type JSONString

type JSONString struct {
	// contains filtered or unexported fields
}

func (*JSONString) Equal

func (s *JSONString) Equal(value string)

func (*JSONString) HasPrefix

func (s *JSONString) HasPrefix(prefix string)

func (*JSONString) HasSuffix

func (s *JSONString) HasSuffix(suffix string)

func (*JSONString) Len

func (s *JSONString) Len() *JSONNumber

func (*JSONString) Value

func (s *JSONString) Value() string

type TestingT

type TestingT interface {
	Errorf(format string, args ...interface{})
	FailNow()
	Helper()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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