mock

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataStoreMock

type DataStoreMock struct {
	// CheckerFunc mocks the Checker method.
	CheckerFunc func(ctx context.Context, state *healthcheck.CheckState) error

	// CloseFunc mocks the Close method.
	CloseFunc func(ctx context.Context) error

	// GetCacheTimeFunc mocks the GetCacheTime method.
	GetCacheTimeFunc func(ctx context.Context, id string) (*models.CacheTime, error)

	// IsConnectedFunc mocks the IsConnected method.
	IsConnectedFunc func(ctx context.Context) bool

	// UpsertCacheTimeFunc mocks the UpsertCacheTime method.
	UpsertCacheTimeFunc func(ctx context.Context, cacheTime *models.CacheTime) error
	// contains filtered or unexported fields
}

DataStoreMock is a mock implementation of api.DataStore.

func TestSomethingThatUsesDataStore(t *testing.T) {

	// make and configure a mocked api.DataStore
	mockedDataStore := &DataStoreMock{
		CheckerFunc: func(ctx context.Context, state *healthcheck.CheckState) error {
			panic("mock out the Checker method")
		},
		CloseFunc: func(ctx context.Context) error {
			panic("mock out the Close method")
		},
		GetCacheTimeFunc: func(ctx context.Context, id string) (*models.CacheTime, error) {
			panic("mock out the GetCacheTime method")
		},
		IsConnectedFunc: func(ctx context.Context) bool {
			panic("mock out the IsConnected method")
		},
		UpsertCacheTimeFunc: func(ctx context.Context, cacheTime *models.CacheTime) error {
			panic("mock out the UpsertCacheTime method")
		},
	}

	// use mockedDataStore in code that requires api.DataStore
	// and then make assertions.

}

func (*DataStoreMock) Checker

func (mock *DataStoreMock) Checker(ctx context.Context, state *healthcheck.CheckState) error

Checker calls CheckerFunc.

func (*DataStoreMock) CheckerCalls

func (mock *DataStoreMock) CheckerCalls() []struct {
	Ctx   context.Context
	State *healthcheck.CheckState
}

CheckerCalls gets all the calls that were made to Checker. Check the length with:

len(mockedDataStore.CheckerCalls())

func (*DataStoreMock) Close

func (mock *DataStoreMock) Close(ctx context.Context) error

Close calls CloseFunc.

func (*DataStoreMock) CloseCalls

func (mock *DataStoreMock) CloseCalls() []struct {
	Ctx context.Context
}

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

len(mockedDataStore.CloseCalls())

func (*DataStoreMock) GetCacheTime

func (mock *DataStoreMock) GetCacheTime(ctx context.Context, id string) (*models.CacheTime, error)

GetCacheTime calls GetCacheTimeFunc.

func (*DataStoreMock) GetCacheTimeCalls

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

GetCacheTimeCalls gets all the calls that were made to GetCacheTime. Check the length with:

len(mockedDataStore.GetCacheTimeCalls())

func (*DataStoreMock) IsConnected

func (mock *DataStoreMock) IsConnected(ctx context.Context) bool

IsConnected calls IsConnectedFunc.

func (*DataStoreMock) IsConnectedCalls

func (mock *DataStoreMock) IsConnectedCalls() []struct {
	Ctx context.Context
}

IsConnectedCalls gets all the calls that were made to IsConnected. Check the length with:

len(mockedDataStore.IsConnectedCalls())

func (*DataStoreMock) UpsertCacheTime

func (mock *DataStoreMock) UpsertCacheTime(ctx context.Context, cacheTime *models.CacheTime) error

UpsertCacheTime calls UpsertCacheTimeFunc.

func (*DataStoreMock) UpsertCacheTimeCalls

func (mock *DataStoreMock) UpsertCacheTimeCalls() []struct {
	Ctx       context.Context
	CacheTime *models.CacheTime
}

UpsertCacheTimeCalls gets all the calls that were made to UpsertCacheTime. Check the length with:

len(mockedDataStore.UpsertCacheTimeCalls())

type HTTPServerMock

