mbtest

package
v5.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package mbtest provides a test server that effectively mocks the MessageBird API.

Index

Constants

This section is empty.

Variables

View Source
var Request request

Request contains the lastly received http.Request by the fake server.

Functions

func AssertEndpointCalled

func AssertEndpointCalled(t *testing.T, method, path string)

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

func AssertTestdata(t *testing.T, relativePath string, actual []byte)

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

func EnableServer(m *testing.M)

EnableServer starts a fake server, runs the test and closes the server.

func Testdata

func Testdata(t *testing.T, relativePath string) []byte

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

func WillReturn(b []byte, s int)

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

func WillReturnTestdata(t *testing.T, relativePath string, s int)

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.

Jump to

Keyboard shortcuts

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