test

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ModuleContext = fx.Provide(fx.Annotate(NewContext, fx.ParamTags(`optional:"true"`)))
View Source
var TestModuleHTTPHandler = fx.Provide(NewTestHTTPHandler)
View Source
var TestModuleRest = rest.Module
View Source
var TestModuleWorkerHandler = worker.ModuleWorkerHandler

Functions

func CreateTestDBName

func CreateTestDBName(conf config.Config) string

func GetTestLogger

func GetTestLogger(tb testing.TB) log.Logger

func IntegrationTest

func IntegrationTest(t *testing.T)

IntegrationTest will skip if this is a testing.Short test run

func NewConfig

func NewConfig(testName string) config.Config

func NewContext

func NewContext(db database.DB, lf *log.LoggerFactory) context.Context

func NewLoggerFactory

func NewLoggerFactory(tb testing.TB, conf config.RootConfig) *log.LoggerFactory

func NewMockAuthN

func NewMockAuthN(t *testing.T, principal middleware.Principal) fx.Option

func NewTestDatabase

func NewTestDatabase(conf config.Config, lf *log.LoggerFactory) database.DB

func NewTestHTTPHandler

func NewTestHTTPHandler(conf config.Config, lf *log.LoggerFactory) rest.HTTPHandler

func NewTestRedis

func NewTestRedis(conf config.Config, lf *log.LoggerFactory) redis.Redis

func OnTestDBStop

func OnTestDBStop(conf config.Config, db database.DB, lf *log.LoggerFactory) error

func OnTestRedisStop

func OnTestRedisStop(redis redis.Redis) error

func ProvideCoreConfig

func ProvideCoreConfig(config config.Config) config.RootConfig

Types

type FxApp

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

func FxIntegration

func FxIntegration(t *testing.T, opts ...fx.Option) *FxApp

func FxIntegrationWithDB

func FxIntegrationWithDB(t *testing.T, opts ...fx.Option) *FxApp

FxIntegrationWithDB is a helper function to create an integration test with DB

func FxUnit

func FxUnit(t *testing.T, opts ...fx.Option) *FxApp

func (*FxApp) Populate

func (a *FxApp) Populate(targets ...any) *FxApp

func (*FxApp) Stop

func (a *FxApp) Stop()

func (*FxApp) Wait

func (a *FxApp) Wait() <-chan fx.ShutdownSignal

func (*FxApp) WithDB

func (a *FxApp) WithDB() *FxApp

func (*FxApp) WithHTTPHandler

func (a *FxApp) WithHTTPHandler() *FxApp

func (*FxApp) WithRedis

func (a *FxApp) WithRedis() *FxApp

func (*FxApp) WithWorkerHandler

func (a *FxApp) WithWorkerHandler() *FxApp

type HTTPHandlerClient

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

HTTPHandlerClient is a client for testing HTTPHandler implementations.

func NewHTTPClient

func NewHTTPClient(t *testing.T, httpHandler rest.HTTPHandler) *HTTPHandlerClient

func (*HTTPHandlerClient) DELETE

func (c *HTTPHandlerClient) DELETE(
	urlFormat string,
	args ...any,
) *Response

func (*HTTPHandlerClient) Do

func (c *HTTPHandlerClient) Do(method, url string, body any) *Response

func (*HTTPHandlerClient) GET

func (c *HTTPHandlerClient) GET(
	urlFormat string,
	args ...any,
) *Response

func (*HTTPHandlerClient) PATCH

func (c *HTTPHandlerClient) PATCH(
	body any,
	urlFormat string,
	args ...any,
) *Response

func (*HTTPHandlerClient) POST

func (c *HTTPHandlerClient) POST(
	body any,
	urlFormat string,
	args ...any,
) *Response

func (*HTTPHandlerClient) SetHeaders

func (c *HTTPHandlerClient) SetHeaders(headers http.Header) *HTTPHandlerClient

type Response

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

func (*Response) RequireEmptyBody

func (r *Response) RequireEmptyBody()

func (*Response) RequireHeader

func (r *Response) RequireHeader(header, value string) *Response

func (*Response) RequireJSONBodyAs

func (r *Response) RequireJSONBodyAs(target any)

RequireJSONBodyAs decodes the response body as JSON into the given body. Target must be a reference to store the deserialized body.

func (*Response) RequireStatus

func (r *Response) RequireStatus(status int) *Response

type Target

type Target interface {
	GetBase() TargetBase
}

type TargetBase

type TargetBase struct {
	fx.In

	Ctx  context.Context
	Conf config.Config

	DB    database.DB `optional:"true"`
	Redis redis.Redis `optional:"true"`

	HTTPHandler rest.HTTPHandler `optional:"true"`
}

func (TargetBase) GetBase

func (f TargetBase) GetBase() TargetBase

Jump to

Keyboard shortcuts

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