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 AssertTestdataJson(t *testing.T, relativePath string, actual []byte)
- func Client(t *testing.T) *messagebird.DefaultClient
- func EnableServer(m *testing.M)
- func HTTPTestTransport(handler http.Handler) (*http.Transport, func())
- func MockClient() messagebird.Client
- func Testdata(t *testing.T, relativePath string) []byte
- func WillReturn(b []byte, s int)
- func WillReturnAccessKeyError()
- func WillReturnOnlyStatus(s int)
- func WillReturnTestdata(t *testing.T, relativePath string, s int)
- type ClientMock
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 AssertTestdataJson ¶
AssertTestdataJson gets testdata as json and asserts it equals actual.
func Client ¶
func Client(t *testing.T) *messagebird.DefaultClient
Client initializes a new MessageBird client that uses the
func EnableServer ¶
EnableServer starts a fake server, runs the test and closes the server.
func HTTPTestTransport ¶
HTTPTestTransport builds http transport that allows to pass custom http handler to http server
func MockClient ¶
func MockClient() messagebird.Client
MockClient initializes a new mock of MessageBird client
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 WillReturnOnlyStatus ¶
func WillReturnOnlyStatus(s int)
WillReturnOnlyStatus sets the response status (s) to be returned by the server for incoming requests.
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 ¶
type ClientMock ¶
func (*ClientMock) DisableFeatures ¶
func (c *ClientMock) DisableFeatures(feature messagebird.Feature)
func (*ClientMock) EnableFeatures ¶
func (c *ClientMock) EnableFeatures(feature messagebird.Feature)
func (*ClientMock) IsFeatureEnabled ¶
func (c *ClientMock) IsFeatureEnabled(feature messagebird.Feature) bool
func (*ClientMock) Request ¶
func (c *ClientMock) Request(v interface{}, method, path string, data interface{}) error