Documentation ¶
Index ¶
- type Decimal
- type Item
- type Repository
- type RepositoryMock
- func (mock *RepositoryMock) AddItem(ctx context.Context, item *Item) (Item, error)
- func (mock *RepositoryMock) AddItemCalls() []struct{ ... }
- func (mock *RepositoryMock) GetItemByID(ctx context.Context, id int64) (Item, error)
- func (mock *RepositoryMock) GetItemByIDCalls() []struct{ ... }
- func (mock *RepositoryMock) GetItems(ctx context.Context, page int64, pageSize int64) ([]Item, error)
- func (mock *RepositoryMock) GetItemsCalls() []struct{ ... }
- func (mock *RepositoryMock) RemoveItem(ctx context.Context, id int64) (int64, error)
- func (mock *RepositoryMock) RemoveItemCalls() []struct{ ... }
- func (mock *RepositoryMock) UpdateItem(ctx context.Context, item *Item) (Item, error)
- func (mock *RepositoryMock) UpdateItemCalls() []struct{ ... }
- type Service
- type ServiceError
- type ServiceStatusCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct { ID int64 `json:"id"` Name string `json:"name"` Price Decimal `json:"price"` Manufacturer string `json:"manufacturer"` }
Item ..
type Repository ¶
type Repository interface { GetItems(ctx context.Context, page int64, pageSize int64) ([]Item, error) GetItemByID(ctx context.Context, id int64) (Item, error) AddItem(ctx context.Context, item *Item) (Item, error) UpdateItem(ctx context.Context, item *Item) (Item, error) RemoveItem(ctx context.Context, id int64) (int64, error) }
Repository ..
type RepositoryMock ¶
type RepositoryMock struct { // AddItemFunc mocks the AddItem method. AddItemFunc func(ctx context.Context, item *Item) (Item, error) // GetItemByIDFunc mocks the GetItemByID method. GetItemByIDFunc func(ctx context.Context, id int64) (Item, error) // GetItemsFunc mocks the GetItems method. GetItemsFunc func(ctx context.Context, page int64, pageSize int64) ([]Item, error) // RemoveItemFunc mocks the RemoveItem method. RemoveItemFunc func(ctx context.Context, id int64) (int64, error) // UpdateItemFunc mocks the UpdateItem method. UpdateItemFunc func(ctx context.Context, item *Item) (Item, 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{ AddItemFunc: func(ctx context.Context, item *Item) (Item, error) { panic("mock out the AddItem method") }, GetItemByIDFunc: func(ctx context.Context, id int64) (Item, error) { panic("mock out the GetItemByID method") }, GetItemsFunc: func(ctx context.Context, page int64, pageSize int64) ([]Item, error) { panic("mock out the GetItems method") }, RemoveItemFunc: func(ctx context.Context, id int64) (int64, error) { panic("mock out the RemoveItem method") }, UpdateItemFunc: func(ctx context.Context, item *Item) (Item, error) { panic("mock out the UpdateItem method") }, } // use mockedRepository in code that requires Repository // and then make assertions. }
func (*RepositoryMock) AddItemCalls ¶
func (mock *RepositoryMock) AddItemCalls() []struct { Ctx context.Context Item *Item }
AddItemCalls gets all the calls that were made to AddItem. Check the length with:
len(mockedRepository.AddItemCalls())
func (*RepositoryMock) GetItemByID ¶
GetItemByID calls GetItemByIDFunc.
func (*RepositoryMock) GetItemByIDCalls ¶
func (mock *RepositoryMock) GetItemByIDCalls() []struct { Ctx context.Context ID int64 }
GetItemByIDCalls gets all the calls that were made to GetItemByID. Check the length with:
len(mockedRepository.GetItemByIDCalls())
func (*RepositoryMock) GetItems ¶
func (mock *RepositoryMock) GetItems(ctx context.Context, page int64, pageSize int64) ([]Item, error)
GetItems calls GetItemsFunc.
func (*RepositoryMock) GetItemsCalls ¶
func (mock *RepositoryMock) GetItemsCalls() []struct { Ctx context.Context Page int64 PageSize int64 }
GetItemsCalls gets all the calls that were made to GetItems. Check the length with:
len(mockedRepository.GetItemsCalls())
func (*RepositoryMock) RemoveItem ¶
RemoveItem calls RemoveItemFunc.
func (*RepositoryMock) RemoveItemCalls ¶
func (mock *RepositoryMock) RemoveItemCalls() []struct { Ctx context.Context ID int64 }
RemoveItemCalls gets all the calls that were made to RemoveItem. Check the length with:
len(mockedRepository.RemoveItemCalls())
func (*RepositoryMock) UpdateItem ¶
UpdateItem calls UpdateItemFunc.
func (*RepositoryMock) UpdateItemCalls ¶
func (mock *RepositoryMock) UpdateItemCalls() []struct { Ctx context.Context Item *Item }
UpdateItemCalls gets all the calls that were made to UpdateItem. Check the length with:
len(mockedRepository.UpdateItemCalls())
type Service ¶
type Service interface { GetItems(ctx context.Context, page int64, pageSize int64) ([]Item, error) GetItemByID(ctx context.Context, id int64) (Item, error) AddCartItem( ctx context.Context, name string, price Decimal, manufacturer string, ) (Item, error) UpdateCartItem( ctx context.Context, id int64, name string, price Decimal, manufacturer string, ) (Item, ServiceError) RemoveCartItem(ctx context.Context, id int64) (int64, ServiceError) }
Service ..
type ServiceError ¶
type ServiceError interface { Message() string StatusCode() ServiceStatusCode }
ServiceError ..
func CreateServiceError ¶
func CreateServiceError(message string, statusCode ServiceStatusCode) ServiceError
CreateServiceError ..
type ServiceStatusCode ¶
type ServiceStatusCode string
ServiceStatusCode ..
const ( // ItemNotFound .. ItemNotFound ServiceStatusCode = "ItemNotFound" // InvalidItem .. InvalidItem ServiceStatusCode = "InvalidItem" // UnknownException .. UnknownException ServiceStatusCode = "UnknownException" )