assertive

package module
v0.0.0-...-8e86251 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: MIT Imports: 8 Imported by: 0

README

Assertive

A go package for making Fluent Assertions on web APIs.

Example

	assertive.NewAPI("http://example.com").
		Get("/api/v1/Some/Path").
		WithHeader("Authorization", suite.JwtToken).
		Should(suite.T()).
		ReturnStatus200().
		Assert()

DISCLAIMER

This is still very much a work in progress. Expect things to change with every commit until something stable is released.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API Struct

func NewAPI

func NewAPI(host string) *API

NewAPI sets up an api url

func (*API) DoRequest

func (api *API) DoRequest() (*http.Response, error)

DoRequest makes the request to the API

func (*API) Get

func (api *API) Get(path string) *API

Get creates a GET request

func (*API) PostJSON

func (api *API) PostJSON(path string, json []byte) *API

PostJSON creates a JSON POST request

func (*API) Should

func (api *API) Should(testSuite *testing.T) *Assertion

Should binds test context to api

func (*API) WithHeader

func (api *API) WithHeader(key, value string) *API

WithHeader adds a header to the request

type Assert

type Assert func(*http.Response) error

Assert the required interface for assertion functions

func BodyContentMatches

func BodyContentMatches(content string) Assert

BodyContentMatches Checks JSONCotent matches expected content

func JSONSchema

func JSONSchema(schema string) Assert

JSONSchema validates the response body against a schema

func StatusEqual

func StatusEqual(code int) Assert

StatusEqual checks the response status equals the expected code

func TypeEqual

func TypeEqual(kind string) Assert

TypeEqual checks the response type equals the expected type

type Assertion

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

Assertion struct to wrap asserions

func (*Assertion) Assert

func (assertion *Assertion) Assert() error

Assert runs the assertions on the request

func (*Assertion) ReturnStatus

func (assertion *Assertion) ReturnStatus(code int) *Assertion

ReturnStatus {code} checks the response is the expected code.

func (*Assertion) ReturnStatus200

func (assertion *Assertion) ReturnStatus200() *Assertion

ReturnStatus200 checks the response was 200

func (*Assertion) ReturnStatus201

func (assertion *Assertion) ReturnStatus201() *Assertion

ReturnStatus201 checks the response was 200

func (*Assertion) ReturnStatus400

func (assertion *Assertion) ReturnStatus400() *Assertion

ReturnStatus400 checks the response was 400

func (*Assertion) ReturnsBody

func (assertion *Assertion) ReturnsBody(content string) *Assertion

ReturnsBody chexks the returned body matches the expected body

func (*Assertion) ReturnsContentTypeJSON

func (assertion *Assertion) ReturnsContentTypeJSON() *Assertion

ReturnsContentTypeJSON checks the returned content type was JSON

func (*Assertion) ReturnsSchemaMatching

func (assertion *Assertion) ReturnsSchemaMatching(schema string) *Assertion

ReturnsSchemaMatching asserts the schema matches the one provided

Jump to

Keyboard shortcuts

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