miniteltest

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateHTTPResponse

func GenerateHTTPResponse(t *testing.T, id string, c int) *http.Response

GenerateHTTPResponse purposes with the given Result and StatusCode. This is here to reduce boilerplate construction in the common case.

Types

type TestServer

type TestServer struct {
	*httptest.Server

	sync.Mutex
	// contains filtered or unexported fields
}

TestServer implements the basic interactions with Minitel for the purposes of testing. Use ExpectNotify and ExpectFollowup to register http.Responses with the handler for controlled testing of responses. Or call those methods with nil to get a generic response. The ExpectDone() method can be used to ensure that all expectations have happened within the provided timeout, which is useful for when the client is used async.

func NewServer

func NewServer() *TestServer

NewServer returns a prepared TestServer which should be used like a httptest.Server

ts := NewServer()
defer ts.Close()

func (*TestServer) ExpectDone

func (ts *TestServer) ExpectDone(max time.Duration) bool

ExpectDone waits up to max duration for all notify and followup responses to be sent. Returns true if they have been sent. If they haven't been sent after the max duration then return false.

func (*TestServer) ExpectFollowup

func (ts *TestServer) ExpectFollowup(r ...*http.Response)

ExpectFollowup and send the supplied responses. If the responses are nil an empty response with a random ID and a http.StatusCreated is sent

func (*TestServer) ExpectNotify

func (ts *TestServer) ExpectNotify(r ...*http.Response)

ExpectNotify and send the supplied responses. If the responses are nil an empty response with a random ID and a http.StatusCreated is sent

Jump to

Keyboard shortcuts

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