mock

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 {
	// DoGetAuthorisationMiddlewareFunc mocks the DoGetAuthorisationMiddleware method.
	DoGetAuthorisationMiddlewareFunc func(ctx context.Context, authorisationConfig *auth.Config) (auth.Middleware, error)

	// DoGetDataBundleSlackClientFunc mocks the DoGetDataBundleSlackClient method.
	DoGetDataBundleSlackClientFunc func(slackConfig *slack.SlackConfig, apiToken string, enabled bool) (slack.Clienter, error)

	// DoGetDatasetAPIClientFunc mocks the DoGetDatasetAPIClient method.
	DoGetDatasetAPIClientFunc func(datasetAPIURL string) datasetAPISDK.Clienter

	// 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.MongoConfig) (store.MongoDB, error)

	// DoGetPermissionsAPIClientFunc mocks the DoGetPermissionsAPIClient method.
	DoGetPermissionsAPIClientFunc func(permissionsAPIURL string) permissionsAPISDK.Clienter
	// 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{
		DoGetAuthorisationMiddlewareFunc: func(ctx context.Context, authorisationConfig *auth.Config) (auth.Middleware, error) {
			panic("mock out the DoGetAuthorisationMiddleware method")
		},
		DoGetDataBundleSlackClientFunc: func(slackConfig *slack.SlackConfig, apiToken string, enabled bool) (slack.Clienter, error) {
			panic("mock out the DoGetDataBundleSlackClient method")
		},
		DoGetDatasetAPIClientFunc: func(datasetAPIURL string) datasetAPISDK.Clienter {
			panic("mock out the DoGetDatasetAPIClient method")
		},
		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.MongoConfig) (store.MongoDB, error) {
			panic("mock out the DoGetMongoDB method")
		},
		DoGetPermissionsAPIClientFunc: func(permissionsAPIURL string) permissionsAPISDK.Clienter {
			panic("mock out the DoGetPermissionsAPIClient method")
		},
	}

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

}

func (*InitialiserMock) DoGetAuthorisationMiddleware added in v1.2.0

func (mock *InitialiserMock) DoGetAuthorisationMiddleware(ctx context.Context, authorisationConfig *auth.Config) (auth.Middleware, error)

DoGetAuthorisationMiddleware calls DoGetAuthorisationMiddlewareFunc.

func (*InitialiserMock) DoGetAuthorisationMiddlewareCalls added in v1.2.0

func (mock *InitialiserMock) DoGetAuthorisationMiddlewareCalls() []struct {
	Ctx                 context.Context
	AuthorisationConfig *auth.Config
}

DoGetAuthorisationMiddlewareCalls gets all the calls that were made to DoGetAuthorisationMiddleware. Check the length with:

len(mockedInitialiser.DoGetAuthorisationMiddlewareCalls())

func (*InitialiserMock) DoGetDataBundleSlackClient added in v1.12.0

func (mock *InitialiserMock) DoGetDataBundleSlackClient(slackConfig *slack.SlackConfig, apiToken string, enabled bool) (slack.Clienter, error)

DoGetDataBundleSlackClient calls DoGetDataBundleSlackClientFunc.

func (*InitialiserMock) DoGetDataBundleSlackClientCalls added in v1.12.0

func (mock *InitialiserMock) DoGetDataBundleSlackClientCalls() []struct {
	SlackConfig *slack.SlackConfig
	ApiToken    string
	Enabled     bool
}

DoGetDataBundleSlackClientCalls gets all the calls that were made to DoGetDataBundleSlackClient. Check the length with:

len(mockedInitialiser.DoGetDataBundleSlackClientCalls())

func (*InitialiserMock) DoGetDatasetAPIClient added in v1.3.0

func (mock *InitialiserMock) DoGetDatasetAPIClient(datasetAPIURL string) datasetAPISDK.Clienter

DoGetDatasetAPIClient calls DoGetDatasetAPIClientFunc.

func (*InitialiserMock) DoGetDatasetAPIClientCalls added in v1.3.0

func (mock *InitialiserMock) DoGetDatasetAPIClientCalls() []struct {
	DatasetAPIURL string
}

DoGetDatasetAPIClientCalls gets all the calls that were made to DoGetDatasetAPIClient. Check the length with:

len(mockedInitialiser.DoGetDatasetAPIClientCalls())

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 added in v1.0.0

func (mock *InitialiserMock) DoGetMongoDB(ctx context.Context, cfg config.MongoConfig) (store.MongoDB, error)

DoGetMongoDB calls DoGetMongoDBFunc.

func (*InitialiserMock) DoGetMongoDBCalls added in v1.0.0

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

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

len(mockedInitialiser.DoGetMongoDBCalls())

func (*InitialiserMock) DoGetPermissionsAPIClient added in v1.12.0

func (mock *InitialiserMock) DoGetPermissionsAPIClient(permissionsAPIURL string) permissionsAPISDK.Clienter

DoGetPermissionsAPIClient calls DoGetPermissionsAPIClientFunc.

func (*InitialiserMock) DoGetPermissionsAPIClientCalls added in v1.12.0

func (mock *InitialiserMock) DoGetPermissionsAPIClientCalls() []struct {
	PermissionsAPIURL string
}

DoGetPermissionsAPIClientCalls gets all the calls that were made to DoGetPermissionsAPIClient. Check the length with:

len(mockedInitialiser.DoGetPermissionsAPIClientCalls())

Jump to

Keyboard shortcuts

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