apitest

package
v0.1.1-0...-d0f436e Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package apitest provides few tools helping you write tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertError

func AssertError(t *testing.T, expect jsonapi.Error, data interface{}, err error) jsonapi.Error

AssertError validates if returned values is specified error value

It checks for following situations:

  • data must be nil
  • err must be jsonapi.Error type
  • expect.EqualTo(err) == true

func Modify

Modify creates a middleware that do some magic before running handler

func Monitor

func Monitor(f func(jsonapi.Request, interface{}, error)) jsonapi.Middleware

Monitor creates a middleware that do some magic after running handler

func NewRequest

func NewRequest(method, target string, data interface{}) *http.Request

NewRequest wraps httptest.NewRequest, use your data (encoded to JSON) as request body

It also sets "Content-Type" to "application/json".

Types

type Test

type Test jsonapi.Handler

Test wraps your handler for test purpose

func (Test) Use

func (t Test) Use(data interface{}) (interface{}, error)

Use executes handler with your data

The request address will be "/" and using POST method.

func (Test) UseRequest

func (t Test) UseRequest(req *http.Request) (interface{}, error)

UseRequest executes handler with specified request

func (Test) With

func (t Test) With(m jsonapi.Middleware) Test

With creates new Test instance by wrapping the handler with the middleware

It executes in REVERSE ORDER:

// order: m2 > m1 > h > m1 > m2
Test(h).With(m1).With(m2).Use(data)

Jump to

Keyboard shortcuts

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