mbtest

package
v0.0.0-...-421306c Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: BSD-2-Clause Imports: 15 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 AssertTestdataJson

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

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

func EnableServer(m *testing.M)

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

func HTTPTestTransport

func HTTPTestTransport(handler http.Handler) (*http.Transport, func())

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

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 WillReturnOnlyStatus

func WillReturnOnlyStatus(s int)

WillReturnOnlyStatus sets the response status (s) to be returned by the server for incoming requests.

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

type ClientMock

type ClientMock struct {
	mock.Mock
}

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

Jump to

Keyboard shortcuts

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