account

package
v0.0.0-...-5927a11 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateAccountInput

type CreateAccountInput struct {
	Name   string
	Secret string
	CPF    string
}

type Repository

type Repository interface {
	CreateAccount(ctx context.Context, account entities.Account) error
	GetById(ctx context.Context, id string) (entities.Account, error)
	GetByCpf(ctx context.Context, cpf string) (entities.Account, error)
	GetAccounts(ctx context.Context) ([]entities.Account, error)
	UpdateBalance(ctx context.Context, id string, value int) error
}

type RepositoryMock

type RepositoryMock struct {
	// CreateAccountFunc mocks the CreateAccount method.
	CreateAccountFunc func(ctx context.Context, account entities.Account) error

	// GetAccountsFunc mocks the GetAccounts method.
	GetAccountsFunc func(ctx context.Context) ([]entities.Account, error)

	// GetByCpfFunc mocks the GetByCpf method.
	GetByCpfFunc func(ctx context.Context, cpf string) (entities.Account, error)

	// GetByIdFunc mocks the GetById method.
	GetByIdFunc func(ctx context.Context, id string) (entities.Account, error)

	// UpdateBalanceFunc mocks the UpdateBalance method.
	UpdateBalanceFunc func(ctx context.Context, id string, value int) error
	// contains filtered or unexported fields
}

RepositoryMock is a mock implementation of Repository.

func TestSomethingThatUsesRepository(t *testing.T) {

	// make and configure a mocked Repository
	mockedRepository := &RepositoryMock{
		CreateAccountFunc: func(ctx context.Context, account entities.Account) error {
			panic("mock out the CreateAccount method")
		},
		GetAccountsFunc: func(ctx context.Context) ([]entities.Account, error) {
			panic("mock out the GetAccounts method")
		},
		GetByCpfFunc: func(ctx context.Context, cpf string) (entities.Account, error) {
			panic("mock out the GetByCpf method")
		},
		GetByIdFunc: func(ctx context.Context, id string) (entities.Account, error) {
			panic("mock out the GetById method")
		},
		UpdateBalanceFunc: func(ctx context.Context, id string, value int) error {
			panic("mock out the UpdateBalance method")
		},
	}

	// use mockedRepository in code that requires Repository
	// and then make assertions.

}

func (*RepositoryMock) CreateAccount

func (mock *RepositoryMock) CreateAccount(ctx context.Context, account entities.Account) error

CreateAccount calls CreateAccountFunc.

func (*RepositoryMock) CreateAccountCalls

func (mock *RepositoryMock) CreateAccountCalls() []struct {
	Ctx     context.Context
	Account entities.Account
}

CreateAccountCalls gets all the calls that were made to CreateAccount. Check the length with:

len(mockedRepository.CreateAccountCalls())

func (*RepositoryMock) GetAccounts

func (mock *RepositoryMock) GetAccounts(ctx context.Context) ([]entities.Account, error)

GetAccounts calls GetAccountsFunc.

func (*RepositoryMock) GetAccountsCalls

func (mock *RepositoryMock) GetAccountsCalls() []struct {
	Ctx context.Context
}

GetAccountsCalls gets all the calls that were made to GetAccounts. Check the length with:

len(mockedRepository.GetAccountsCalls())

func (*RepositoryMock) GetByCpf

func (mock *RepositoryMock) GetByCpf(ctx context.Context, cpf string) (entities.Account, error)

GetByCpf calls GetByCpfFunc.

func (*RepositoryMock) GetByCpfCalls

func (mock *RepositoryMock) GetByCpfCalls() []struct {
	Ctx context.Context
	Cpf string
}

GetByCpfCalls gets all the calls that were made to GetByCpf. Check the length with:

len(mockedRepository.GetByCpfCalls())

func (*RepositoryMock) GetById

func (mock *RepositoryMock) GetById(ctx context.Context, id string) (entities.Account, error)

GetById calls GetByIdFunc.

func (*RepositoryMock) GetByIdCalls

func (mock *RepositoryMock) GetByIdCalls() []struct {
	Ctx context.Context
	ID  string
}

GetByIdCalls gets all the calls that were made to GetById. Check the length with:

len(mockedRepository.GetByIdCalls())

func (*RepositoryMock) UpdateBalance

func (mock *RepositoryMock) UpdateBalance(ctx context.Context, id string, value int) error

UpdateBalance calls UpdateBalanceFunc.

func (*RepositoryMock) UpdateBalanceCalls

func (mock *RepositoryMock) UpdateBalanceCalls() []struct {
	Ctx   context.Context
	ID    string
	Value int
}

UpdateBalanceCalls gets all the calls that were made to UpdateBalance. Check the length with:

len(mockedRepository.UpdateBalanceCalls())

type UseCase

type UseCase interface {
	Create(ctx context.Context, input CreateAccountInput) (entities.Account, error)
	GetAccounts(ctx context.Context) ([]entities.Account, error)
	GetBalance(ctx context.Context, id string) (int, error)
	GetById(ctx context.Context, id string) (entities.Account, error)
	GetByCpf(ctx context.Context, cpf string) (entities.Account, error)
	UpdateBalance(ctx context.Context, originAccountId, destinationAccountId string, amount int) error
}