type HTTPServerMock struct {
	// ListenAndServeFunc mocks the ListenAndServe method.
	ListenAndServeFunc func() error

	// ShutdownFunc mocks the Shutdown method.
	ShutdownFunc func(ctx context.Context) error
	// contains filtered or unexported fields
}

HTTPServerMock is a mock implementation of service.HTTPServer.

func TestSomethingThatUsesHTTPServer(t *testing.T) {

	// make and configure a mocked service.HTTPServer
	mockedHTTPServer := &HTTPServerMock{
		ListenAndServeFunc: func() error {
			panic("mock out the ListenAndServe method")
		},
		ShutdownFunc: func(ctx context.Context) error {
			panic("mock out the Shutdown method")
		},
	}

	// use mockedHTTPServer in code that requires service.HTTPServer
	// and then make assertions.

}

func (*HTTPServerMock) ListenAndServe

func (mock *HTTPServerMock) ListenAndServe() error

ListenAndServe calls ListenAndServeFunc.

func (*HTTPServerMock) ListenAndServeCalls

func (mock *HTTPServerMock) ListenAndServeCalls() []struct {
}

ListenAndServeCalls gets all the calls that were made to ListenAndServe. Check the length with:

len(mockedHTTPServer.ListenAndServeCalls())

func (*HTTPServerMock) Shutdown

func (mock *HTTPServerMock) Shutdown(ctx context.Context) error

Shutdown calls ShutdownFunc.

func (*HTTPServerMock) ShutdownCalls

func (mock *HTTPServerMock) ShutdownCalls() []struct {
	Ctx context.Context
}

ShutdownCalls gets all the calls that were made to Shutdown. Check the length with:

len(mockedHTTPServer.ShutdownCalls())

type HealthCheckerMock

type HealthCheckerMock struct {
	// AddCheckFunc mocks the AddCheck method.
	AddCheckFunc func(name string, checker healthcheck.Checker) error

	// HandlerFunc mocks the Handler method.
	HandlerFunc func(w http.ResponseWriter, req *http.Request)

	// StartFunc mocks the Start method.
	StartFunc func(ctx context.Context)

	// StopFunc mocks the Stop method.
	StopFunc func()
	// contains filtered or unexported fields
}

HealthCheckerMock is a mock implementation of service.HealthChecker.

func TestSomethingThatUsesHealthChecker(t *testing.T) {

	// make and configure a mocked service.HealthChecker
	mockedHealthChecker := &HealthCheckerMock{
		AddCheckFunc: func(name string, checker healthcheck.Checker) error {
			panic("mock out the AddCheck method")
		},
		HandlerFunc: func(w http.ResponseWriter, req *http.Request)  {
			panic("mock out the Handler method")
		},
		StartFunc: func(ctx context.Context)  {
			panic("mock out the Start method")
		},
		StopFunc: func()  {
			panic("mock out the Stop method")
		},
	}

	// use mockedHealthChecker in code that requires service.HealthChecker
	// and then make assertions.

}

func (*HealthCheckerMock) AddCheck

func (mock *HealthCheckerMock) AddCheck(name string, checker healthcheck.Checker) error

AddCheck calls AddCheckFunc.

func (*HealthCheckerMock) AddCheckCalls

func (mock *HealthCheckerMock) AddCheckCalls() []struct {
	Name    string
	Checker healthcheck.Checker
}

AddCheckCalls gets all the calls that were made to AddCheck. Check the length with:

len(mockedHealthChecker.AddCheckCalls())

func (*HealthCheckerMock) Handler

func (mock *HealthCheckerMock) Handler(w http.ResponseWriter, req *http.Request)

Handler calls HandlerFunc.

func (*HealthCheckerMock) HandlerCalls

func (mock *HealthCheckerMock) HandlerCalls() []struct {
	W   http.ResponseWriter
	Req *http.Request
}

HandlerCalls gets all the calls that were made to Handler. Check the length with:

len(mockedHealthChecker.HandlerCalls())

func (*HealthCheckerMock) Start

func (mock *HealthCheckerMock) Start(ctx context.Context)

Start calls StartFunc.

