testkit

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 20 Imported by: 1

Documentation

Overview

Package testkit provides functionalities for testing N26 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.5.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 N26 APIs.

func NewServer added in v0.3.1

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) BasicAuthorization

func (s *Server) BasicAuthorization() string

BasicAuthorization returns the credentials for asserting the /oauth/token Authorization.

func (*Server) DeviceID

func (s *Server) DeviceID() uuid.UUID

DeviceID returns the deviceID.

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) ExpectWithBasicAuth

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

ExpectWithBasicAuth expects a request with Basic Authorization.

func (*Server) MFAToken

func (s *Server) MFAToken() uuid.UUID

MFAToken returns the deviceID.

func (*Server) RefreshToken

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

RefreshToken returns the refreshToken.

func (*Server) UserID

func (s *Server) UserID() uuid.UUID

UserID returns the userID.

func (*Server) WithAccessToken

func (s *Server) WithAccessToken(token uuid.UUID) *Server

WithAccessToken sets the accessToken.

func (*Server) WithAuthAuthorization

func (s *Server) WithAuthAuthorization(username, password string) *Server

WithAuthAuthorization sets Authorization credentials for asserting the /oauth/token request.

func (*Server) WithDeviceID

func (s *Server) WithDeviceID(deviceID uuid.UUID) *Server

WithDeviceID sets the deviceID.

func (*Server) WithMFAToken

func (s *Server) WithMFAToken(mfaToken uuid.UUID) *Server

WithMFAToken sets the mfaToken.

func (*Server) WithPlanner added in v0.4.0

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

WithPlanner sets planner.

func (*Server) WithRefreshToken

func (s *Server) WithRefreshToken(token uuid.UUID) *Server

WithRefreshToken sets the refreshToken.

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 N26 API server.

func MockServer

func MockServer(
	username, password string,
	deviceID uuid.UUID,
	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 WithAuthAuthorization

func WithAuthAuthorization(username, password string) ServerOption

WithAuthAuthorization sets the Authorization credentials for asserting the /oauth/token request.

func WithAuthConfirmLoginFailure

func WithAuthConfirmLoginFailure() ServerOption

WithAuthConfirmLoginFailure expects a request for Login Confirm and returns a 500.

func WithAuthConfirmLoginFailureInvalidToken

func WithAuthConfirmLoginFailureInvalidToken(times uint) ServerOption

WithAuthConfirmLoginFailureInvalidToken expects a request for Login Confirm and returns an Invalid Token error (401).

func WithAuthConfirmLoginSuccess

func WithAuthConfirmLoginSuccess() ServerOption

WithAuthConfirmLoginSuccess expects a request for Login Confirm and returns a success.

func WithAuthMFAChallengeFailure

func WithAuthMFAChallengeFailure() ServerOption

WithAuthMFAChallengeFailure expects a request for MFA Challenge and returns a 500.

func WithAuthMFAChallengeFailureInvalidToken

func WithAuthMFAChallengeFailureInvalidToken() ServerOption

WithAuthMFAChallengeFailureInvalidToken expects a request for MFA Challenge and returns an Invalid Token error (401).

func WithAuthMFAChallengeSuccess

func WithAuthMFAChallengeSuccess() ServerOption

WithAuthMFAChallengeSuccess expects a request for MFA Challenge and returns a success.

func WithAuthPasswordLoginFailure

func WithAuthPasswordLoginFailure(username, password string, deviceID uuid.UUID) ServerOption

WithAuthPasswordLoginFailure expects a request for login and returns a 500.

func WithAuthPasswordLoginFailureTooManyAttempts

func WithAuthPasswordLoginFailureTooManyAttempts(username, password string, deviceID uuid.UUID) ServerOption

WithAuthPasswordLoginFailureTooManyAttempts expects a request for login and returns a too many attempts error (429).

func WithAuthPasswordLoginFailureWrongCredentials

func WithAuthPasswordLoginFailureWrongCredentials(username, password string, deviceID uuid.UUID) ServerOption

WithAuthPasswordLoginFailureWrongCredentials expects a request for login and returns a bad credentials error (400).

func WithAuthPasswordLoginSuccess

func WithAuthPasswordLoginSuccess(username, password string, deviceID uuid.UUID) ServerOption

WithAuthPasswordLoginSuccess expects a request for login and returns a 403 for the MFA Challenge.

func WithAuthPasswordLoginUnexpectedResponse

func WithAuthPasswordLoginUnexpectedResponse(username, password string, deviceID uuid.UUID) ServerOption

WithAuthPasswordLoginUnexpectedResponse expects a request for login and returns a 200 as an unexpected response.

func WithAuthRefreshTokenFailure

func WithAuthRefreshTokenFailure() ServerOption

WithAuthRefreshTokenFailure expects a request for Token Refresh and returns a 500.

func WithAuthRefreshTokenFailureInvalidToken

func WithAuthRefreshTokenFailureInvalidToken() ServerOption

WithAuthRefreshTokenFailureInvalidToken expects a request for Token Refresh and returns an Invalid Token error (401).

func WithAuthRefreshTokenSuccess

func WithAuthRefreshTokenSuccess() ServerOption

WithAuthRefreshTokenSuccess expects a request for Token Refresh and returns a success.

func WithAuthSuccess

func WithAuthSuccess(username, password string, deviceID uuid.UUID) ServerOption

WithAuthSuccess expects a success login workflow.

func WithFindAllTransactionsInRange

func WithFindAllTransactionsInRange(
	from time.Time,
	to time.Time,
	pageSize int64,
	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 N26 authentication.
Package auth provides functionalities for testing N26 authentication.
Package transaction provides functionalities for testing N26 Transaction APIs.
Package transaction provides functionalities for testing N26 Transaction APIs.

Jump to

Keyboard shortcuts

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