Help us shape the future of Go! Take the 2026 Go Developer Survey

mock

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseMock

type DatabaseMock struct {
	// CloseFunc mocks the Close method.
	CloseFunc func() error

	// GetAlertFunc mocks the GetAlert method.
	GetAlertFunc func(ctx context.Context, id types.AlertID) (*model.Alert, error)

	// GetAttrsFunc mocks the GetAttrs method.
	GetAttrsFunc func(ctx context.Context, ns types.Namespace) (model.Attributes, error)

	// GetWorkflowFunc mocks the GetWorkflow method.
	GetWorkflowFunc func(ctx context.Context, id types.WorkflowID) (*model.WorkflowRecord, error)

	// GetWorkflowsFunc mocks the GetWorkflows method.
	GetWorkflowsFunc func(ctx context.Context, offset int, limit int) ([]model.WorkflowRecord, error)

	// LockFunc mocks the Lock method.
	LockFunc func(ctx context.Context, ns types.Namespace, timeout time.Time) error

	// PutAlertFunc mocks the PutAlert method.
	PutAlertFunc func(ctx context.Context, alert model.Alert) error

	// PutAttrsFunc mocks the PutAttrs method.
	PutAttrsFunc func(ctx context.Context, ns types.Namespace, attrs model.Attributes) error

	// PutWorkflowFunc mocks the PutWorkflow method.
	PutWorkflowFunc func(ctx context.Context, workflow model.WorkflowRecord) error

	// UnlockFunc mocks the Unlock method.
	UnlockFunc func(ctx context.Context, ns types.Namespace) error
	// contains filtered or unexported fields
}

DatabaseMock is a mock implementation of interfaces.Database.

func TestSomethingThatUsesDatabase(t *testing.T) {

	// make and configure a mocked interfaces.Database
	mockedDatabase := &DatabaseMock{
		CloseFunc: func() error {
			panic("mock out the Close method")
		},
		GetAlertFunc: func(ctx context.Context, id types.AlertID) (*model.Alert, error) {
			panic("mock out the GetAlert method")
		},
		GetAttrsFunc: func(ctx context.Context, ns types.Namespace) (model.Attributes, error) {
			panic("mock out the GetAttrs method")
		},
		GetWorkflowFunc: func(ctx context.Context, id types.WorkflowID) (*model.WorkflowRecord, error) {
			panic("mock out the GetWorkflow method")
		},
		GetWorkflowsFunc: func(ctx context.Context, offset int, limit int) ([]model.WorkflowRecord, error) {
			panic("mock out the GetWorkflows method")
		},
		LockFunc: func(ctx context.Context, ns types.Namespace, timeout time.Time) error {
			panic("mock out the Lock method")
		},
		PutAlertFunc: func(ctx context.Context, alert model.Alert) error {
			panic("mock out the PutAlert method")
		},
		PutAttrsFunc: func(ctx context.Context, ns types.Namespace, attrs model.Attributes) error {
			panic("mock out the PutAttrs method")
		},
		PutWorkflowFunc: func(ctx context.Context, workflow model.WorkflowRecord) error {
			panic("mock out the PutWorkflow method")
		},
		UnlockFunc: func(ctx context.Context, ns types.Namespace) error {
			panic("mock out the Unlock method")
		},
	}

	// use mockedDatabase in code that requires interfaces.Database
	// and then make assertions.

}

func (*DatabaseMock) Close

func (mock *DatabaseMock) Close() error

Close calls CloseFunc.

func (*DatabaseMock) CloseCalls

func (mock *DatabaseMock) CloseCalls() []struct {
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedDatabase.CloseCalls())

func (*DatabaseMock) GetAlert

func (mock *DatabaseMock) GetAlert(ctx context.Context, id types.AlertID) (*model.Alert, error)

GetAlert calls GetAlertFunc.

func (*DatabaseMock) GetAlertCalls

func (mock *DatabaseMock) GetAlertCalls() []struct {
	Ctx context.Context
	ID  types.AlertID
}

GetAlertCalls gets all the calls that were made to GetAlert. Check the length with:

len(mockedDatabase.GetAlertCalls())

func (*DatabaseMock) GetAttrs

func (mock *DatabaseMock) GetAttrs(ctx context.Context, ns types.Namespace) (model.Attributes, error)

GetAttrs calls GetAttrsFunc.

func (*DatabaseMock) GetAttrsCalls

func (mock *DatabaseMock) GetAttrsCalls() []struct {
	Ctx context.Context
	Ns  types.Namespace
}

GetAttrsCalls gets all the calls that were made to GetAttrs. Check the length with:

len(mockedDatabase.GetAttrsCalls())

func (*DatabaseMock) GetWorkflow