func (*HealthCheckerMock) StartCalls

func (mock *HealthCheckerMock) StartCalls() []struct {
	Ctx context.Context
}

StartCalls gets all the calls that were made to Start. Check the length with:

len(mockedHealthChecker.StartCalls())

func (*HealthCheckerMock) Stop

func (mock *HealthCheckerMock) Stop()

Stop calls StopFunc.

func (*HealthCheckerMock) StopCalls

func (mock *HealthCheckerMock) StopCalls() []struct {
}

StopCalls gets all the calls that were made to Stop. Check the length with:

len(mockedHealthChecker.StopCalls())

type InitialiserMock

type InitialiserMock struct {
	// DoGetHTTPServerFunc mocks the DoGetHTTPServer method.
	DoGetHTTPServerFunc func(bindAddr string, router http.Handler) service.HTTPServer

	// DoGetHealthCheckFunc mocks the DoGetHealthCheck method.
	DoGetHealthCheckFunc func(cfg *config.Config, buildTime string, gitCommit string, version string) (service.HealthChecker, error)

	// DoGetMongoDBFunc mocks the DoGetMongoDB method.
	DoGetMongoDBFunc func(ctx context.Context, cfg *config.Config) (service.DataStore, error)
	// contains filtered or unexported fields
}

InitialiserMock is a mock implementation of service.Initialiser.

func TestSomethingThatUsesInitialiser(t *testing.T) {

	// make and configure a mocked service.Initialiser
	mockedInitialiser := &InitialiserMock{
		DoGetHTTPServerFunc: func(bindAddr string, router http.Handler) service.HTTPServer {
			panic("mock out the DoGetHTTPServer method")
		},
		DoGetHealthCheckFunc: func(cfg *config.Config, buildTime string, gitCommit string, version string) (service.HealthChecker, error) {
			panic("mock out the DoGetHealthCheck method")
		},
		DoGetMongoDBFunc: func(ctx context.Context, cfg *config.Config) (service.DataStore, error) {
			panic("mock out the DoGetMongoDB method")
		},
	}

	// use mockedInitialiser in code that requires service.Initialiser
	// and then make assertions.

}

func (*InitialiserMock) DoGetHTTPServer

func (mock *InitialiserMock) DoGetHTTPServer(bindAddr string, router http.Handler) service.HTTPServer

DoGetHTTPServer calls DoGetHTTPServerFunc.

func (*InitialiserMock) DoGetHTTPServerCalls

func (mock *InitialiserMock) DoGetHTTPServerCalls() []struct {
	BindAddr string
	Router   http.Handler
}

DoGetHTTPServerCalls gets all the calls that were made to DoGetHTTPServer. Check the length with:

len(mockedInitialiser.DoGetHTTPServerCalls())

func (*InitialiserMock) DoGetHealthCheck

func (mock *InitialiserMock) DoGetHealthCheck(cfg *config.Config, buildTime string, gitCommit string, version string) (service.HealthChecker, error)

DoGetHealthCheck calls DoGetHealthCheckFunc.

func (*InitialiserMock) DoGetHealthCheckCalls

func (mock *InitialiserMock) DoGetHealthCheckCalls() []struct {
	Cfg       *config.Config
	BuildTime string
	GitCommit string
	Version   string
}

DoGetHealthCheckCalls gets all the calls that were made to DoGetHealthCheck. Check the length with:

len(mockedInitialiser.DoGetHealthCheckCalls())

func (*InitialiserMock) DoGetMongoDB

func (mock *InitialiserMock) DoGetMongoDB(ctx context.Context, cfg *config.Config) (service.DataStore, error)

DoGetMongoDB calls DoGetMongoDBFunc.

func (*InitialiserMock) DoGetMongoDBCalls

func (mock *InitialiserMock) DoGetMongoDBCalls() []struct {
	Ctx context.Context
	Cfg *config.Config
}

DoGetMongoDBCalls gets all the calls that were made to DoGetMongoDB. Check the length with:

len(mockedInitialiser.DoGetMongoDBCalls())

Jump to

Keyboard shortcuts

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