testkit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package testkit provides functionalities for testing the APIs.

Index

Constants

This section is empty.

Variables

View Source
var NoMockCredentialsProvider = MockCredentialsProvider()

NoMockCredentialsProvider is no mock CredentialsProvider.

Functions

This section is empty.

Types

type CredentialsProvider

type CredentialsProvider struct {
	mock.Mock
}

CredentialsProvider is a CredentialsProvider.

func (*CredentialsProvider) Password

func (c *CredentialsProvider) Password() string

Password satisfies CredentialsProvider.

func (*CredentialsProvider) Username

func (c *CredentialsProvider) Username() string

Username satisfies CredentialsProvider.

type CredentialsProviderMocker

type CredentialsProviderMocker func(tb testing.TB) *CredentialsProvider

CredentialsProviderMocker is CredentialsProvider mocker.

func MockCredentialsProvider

func MockCredentialsProvider(mocks ...func(p *CredentialsProvider)) CredentialsProviderMocker

MockCredentialsProvider creates CredentialsProvider mock with cleanup to ensure all the expectations are met.

type Expectation added in v0.2.0

type Expectation = httpmock.Expectation

Expectation is an alias of httpmock.Expectation.

type Server

type Server struct {
	*httpmock.Server
	// contains filtered or unexported fields
}

Server is a wrapped httpmock.Server to provide more functionalities for testing MoneyLover APIs.

func NewServer

func NewServer(t TestingT) *Server

NewServer creates a new Server.

func (*Server) AccessToken

func (s *Server) AccessToken() auth.Token

AccessToken returns the accessToken.

func (*Server) Expect

func (s *Server) Expect(method string, requestURI interface{}) Expectation

Expect expects a request with Bearer Authorization.

Server.Expect(http.MethodGet, "/path").

func (*Server) ExpectDelete

func (s *Server) ExpectDelete(requestURI interface{}) Expectation

ExpectDelete expects a request with Bearer Authorization.

Server.ExpectDelete("/path")

func (*Server) ExpectGet

func (s *Server) ExpectGet(requestURI interface{}) Expectation

ExpectGet expects a request with Bearer Authorization.

Server.ExpectGet("/path")

func (*Server) ExpectHead

func (s *Server) ExpectHead(requestURI interface{}) Expectation

ExpectHead expects a request with Bearer Authorization.

Server.ExpectHead("/path")

func (*Server) ExpectPatch

func (s *Server) ExpectPatch(requestURI interface{}) Expectation

ExpectPatch expects a request with Bearer Authorization.

Server.ExpectPatch("/path")

func (*Server) ExpectPost

func (s *Server) ExpectPost(requestURI interface{}) Expectation

ExpectPost expects a request with Bearer Authorization.

Server.ExpectPost("/path")

func (*Server) ExpectPut

func (s *Server) ExpectPut(requestURI interface{}) Expectation

ExpectPut expects a request with Bearer Authorization.

Server.ExpectPut("/path")

func (*Server) RefreshToken

func (s *Server) RefreshToken() auth.Token

RefreshToken returns the refreshToken.

func (*Server) RequestToken

func (s *Server) RequestToken() auth.Token

RequestToken returns the requestToken.

func (*Server) WithAccessToken

func (s *Server) WithAccessToken(token string) *Server

WithAccessToken sets the accessToken.

func (*Server) WithPlanner added in v0.2.0

func (s *Server) WithPlanner(p planner.Planner) *Server

WithPlanner sets planner.

func (*Server) WithRefreshToken

func (s *Server) WithRefreshToken(token string) *Server

WithRefreshToken sets the refreshToken.

func (*Server) WithRequestToken

func (s *Server) WithRequestToken(token string) *Server

WithRequestToken sets the accessToken.

type ServerMocker

type ServerMocker func(t TestingT) *Server

ServerMocker is a function that applies expectations to the mocked server.

func MockEmptyServer

func MockEmptyServer(mocks ...ServerOption) ServerMocker

MockEmptyServer mocks a MoneyLover API server.

func MockServer

func MockServer(
	username, password string,
	mocks ...ServerOption,
) ServerMocker

MockServer mocks a server with successful authentication workflow.

type ServerOption

type ServerOption = func(s *Server)

ServerOption is an option to configure Server.

func WithAuthLoginURLFailure

func WithAuthLoginURLFailure() ServerOption

WithAuthLoginURLFailure expects a request for login URL and returns a 500.

func WithAuthLoginURLSuccess

func WithAuthLoginURLSuccess() ServerOption

WithAuthLoginURLSuccess expects a request for login URL.

func WithAuthSuccess

func WithAuthSuccess(username, password string) ServerOption

WithAuthSuccess expects a success login workflow.

func WithAuthTokenFailure

func WithAuthTokenFailure(username, password string) ServerOption

WithAuthTokenFailure expects a request for login and returns a 401.

func WithAuthTokenSuccess

func WithAuthTokenSuccess(username, password string) ServerOption

WithAuthTokenSuccess expects a request for login.

func WithFindAllTransactionsInRange

func WithFindAllTransactionsInRange(
	walletID string,
	from time.Time,
	to time.Time,
	result []transaction.Transaction,
) ServerOption

WithFindAllTransactionsInRange sets expectations for finding all transactions in a range.

type TestingT

type TestingT = test.T

TestingT is an alias of httpmock.TestingT.

Directories

Path Synopsis
Package auth provides functionalities for testing authentication.
Package auth provides functionalities for testing authentication.
Package category provides functionalities for testing category contract.
Package category provides functionalities for testing category contract.
Package transaction provides functionalities for testing transaction contract.
Package transaction provides functionalities for testing transaction contract.
Package wallet provides functionalities for testing wallet contract.
Package wallet provides functionalities for testing wallet contract.

Jump to

Keyboard shortcuts

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