type UseCaseMock

type UseCaseMock struct {
	// CreateFunc mocks the Create method.
	CreateFunc func(ctx context.Context, input CreateAccountInput) (entities.Account, error)

	// GetAccountsFunc mocks the GetAccounts method.
	GetAccountsFunc func(ctx context.Context) ([]entities.Account, error)

	// GetBalanceFunc mocks the GetBalance method.
	GetBalanceFunc func(ctx context.Context, id string) (int, error)

	// GetByCpfFunc mocks the GetByCpf method.
	GetByCpfFunc func(ctx context.Context, cpf string) (entities.Account, error)

	// GetByIdFunc mocks the GetById method.
	GetByIdFunc func(ctx context.Context, id string) (entities.Account, error)

	// UpdateBalanceFunc mocks the UpdateBalance method.
	UpdateBalanceFunc func(ctx context.Context, originAccountId string, destinationAccountId string, amount int) error
	// contains filtered or unexported fields
}

UseCaseMock is a mock implementation of UseCase.

func TestSomethingThatUsesUseCase(t *testing.T) {

	// make and configure a mocked UseCase
	mockedUseCase := &UseCaseMock{
		CreateFunc: func(ctx context.Context, input CreateAccountInput) (entities.Account, error) {
			panic("mock out the Create method")
		},
		GetAccountsFunc: func(ctx context.Context) ([]entities.Account, error) {
			panic("mock out the GetAccounts method")
		},
		GetBalanceFunc: func(ctx context.Context, id string) (int, error) {
			panic("mock out the GetBalance method")
		},
		GetByCpfFunc: func(ctx context.Context, cpf string) (entities.Account, error) {
			panic("mock out the GetByCpf method")
		},
		GetByIdFunc: func(ctx context.Context, id string) (entities.Account, error) {
			panic("mock out the GetById method")
		},
		UpdateBalanceFunc: func(ctx context.Context, originAccountId string, destinationAccountId string, amount int) error {
			panic("mock out the UpdateBalance method")
		},
	}

	// use mockedUseCase in code that requires UseCase
	// and then make assertions.

}

func (*UseCaseMock) Create

func (mock *UseCaseMock) Create(ctx context.Context, input CreateAccountInput) (entities.Account, error)

Create calls CreateFunc.

func (*UseCaseMock) CreateCalls

func (mock *UseCaseMock) CreateCalls() []struct {
	Ctx   context.Context
	Input CreateAccountInput
}

CreateCalls gets all the calls that were made to Create. Check the length with:

len(mockedUseCase.CreateCalls())

func (*UseCaseMock) GetAccounts

func (mock *UseCaseMock) GetAccounts(ctx context.Context) ([]entities.Account, error)

GetAccounts calls GetAccountsFunc.

func (*UseCaseMock) GetAccountsCalls

func (mock *UseCaseMock) GetAccountsCalls() []struct {
	Ctx context.Context
}

GetAccountsCalls gets all the calls that were made to GetAccounts. Check the length with:

len(mockedUseCase.GetAccountsCalls())

func (*UseCaseMock) GetBalance

func (mock *UseCaseMock) GetBalance(ctx context.Context, id string) (int, error)

GetBalance calls GetBalanceFunc.

func (*UseCaseMock) GetBalanceCalls

func (mock *UseCaseMock) GetBalanceCalls() []struct {
	Ctx context.Context
	ID  string
}

GetBalanceCalls gets all the calls that were made to GetBalance. Check the length with:

len(mockedUseCase.GetBalanceCalls())

func (*UseCaseMock) GetByCpf

func (mock *UseCaseMock) GetByCpf(ctx context.Context, cpf string) (entities.Account, error)

GetByCpf calls GetByCpfFunc.

func (*UseCaseMock) GetByCpfCalls

func (mock *UseCaseMock) GetByCpfCalls() []struct {
	Ctx context.Context
	Cpf string
}

GetByCpfCalls gets all the calls that were made to GetByCpf. Check the length with:

len(mockedUseCase.GetByCpfCalls())

func (*UseCaseMock) GetById

func (mock *UseCaseMock) GetById(ctx context.Context, id string) (entities.Account, error)

GetById calls GetByIdFunc.

func (*UseCaseMock) GetByIdCalls

func (mock *UseCaseMock) GetByIdCalls() []struct {
	Ctx context.Context
	ID  string
}

GetByIdCalls gets all the calls that were made to GetById. Check the length with:

len(mockedUseCase.GetByIdCalls())

func (*UseCaseMock) UpdateBalance

func (mock *UseCaseMock) UpdateBalance(ctx context.Context, originAccountId string, destinationAccountId string, amount int) error

UpdateBalance calls UpdateBalanceFunc.

func (*UseCaseMock) UpdateBalanceCalls

func (mock *UseCaseMock) UpdateBalanceCalls() []struct {
	Ctx                  context.Context
	OriginAccountId      string
	DestinationAccountId string
	Amount               int
}

UpdateBalanceCalls gets all the calls that were made to UpdateBalance. Check the length with:

len(mockedUseCase.UpdateBalanceCalls())

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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