service

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExternalServiceList added in v0.3.0

type ExternalServiceList struct {
	Vault       bool
	S3Uploaded  bool
	HealthCheck bool
	Init        Initialiser
}

ExternalServiceList holds the initialiser and initialisation state of external services.

func NewServiceList added in v0.3.0

func NewServiceList(initialiser Initialiser) *ExternalServiceList

NewServiceList creates a new service list with the provided initialiser

func (*ExternalServiceList) GetHTTPServer added in v0.3.0

func (e *ExternalServiceList) GetHTTPServer(bindAddr string, router http.Handler) HTTPServer

GetHTTPServer creates an http server

func (*ExternalServiceList) GetHealthCheck added in v0.3.0

func (e *ExternalServiceList) GetHealthCheck(cfg *config.Config, buildTime, gitCommit, version string) (HealthChecker, error)

GetHealthCheck creates a healthcheck with versionInfo and sets teh HealthCheck flag to true

func (*ExternalServiceList) GetS3Uploaded added in v0.3.0

func (e *ExternalServiceList) GetS3Uploaded(ctx context.Context, cfg *config.Config) (upload.S3Clienter, error)

GetS3Uploaded creates a S3 client and sets the S3Uploaded flag to true

func (*ExternalServiceList) GetVault added in v0.3.0

GetVault creates a Vault client and sets the Vault flag to true

type HTTPServer added in v0.3.0

type HTTPServer interface {
	ListenAndServe() error
	Shutdown(ctx context.Context) error
}

HTTPServer defines the required methods from the HTTP server

type HTTPServerMock added in v0.3.0

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 HTTPServer.

    func TestSomethingThatUsesHTTPServer(t *testing.T) {

        // make and configure a mocked 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 HTTPServer
        // and then make assertions.

    }

func (*HTTPServerMock) ListenAndServe added in v0.3.0

func (mock *HTTPServerMock) ListenAndServe() error

ListenAndServe calls ListenAndServeFunc.

func (*HTTPServerMock) ListenAndServeCalls added in v0.3.0

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 added in v0.3.0

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

Shutdown calls ShutdownFunc.

func (*HTTPServerMock) ShutdownCalls added in v0.3.0

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 HealthChecker added in v0.3.0

type HealthChecker interface {
	Handler(w http.ResponseWriter, req *http.Request)
	Start(ctx context.Context)
	Stop()
	AddCheck(name string, checker healthcheck.Checker) (err error)
}

HealthChecker defines the required methods from Healthcheck

type HealthCheckerMock added in v0.3.0

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 HealthChecker.

    func TestSomethingThatUsesHealthChecker(t *testing.T) {

        // make and configure a mocked 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 HealthChecker
        // and then make assertions.

    }

func (*HealthCheckerMock) AddCheck added in v0.3.0

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

AddCheck calls AddCheckFunc.

func (*HealthCheckerMock) AddCheckCalls added in v0.3.0

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 added in v0.3.0

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

Handler calls HandlerFunc.

func (*HealthCheckerMock) HandlerCalls added in v0.3.0

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 added in v0.3.0

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

Start calls StartFunc.

func (*HealthCheckerMock) StartCalls added in v0.3.0

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 added in v0.3.0

func (mock *HealthCheckerMock) Stop()

Stop calls StopFunc.

func (*HealthCheckerMock) StopCalls added in v0.3.0

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

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

len(mockedHealthChecker.StopCalls())

type Init added in v0.3.0

type Init struct{}

Init implements the Initialiser interface to initialise dependencies

func (*Init) DoGetHTTPServer added in v0.3.0

func (e *Init) DoGetHTTPServer(bindAddr string, router http.Handler) HTTPServer

DoGetHTTPServer creates an HTTP Server with the provided bind address and router

func (*Init) DoGetHealthCheck added in v0.3.0

func (e *Init) DoGetHealthCheck(cfg *config.Config, buildTime, gitCommit, version string) (HealthChecker, error)

DoGetHealthCheck creates a healthcheck with versionInfo

func (*Init) DoGetS3Uploaded added in v0.3.0

func (e *Init) DoGetS3Uploaded(ctx context.Context, cfg *config.Config) (upload.S3Clienter, error)

DoGetS3Uploaded returns a S3Client

func (*Init) DoGetVault added in v0.3.0

func (e *Init) DoGetVault(ctx context.Context, cfg *config.Config) (upload.VaultClienter, error)

DoGetVault returns a VaultClient unless encryption is disabled

If cfg.EncryptionDisabled is true then the function returns nil

type Initialiser added in v0.3.0

type Initialiser interface {
	DoGetHTTPServer(bindAddr string, router http.Handler) HTTPServer
	DoGetVault(ctx context.Context, cfg *config.Config) (upload.VaultClienter, error)
	DoGetHealthCheck(cfg *config.Config, buildTime, gitCommit, version string) (HealthChecker, error)
	DoGetS3Uploaded(ctx context.Context, cfg *config.Config) (upload.S3Clienter, error)
}

Initialiser defines the methods to initialise external services

type InitialiserMock added in v0.3.0

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

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

	// DoGetS3UploadedFunc mocks the DoGetS3Uploaded method.
	DoGetS3UploadedFunc func(ctx context.Context, cfg *config.Config) (upload.S3Clienter, error)

	// DoGetVaultFunc mocks the DoGetVault method.
	DoGetVaultFunc func(ctx context.Context, cfg *config.Config) (upload.VaultClienter, error)
	// contains filtered or unexported fields
}

InitialiserMock is a mock implementation of Initialiser.

    func TestSomethingThatUsesInitialiser(t *testing.T) {

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

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

    }

func (*InitialiserMock) DoGetHTTPServer added in v0.3.0

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

DoGetHTTPServer calls DoGetHTTPServerFunc.

func (*InitialiserMock) DoGetHTTPServerCalls added in v0.3.0

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 added in v0.3.0

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

DoGetHealthCheck calls DoGetHealthCheckFunc.

func (*InitialiserMock) DoGetHealthCheckCalls added in v0.3.0

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) DoGetS3Uploaded added in v0.3.0

func (mock *InitialiserMock) DoGetS3Uploaded(ctx context.Context, cfg *config.Config) (upload.S3Clienter, error)

DoGetS3Uploaded calls DoGetS3UploadedFunc.

func (*InitialiserMock) DoGetS3UploadedCalls added in v0.3.0

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

DoGetS3UploadedCalls gets all the calls that were made to DoGetS3Uploaded. Check the length with:

len(mockedInitialiser.DoGetS3UploadedCalls())

func (*InitialiserMock) DoGetVault added in v0.3.0

func (mock *InitialiserMock) DoGetVault(ctx context.Context, cfg *config.Config) (upload.VaultClienter, error)

DoGetVault calls DoGetVaultFunc.

func (*InitialiserMock) DoGetVaultCalls added in v0.3.0

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

DoGetVaultCalls gets all the calls that were made to DoGetVault. Check the length with:

len(mockedInitialiser.DoGetVaultCalls())

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service contains all the configs, server and clients to run the dp-upload-service API

func Run

func Run(ctx context.Context, serviceList *ExternalServiceList, buildTime, gitCommit, version string, svcErrors chan error) (*Service, error)

Run the service

func (*Service) Close

func (svc *Service) Close(ctx context.Context) error

Close gracefully shuts the service down in the required order, with timeout

Jump to

Keyboard shortcuts

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