func (mock *DatabaseMock) GetWorkflow(ctx context.Context, id types.WorkflowID) (*model.WorkflowRecord, error)

GetWorkflow calls GetWorkflowFunc.

func (*DatabaseMock) GetWorkflowCalls

func (mock *DatabaseMock) GetWorkflowCalls() []struct {
	Ctx context.Context
	ID  types.WorkflowID
}

GetWorkflowCalls gets all the calls that were made to GetWorkflow. Check the length with:

len(mockedDatabase.GetWorkflowCalls())

func (*DatabaseMock) GetWorkflows

func (mock *DatabaseMock) GetWorkflows(ctx context.Context, offset int, limit int) ([]model.WorkflowRecord, error)

GetWorkflows calls GetWorkflowsFunc.

func (*DatabaseMock) GetWorkflowsCalls

func (mock *DatabaseMock) GetWorkflowsCalls() []struct {
	Ctx    context.Context
	Offset int
	Limit  int
}

GetWorkflowsCalls gets all the calls that were made to GetWorkflows. Check the length with:

len(mockedDatabase.GetWorkflowsCalls())

func (*DatabaseMock) Lock

func (mock *DatabaseMock) Lock(ctx context.Context, ns types.Namespace, timeout time.Time) error

Lock calls LockFunc.

func (*DatabaseMock) LockCalls

func (mock *DatabaseMock) LockCalls() []struct {
	Ctx     context.Context
	Ns      types.Namespace
	Timeout time.Time
}

LockCalls gets all the calls that were made to Lock. Check the length with:

len(mockedDatabase.LockCalls())

func (*DatabaseMock) PutAlert

func (mock *DatabaseMock) PutAlert(ctx context.Context, alert model.Alert) error

PutAlert calls PutAlertFunc.

func (*DatabaseMock) PutAlertCalls

func (mock *DatabaseMock) PutAlertCalls() []struct {
	Ctx   context.Context
	Alert model.Alert
}

PutAlertCalls gets all the calls that were made to PutAlert. Check the length with:

len(mockedDatabase.PutAlertCalls())

func (*DatabaseMock) PutAttrs

func (mock *DatabaseMock) PutAttrs(ctx context.Context, ns types.Namespace, attrs model.Attributes) error

PutAttrs calls PutAttrsFunc.

func (*DatabaseMock) PutAttrsCalls

func (mock *DatabaseMock) PutAttrsCalls() []struct {
	Ctx   context.Context
	Ns    types.Namespace
	Attrs model.Attributes
}

PutAttrsCalls gets all the calls that were made to PutAttrs. Check the length with:

len(mockedDatabase.PutAttrsCalls())

func (*DatabaseMock) PutWorkflow

func (mock *DatabaseMock) PutWorkflow(ctx context.Context, workflow model.WorkflowRecord) error

PutWorkflow calls PutWorkflowFunc.

func (*DatabaseMock) PutWorkflowCalls

func (mock *DatabaseMock) PutWorkflowCalls() []struct {
	Ctx      context.Context
	Workflow model.WorkflowRecord
}

PutWorkflowCalls gets all the calls that were made to PutWorkflow. Check the length with:

len(mockedDatabase.PutWorkflowCalls())

func (*DatabaseMock) Unlock

func (mock *DatabaseMock) Unlock(ctx context.Context, ns types.Namespace) error

Unlock calls UnlockFunc.

func (*DatabaseMock) UnlockCalls

func (mock *DatabaseMock) UnlockCalls() []struct {
	Ctx context.Context
	Ns  types.Namespace
}

UnlockCalls gets all the calls that were made to Unlock. Check the length with:

len(mockedDatabase.UnlockCalls())

type GenAIMock

type GenAIMock struct {
	// GenerateFunc mocks the Generate method.
	GenerateFunc func(ctx context.Context, prompts ...string) ([]string, error)
	// contains filtered or unexported fields
}

GenAIMock is a mock implementation of interfaces.GenAI.

func TestSomethingThatUsesGenAI(t *testing.T) {

	// make and configure a mocked interfaces.GenAI
	mockedGenAI := &GenAIMock{
		GenerateFunc: func(ctx context.Context, prompts ...string) ([]string, error) {
			panic("mock out the Generate method")
		},
	}

	// use mockedGenAI in code that requires interfaces.GenAI
	// and then make assertions.

}

func (*GenAIMock) Generate

func (mock *GenAIMock) Generate(ctx context.Context, prompts ...string) ([]string, error)

Generate calls GenerateFunc.

func (*GenAIMock) GenerateCalls

func (mock *GenAIMock) GenerateCalls() []struct {
	Ctx     context.Context
	Prompts []string
}

GenerateCalls gets all the calls that were made to Generate. Check the length with:

len(mockedGenAI.GenerateCalls())

Jump to

Keyboard shortcuts

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