restclienttest

package module
v0.0.0-...-50e3e38 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package restclienttest simplifying test restclient by wrapping `*httptest.Server`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RequestHandlers

type RequestHandlers map[string]TestRequest

RequestHandlers mapped of handler, key is in form or `method:path`.

type TestRequest

type TestRequest struct {
	Name           string
	Test           func(ass *assert.Assertions, r *http.Request) bool
	HeaderTest     func(ass *assert.Assertions, headers http.Header) bool
	FormTest       func(ass *assert.Assertions, forms url.Values) bool
	QueryTest      func(ass *assert.Assertions, queries url.Values) bool
	ResponseFunc   func(ass *assert.Assertions, w http.ResponseWriter)
	ResponseCode   int
	ResponseHeader map[string][]string
	ResponseBody   []byte
}

TestRequest definition how to validate and respond of request. All `*Test` fields will be evaluated in sequence when not nil. `Responsefunc` field will be prioritized as over `ResponseCode`, `ResponseHeader`, and `ResponseBody`.

type TestServer

type TestServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

TestServer contains dependencies needed for testing.

func NewTestServer

func NewTestServer(t *testing.T) *TestServer

NewTestServer create a new `*TestServer` with provided `*testing.T`.

func (*TestServer) AppendHandler

func (ts *TestServer) AppendHandler(method, path string, testRequest TestRequest)

AppendHandler append request based on `method` and `path` that will be handled with `testRequest`.

func (*TestServer) Close

func (ts *TestServer) Close()

Close close the server.

Jump to

Keyboard shortcuts

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