chore: minor refactor of api module

This commit is contained in:
Julien Neuhart
2023-11-22 11:54:34 +01:00
parent 71eeca96ee
commit 3a28f4a0cb
20 changed files with 1228 additions and 904 deletions
+36 -1
View File
@@ -1,6 +1,7 @@
package api
import (
"github.com/alexliesenfeld/health"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
@@ -63,7 +64,7 @@ func (ctx *ContextMock) SetCancelled(cancelled bool) {
//
// ctx := &api.ContextMock{Context: &api.Context{}}
// outputPaths := ctx.OutputPaths()
func (ctx ContextMock) OutputPaths() []string {
func (ctx *ContextMock) OutputPaths() []string {
return ctx.outputPaths
}
@@ -82,3 +83,37 @@ func (ctx *ContextMock) SetLogger(logger *zap.Logger) {
func (ctx *ContextMock) SetEchoContext(c echo.Context) {
ctx.Context.echoCtx = c
}
// RouterMock is a mock for the [Router] interface.
type RouterMock struct {
RoutesMock func() ([]Route, error)
}
func (router *RouterMock) Routes() ([]Route, error) {
return router.RoutesMock()
}
// MiddlewareProviderMock is a mock for the [MiddlewareProvider] interface.
type MiddlewareProviderMock struct {
MiddlewaresMock func() ([]Middleware, error)
}
func (provider *MiddlewareProviderMock) Middlewares() ([]Middleware, error) {
return provider.MiddlewaresMock()
}
// HealthCheckerMock is mock for the [HealthChecker] interface.
type HealthCheckerMock struct {
ChecksMock func() ([]health.CheckerOption, error)
}
func (mod *HealthCheckerMock) Checks() ([]health.CheckerOption, error) {
return mod.ChecksMock()
}
// Interface guards.
var (
_ Router = (*RouterMock)(nil)
_ MiddlewareProvider = (*MiddlewareProviderMock)(nil)
_ HealthChecker = (*HealthCheckerMock)(nil)
)