mock

package
v0.0.0-...-7d02455 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBMock

type DBMock struct {
	// CreateFunc mocks the Create method.
	CreateFunc func(value interface{}) *gorm.DB

	// DeleteFunc mocks the Delete method.
	DeleteFunc func(value interface{}, conds ...interface{}) *gorm.DB

	// FindFunc mocks the Find method.
	FindFunc func(dest interface{}, conds ...interface{}) *gorm.DB

	// FirstFunc mocks the First method.
	FirstFunc func(dest interface{}, conds ...interface{}) *gorm.DB

	// SaveFunc mocks the Save method.
	SaveFunc func(value interface{}) *gorm.DB
	// contains filtered or unexported fields
}

DBMock is a mock implementation of repository.DB.

func TestSomethingThatUsesDB(t *testing.T) {

	// make and configure a mocked repository.DB
	mockedDB := &DBMock{
		CreateFunc: func(value interface{}) *gorm.DB {
			panic("mock out the Create method")
		},
		DeleteFunc: func(value interface{}, conds ...interface{}) *gorm.DB {
			panic("mock out the Delete method")
		},
		FindFunc: func(dest interface{}, conds ...interface{}) *gorm.DB {
			panic("mock out the Find method")
		},
		FirstFunc: func(dest interface{}, conds ...interface{}) *gorm.DB {
			panic("mock out the First method")
		},
		SaveFunc: func(value interface{}) *gorm.DB {
			panic("mock out the Save method")
		},
	}

	// use mockedDB in code that requires repository.DB
	// and then make assertions.

}

func (*DBMock) Create

func (mock *DBMock) Create(value interface{}) *gorm.DB

Create calls CreateFunc.

func (*DBMock) CreateCalls

func (mock *DBMock) CreateCalls() []struct {
	Value interface{}
}

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

len(mockedDB.CreateCalls())

func (*DBMock) Delete

func (mock *DBMock) Delete(value interface{}, conds ...interface{}) *gorm.DB

Delete calls DeleteFunc.

func (*DBMock) DeleteCalls

func (mock *DBMock) DeleteCalls() []struct {
	Value interface{}
	Conds []interface{}
}

DeleteCalls gets all the calls that were made to Delete. Check the length with:

len(mockedDB.DeleteCalls())

func (*DBMock) Find

func (mock *DBMock) Find(dest interface{}, conds ...interface{}) *gorm.DB

Find calls FindFunc.

func (*DBMock) FindCalls

func (mock *DBMock) FindCalls() []struct {
	Dest  interface{}
	Conds []interface{}
}

FindCalls gets all the calls that were made to Find. Check the length with:

len(mockedDB.FindCalls())

func (*DBMock) First

func (mock *DBMock) First(dest interface{}, conds ...interface{}) *gorm.DB

First calls FirstFunc.

func (*DBMock) FirstCalls

func (mock *DBMock) FirstCalls() []struct {
	Dest  interface{}
	Conds []interface{}
}

FirstCalls gets all the calls that were made to First. Check the length with:

len(mockedDB.FirstCalls())

func (*DBMock) Save

func (mock *DBMock) Save(value interface{}) *gorm.DB

Save calls SaveFunc.

func (*DBMock) SaveCalls

func (mock *DBMock) SaveCalls() []struct {
	Value interface{}
}

SaveCalls gets all the calls that were made to Save. Check the length with:

len(mockedDB.SaveCalls())

type UserRepositoryMock

type UserRepositoryMock struct {
	// CreateUserFunc mocks the CreateUser method.
	CreateUserFunc func(user *model.User) error

	// DeleteUserFunc mocks the DeleteUser method.
	DeleteUserFunc func(id uuid.UUID) error

	// GetUserByIDFunc mocks the GetUserByID method.
	GetUserByIDFunc func(id uuid.UUID) (*model.User, error)

	// ListUsersFunc mocks the ListUsers method.
	ListUsersFunc func() ([]*model.User, error)

	// UpdateUserFunc mocks the UpdateUser method.
	UpdateUserFunc func(user *model.User) error
	// contains filtered or unexported fields
}

UserRepositoryMock is a mock implementation of repository.UserRepository.

func TestSomethingThatUsesUserRepository(t *testing.T) {

	// make and configure a mocked repository.UserRepository
	mockedUserRepository := &UserRepositoryMock{
		CreateUserFunc: func(user *model.User) error {
			panic("mock out the CreateUser method")
		},
		DeleteUserFunc: func(id uuid.UUID) error {
			panic("mock out the DeleteUser method")
		},
		GetUserByIDFunc: func(id uuid.UUID) (*model.User, error) {
			panic("mock out the GetUserByID method")
		},
		ListUsersFunc: func() ([]*model.User, error) {
			panic("mock out the ListUsers method")
		},
		UpdateUserFunc: func(user *model.User) error {
			panic("mock out the UpdateUser method")
		},
	}

	// use mockedUserRepository in code that requires repository.UserRepository
	// and then make assertions.

}

func (*UserRepositoryMock) CreateUser

func (mock *UserRepositoryMock) CreateUser(user *model.User) error

CreateUser calls CreateUserFunc.

func (*UserRepositoryMock) CreateUserCalls

func (mock *UserRepositoryMock) CreateUserCalls() []struct {
	User *model.User
}

CreateUserCalls gets all the calls that were made to CreateUser. Check the length with:

len(mockedUserRepository.CreateUserCalls())

func (*UserRepositoryMock) DeleteUser

func (mock *UserRepositoryMock) DeleteUser(id uuid.UUID) error

DeleteUser calls DeleteUserFunc.

func (*UserRepositoryMock) DeleteUserCalls

func (mock *UserRepositoryMock) DeleteUserCalls() []struct {
	ID uuid.UUID
}

DeleteUserCalls gets all the calls that were made to DeleteUser. Check the length with:

len(mockedUserRepository.DeleteUserCalls())

func (*UserRepositoryMock) GetUserByID

func (mock *UserRepositoryMock) GetUserByID(id uuid.UUID) (*model.User, error)

GetUserByID calls GetUserByIDFunc.

func (*UserRepositoryMock) GetUserByIDCalls

func (mock *UserRepositoryMock) GetUserByIDCalls() []struct {
	ID uuid.UUID
}

GetUserByIDCalls gets all the calls that were made to GetUserByID. Check the length with:

len(mockedUserRepository.GetUserByIDCalls())

func (*UserRepositoryMock) ListUsers

func (mock *UserRepositoryMock) ListUsers() ([]*model.User, error)

ListUsers calls ListUsersFunc.

func (*UserRepositoryMock) ListUsersCalls

func (mock *UserRepositoryMock) ListUsersCalls() []struct {
}

ListUsersCalls gets all the calls that were made to ListUsers. Check the length with:

len(mockedUserRepository.ListUsersCalls())

func (*UserRepositoryMock) UpdateUser

func (mock *UserRepositoryMock) UpdateUser(user *model.User) error

UpdateUser calls UpdateUserFunc.

func (*UserRepositoryMock) UpdateUserCalls

func (mock *UserRepositoryMock) UpdateUserCalls() []struct {
	User *model.User
}

UpdateUserCalls gets all the calls that were made to UpdateUser. Check the length with:

len(mockedUserRepository.UpdateUserCalls())

Jump to

Keyboard shortcuts

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