test

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FxExportContext = fx.Provide(fx.Annotate(NewContext, fx.ParamTags(`optional:"true"`, `optional:"true"`)))
View Source
var FxExportTestAWSLocalStackConfig = fx.Options(
	fx.Provide(NewLocalStackAWSConfig),
)
View Source
var TestFxExportDBGORM = fx.Provide(
	fx.Annotate(
		NewTestDBGORM,
		fx.OnStop(OnTestDBGORMStop),
	),
)
View Source
var TestModuleWorkerHandler = worker.FxExport

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 NewContext

func NewContext(dbGORM databasegorm.DB, dbBun *bun.DB, lf log.LoggerFactory) context.Context

func NewLocalStackAWSConfig added in v0.5.0

func NewLocalStackAWSConfig(tb testing.TB) (aws.Config, error)

func NewLoggerFactory

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

func NewMockAuthNGin added in v0.7.0

func NewMockAuthNGin(t *testing.T, principal middleware_gin.Principal) fx.Option

func NewTestConfig added in v0.5.0

func NewTestConfig(rootConf config.RootConfig) config.Config

func NewTestDBBun added in v0.7.0

func NewTestDBBun(conf config.Config, lf log.LoggerFactory) *bun.DB

func NewTestDBGORM added in v0.7.0

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

func NewTestDynamoDB added in v0.5.0

func NewTestDynamoDB(_ testing.TB, ctx context.Context, conf config.Config, dynamoDBClient *awsdynamodb.Client) *dynamodb.DynamoDB

func NewTestHTTPHandlerGin added in v0.7.0

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

func NewTestRedis

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

func NewTestRootConfig added in v0.5.0

func NewTestRootConfig(tb testing.TB) config.RootConfig

func OnTestDBBunStop added in v0.7.0

func OnTestDBBunStop(ctx context.Context, conf config.Config, db *bun.DB, lf log.LoggerFactory) error

func OnTestDBGORMStop added in v0.7.0

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

func OnTestDynamoDBStop added in v0.5.0

func OnTestDynamoDBStop(tb testing.TB, ctx context.Context, ddb *dynamodb.DynamoDB) error

func OnTestRedisStop

func OnTestRedisStop(redis redis.Redis) error

Types

type AcceptType added in v0.7.0

type AcceptType string
const (
	AcceptTypeJSON   AcceptType = "json"
	AcceptTypeYAML   AcceptType = "yaml"
	AcceptTypeBinary AcceptType = "binary"
	AcceptTypeText   AcceptType = "text"
	AcceptTypeSSE    AcceptType = "sse"
)

type BodyType added in v0.7.0

type BodyType string
const (
	BodyTypeText   BodyType = "text"
	BodyTypeJSON   BodyType = "json"
	BodyTypeYAML   BodyType = "yaml"
	BodyTypeBinary BodyType = "binary"
)

type FxApp

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

func FxIntegration

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

func FxIntegrationWithDBBun added in v0.7.0

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

func FxIntegrationWithDBGORM added in v0.7.0

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

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) WithDBBun added in v0.7.0

func (a *FxApp) WithDBBun() *FxApp

func (*FxApp) WithDBGORM added in v0.7.0

func (a *FxApp) WithDBGORM() *FxApp

func (*FxApp) WithHTTPHandler

func (a *FxApp) WithHTTPHandler() *FxApp

func (*FxApp) WithHTTPHandlerGin added in v0.7.0

func (a *FxApp) WithHTTPHandlerGin() *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, baseURL string, client *http.Client) *HTTPHandlerClient

func (*HTTPHandlerClient) DELETE

func (c *HTTPHandlerClient) DELETE(req RequestArgs, urlArgs ...any) *Response

func (*HTTPHandlerClient) Do

func (c *HTTPHandlerClient) Do(method string, reqArgs RequestArgs, urlArgs ...any) *Response

func (*HTTPHandlerClient) GET

func (c *HTTPHandlerClient) GET(req RequestArgs, urlArgs ...any) *Response

func (*HTTPHandlerClient) PATCH

func (c *HTTPHandlerClient) PATCH(req RequestArgs, urlArgs ...any) *Response

func (*HTTPHandlerClient) POST

func (c *HTTPHandlerClient) POST(req RequestArgs, urlArgs ...any) *Response

func (*HTTPHandlerClient) PUT added in v0.7.0

func (c *HTTPHandlerClient) PUT(req RequestArgs, urlArgs ...any) *Response

func (*HTTPHandlerClient) SetHeaders

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

type HTTPHandlerClientGin added in v0.7.0

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

HTTPHandlerClientGin is a client for testing HTTPHandler implementations.

func NewHTTPClientGin added in v0.7.0

func NewHTTPClientGin(t *testing.T, httpHandler rest.HTTPHandler) *HTTPHandlerClientGin

func (*HTTPHandlerClientGin) DELETE added in v0.7.0

func (c *HTTPHandlerClientGin) DELETE(
	urlFormat string,
	args ...any,
) *ResponseGin

func (*HTTPHandlerClientGin) Do added in v0.7.0

func (c *HTTPHandlerClientGin) Do(method, url string, body any) *ResponseGin

func (*HTTPHandlerClientGin) GET added in v0.7.0

func (c *HTTPHandlerClientGin) GET(
	urlFormat string,
	args ...any,
) *ResponseGin

func (*HTTPHandlerClientGin) PATCH added in v0.7.0

func (c *HTTPHandlerClientGin) PATCH(
	body any,
	urlFormat string,
	args ...any,
) *ResponseGin

func (*HTTPHandlerClientGin) POST added in v0.7.0

func (c *HTTPHandlerClientGin) POST(
	body any,
	urlFormat string,
	args ...any,
) *ResponseGin

func (*HTTPHandlerClientGin) SetHeaders added in v0.7.0

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

type RequestArgs added in v0.7.0

type RequestArgs struct {
	Body      any
	BodyType  BodyType
	UrlFormat string
	Headers   http.Header
	Accept    AcceptType
}

type Response

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

func NewResponse added in v0.7.0

func NewResponse(t *testing.T, rr *http.Response) *Response

func (*Response) Body added in v0.7.0

func (r *Response) Body() io.ReadCloser

func (*Response) BodyBytes added in v0.7.0

func (r *Response) BodyBytes() []byte

func (*Response) BodyString added in v0.7.0

func (r *Response) BodyString() string

func (*Response) RequireEmptyBody

func (r *Response) RequireEmptyBody()

func (*Response) RequireHeader

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

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)

func (*Response) StatusCode added in v0.7.0

func (r *Response) StatusCode() int

type ResponseGin added in v0.7.0

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

func (*ResponseGin) RequireEmptyBody added in v0.7.0

func (r *ResponseGin) RequireEmptyBody() *ResponseGin

func (*ResponseGin) RequireHeader added in v0.7.0

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

func (*ResponseGin) RequireJSONBodyAs added in v0.7.0

func (r *ResponseGin) 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 (*ResponseGin) RequireStatus added in v0.7.0

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

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
⌂ 换网址