Documentation ¶
Overview ¶
Package mbtest provides a test server that effectively mocks the MessageBird API.
Index ¶
- Variables
- func AssertEndpointCalled(t *testing.T, method, path string)
- func AssertTestdata(t *testing.T, relativePath string, actual []byte)
- func Client(t *testing.T) *messagebird.Client
- func EnableServer(m *testing.M)
- func Testdata(t *testing.T, relativePath string) []byte
- func WillReturn(b []byte, s int)
- func WillReturnAccessKeyError()
- func WillReturnTestdata(t *testing.T, relativePath string, s int)
Constants ¶
This section is empty.
Variables ¶
var Request request
Request contains the lastly received http.Request by the fake server.
Functions ¶
func AssertEndpointCalled ¶
AssertEndpointCalled fails the test if the last request was not made to the provided endpoint (e.g. combination of HTTP method and path).
func AssertTestdata ¶
AssertTestdata gets testdata and asserts it equals actual. We start by slicing off all leading and trailing white space, as defined by Unicode.
func Client ¶
func Client(t *testing.T) *messagebird.Client
Client initializes a new MessageBird client that uses the
func EnableServer ¶
EnableServer starts a fake server, runs the test and closes the server.
func Testdata ¶
Testdata returns a file's bytes based on the path relative to the testdata directory. It fails the test if the testdata file can not be read.
func WillReturn ¶
WillReturn sets the response body (b) and status (s) to be returned by the server for incoming requests. These can be used by tests to assert unmarshalling responses works as intended.
func WillReturnAccessKeyError ¶
func WillReturnAccessKeyError()
WillReturnAccessKeyError sets the response body and status for requests to indicate the request is not allowed due to an incorrect access key.
func WillReturnTestdata ¶
WillReturnTestdata sets the status (s) for the test server to respond with. Additionally it reads the bytes from the relativePath file and returns that for requests. It fails the test if the file can not be read. The path is relative to the testdata directory (the go tool ignores directories named "testdata" in test packages: https://golang.org/cmd/go/#hdr-Test_packages).
Types ¶
This section is empty.