servertest

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package servertest provides methods and types to test server.Handler implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	Unimplemented = errors.New("Unimplemented")
)

Functions

func Run

func Run(t *testing.T, tests []Test, handler server.Handler)

Run executes all the given tests on the given Handler.

The same handler is used for all tests. The tests are executed in the given order. The requests received by the handler are as if the handler had been registered for the pattern "/a/test".

Each test is executed inside testing.T.Run, hence calling t.Fatal in the checker abort only the current test.

func RunFunc

func RunFunc(t *testing.T, tests []Test, handler server.HandleFunction)

RunFunc is a convenient wrapper around Run for HandleFunction.

Types

type Checker

type Checker = func(t *testing.T, response *http.Response, req *http.Request)

Checker is a signature for functions that check the result of a request on a Handler.

func CheckerJSON

func CheckerJSON(expectCode int, expectBody interface{}) Checker

CheckerJSON returns a Checker to check responses whose body is a JSON object.

The returned function checks that the statuc code and the body are as expected.

func CheckerStatus

func CheckerStatus(expectCode int) Checker

CheckerJSONString returns a Checker to check status code.

The returned function checks that the statuc code is as expected. The body is not checked.

type ClientStore

type ClientStore struct {
	Codecs []securecookie.Codec
}

ClientStore is a sessions.Store that store sessions in client requests.

func NewClientStore

func NewClientStore(keys ...[]byte) *ClientStore

func (*ClientStore) Get

func (self *ClientStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get is currently not implemented.

func (*ClientStore) New

func (self *ClientStore) New(r *http.Request, name string) (*sessions.Session, error)

func (*ClientStore) Save

func (self *ClientStore) Save(r *http.Request, w http.ResponseWriter,
	session *sessions.Session) error

type Request

type Request struct {
	Method string
	Target string
	Body   string
	UserId *uint32
}

Request provides information to create an http.Request.

Its zero value is valid and produces the request "GET /a/test". See Make() for details.

func (*Request) Make

func (self *Request) Make() (req *http.Request, err error)

Make generates an http.Request.

Default value for Method is "GET". Default value for Target is "/a/test". If UserId is not nil then a valid session for that user is added to the request.

type Test

type Test struct {
	Name    string
	Update  func(t *testing.T)
	Request Request
	Checker Checker
}

Test represents a test to be executed by Run().

Update is called before the test, if not nil.

Jump to

Keyboard shortcuts

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