test

package
v2.167.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License: MIT Imports: 113 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ID for test.
	ID = env.ID("1234567890")

	// Name for test.
	Name = env.Name("test")

	// UserID for test.
	UserID = env.UserID(Name)

	// Version for test.
	Version = env.Version("1.0.0")

	// Environment for test.
	Environment = env.Environment("dev")
)
View Source
const DefaultTimeout = 10 * time.Minute

DefaultTimeout for test.

Variables

View Source
var (
	// ErrGenerate for test.
	ErrGenerate = errors.New("token: generation issue")

	// ErrInvalid for test.
	ErrInvalid = errors.New("token: invalid match")

	// ErrFailed for test.
	ErrFailed = errors.New("failed")

	// ErrInternal for test.
	ErrInternal = &internalError{}
)
View Source
var (
	// FileSystem for test.
	//go:embed views/*.tmpl
	//go:embed static/*.txt
	FileSystem embed.FS

	// Layout for test.
	Layout = mvc.NewLayout("views/full.tmpl", "views/partial.tmpl")

	// Model for test.
	Model = Page{
		Title: "My TODO list",
		Todos: []Todo{
			{Title: "Task 1", Done: false},
			{Title: "Task 2", Done: true},
			{Title: "Task 3", Done: true},
		},
	}
)
View Source
var (
	// FS used for tests.
	FS = os.NewFS()

	// ErrFS for tests.
	ErrFS *os.FS
)

Compressor for tests.

Content for tests.

View Source
var Encoder = encoding.NewMap(encoding.MapParams{
	JSON:        json.NewEncoder(),
	YAML:        yaml.NewEncoder(),
	TOML:        toml.NewEncoder(),
	ProtoBinary: proto.NewBinary(),
	ProtoText:   proto.NewText(),
	ProtoJSON:   proto.NewJSON(),
	GOB:         gob.NewEncoder(),
	Bytes:       bytes.NewEncoder(),
})

Encoder for tests.

View Source
var LimiterKeyMap = limiter.NewKeyMap()

LimiterKeyMap for test.

PEM for test.

Pool for test.

View Source
var UserAgent = env.UserAgent(Name.String() + "/" + Version.String())

UserAgent for test.

View Source
var Validator = config.NewValidator()

Validator for testing.

Functions

func ErrorsInternalProtobufSayHello

func ErrorsInternalProtobufSayHello(_ context.Context, _ *v1.SayHelloRequest) (*v1.SayHelloResponse, error)

ErrorsInternalProtobufSayHello for test.

func ErrorsNotMappedProtobufSayHello

func ErrorsNotMappedProtobufSayHello(_ context.Context, _ *v1.SayHelloRequest) (*v1.SayHelloResponse, error)

ErrorsNotMappedProtobufSayHello for test.

func ErrorsProtobufSayHello

func ErrorsProtobufSayHello(_ context.Context, _ *v1.SayHelloRequest) (*v1.SayHelloResponse, error)

ErrorsProtobufSayHello for test.

func FilePath

func FilePath(path string) string

FilePath for test.

func NewAES

func NewAES() *aes.Config

NewAES for test.

func NewAccessConfig added in v2.30.0

func NewAccessConfig() *access.Config

NewAccessConfig for test.

func NewCacheConfig

func NewCacheConfig(kind, compressor, encoder, secret string) *cache.Config

NewCacheConfig for test.

func NewCompressor

func NewCompressor(err error) compress.Compressor

NewCompressor for test.

func NewDebugServer added in v2.26.0

func NewDebugServer(config *debug.Config, logger *logger.Logger) *debug.Server

NewDebugServer for test.

func NewDecoder added in v2.24.0

func NewDecoder(set *flag.FlagSet) config.Decoder

NewDecoder for test.

func NewEd25519

func NewEd25519() *ed25519.Config

NewEd25519 for test.

func NewEncoder

func NewEncoder(err error) encoding.Encoder

NewEncoder for test.

func NewEvents added in v2.25.0

func NewEvents(mux *http.ServeMux, rt http.RoundTripper, id *id.UUID) (*events.Receiver, client.Client)

NewEvents for test.

func NewGRPCClientLimiter added in v2.132.0

func NewGRPCClientLimiter(lc di.Lifecycle, keys limiter.KeyMap, cfg *limiter.Config) *gl.Client

NewGRPCClientLimiter for test.

func NewGRPCServerLimiter added in v2.132.0

func NewGRPCServerLimiter(lc di.Lifecycle, keys limiter.KeyMap, cfg *limiter.Config) *gl.Server

NewGRPCServerLimiter for test.

func NewHMAC

func NewHMAC() *hmac.Config

NewHMAC for test.

func NewHTTPClientLimiter added in v2.132.0

func NewHTTPClientLimiter(lc di.Lifecycle, keys limiter.KeyMap, cfg *limiter.Config) *hl.Client

NewHTTPClientLimiter for test.

func NewHTTPServerLimiter added in v2.132.0

func NewHTTPServerLimiter(lc di.Lifecycle, keys limiter.KeyMap, cfg *limiter.Config) *hl.Server

NewHTTPServerLimiter for test.

func NewHook

func NewHook() *hooks.Config

NewHook for test.

func NewInsecureConfig

func NewInsecureConfig() *tls.Config

NewInsecureConfig for test.

func NewInsecureDebugConfig

func NewInsecureDebugConfig() *debug.Config

NewInsecureDebugConfig for test.

func NewInsecureTransportConfig

func NewInsecureTransportConfig() *transport.Config

NewInsecureTransportConfig for test.

func NewJSONLoggerConfig

func NewJSONLoggerConfig() *logger.Config

NewJSONLoggerConfig for test.

func NewLimiterConfig

func NewLimiterConfig(kind, interval string, tokens uint64) *limiter.Config

NewLimiterConfig for test.

func NewLogger

func NewLogger(lc di.Lifecycle, config *logger.Config) *logger.Logger

NewLogger for test.

func NewMeter

func NewMeter(lc di.Lifecycle, c *metrics.Config) *metrics.Meter

NewMeter for test.

func NewMeterProvider

func NewMeterProvider(lc di.Lifecycle, config *metrics.Config) metric.MeterProvider

NewMeterProvider for test.

func NewOTLPLoggerConfig

func NewOTLPLoggerConfig() *logger.Config

NewOTLPLoggerConfig for test.

func NewOTLPMeter

func NewOTLPMeter(lc di.Lifecycle) *metrics.Meter

NewOTLPMeter for test.

func NewOTLPMeterProvider

func NewOTLPMeterProvider(lc di.Lifecycle) metric.MeterProvider

NewOTLPMeterProvider for test.

func NewOTLPMetricsConfig

func NewOTLPMetricsConfig() *metrics.Config

NewOTLPMetricsConfig for test.

func NewOTLPTracerConfig

func NewOTLPTracerConfig() *tracer.Config

NewOTLPTracerConfig for test.

func NewPGConfig

func NewPGConfig() *pg.Config

NewPGConfig for test.

func NewPrometheusMeter

func NewPrometheusMeter(lc di.Lifecycle) *metrics.Meter

NewPrometheusMeter for test.

func NewPrometheusMeterProvider

func NewPrometheusMeterProvider(lc di.Lifecycle) metric.MeterProvider

NewPrometheusMeterProvider for test.

func NewPrometheusMetricsConfig

func NewPrometheusMetricsConfig() *metrics.Config

NewPrometheusMetricsConfig for test.

func NewRSA

func NewRSA() *rsa.Config

NewRSA for test.

func NewRetry

func NewRetry() *retry.Config

NewRetry for test.

func NewSSH

func NewSSH(public, private string) *ssh.Config

NewSSH for test.

func NewSecureDebugConfig

func NewSecureDebugConfig() *debug.Config

NewSecureDebugConfig for test.

func NewSecureTransportConfig

func NewSecureTransportConfig() *transport.Config

NewSecureTransportConfig for test.

func NewTLSClientConfig

func NewTLSClientConfig() *tls.Config

NewTLSClientConfig for test.

func NewTLSConfig

func NewTLSConfig(c, k string) *tls.Config

NewTLSConfig for test.

func NewTLSServerConfig

func NewTLSServerConfig() *tls.Config

NewTLSServerConfig for test.

func NewTextLoggerConfig

func NewTextLoggerConfig() *logger.Config

NewTextLoggerConfig for test.

func NewTintLoggerConfig

func NewTintLoggerConfig() *logger.Config

NewTintLoggerConfig for test.

func NewToken

func NewToken(kind string) *token.Config

NewToken for test.

func NewTracer

func NewTracer(lc di.Lifecycle, config *tracer.Config) *tracer.Tracer

NewTracer for test.

func Options

func Options() []di.Option

Options for test.

func Path

func Path(path string) string

Path for test.

func RandomAddress added in v2.93.0

func RandomAddress() string

RandomAddress address for tests.

func RandomHost added in v2.93.0

func RandomHost() string

RandomHost for tests.

func RandomNetworkHost added in v2.93.0

func RandomNetworkHost() (string, string)

RandomNetworkHost for tests.

func RegisterHandlers

func RegisterHandlers[Res any](path string, h content.Handler[Res])

RegisterHandlers for test.

func RegisterHealth added in v2.22.0

func RegisterHealth(server *server.Server)

RegisterHealth for test.

func RegisterRequestHandlers

func RegisterRequestHandlers[Req any, Res any](path string, h content.RequestHandler[Req, Res])

RegisterRequestHandlers for test.

func RestRequestProtobuf

func RestRequestProtobuf(_ context.Context, r *v1.SayHelloRequest) (*v1.SayHelloResponse, error)

RestRequestProtobuf for test.

func StatusURL

func StatusURL(status string) string

StatusURL for test.

func SuccessProtobufSayHello

func SuccessProtobufSayHello(_ context.Context, r *v1.SayHelloRequest) (*v1.SayHelloResponse, error)

SuccessProtobufSayHello for test.

func Test

func Test(ctx context.Context) meta.Value

Test retrieves sample info.

func Timeout

func Timeout() (context.Context, context.CancelFunc)

Timeout for tests.

func WithTest

func WithTest(ctx context.Context, value meta.Value) context.Context

WithTest stores sample info.

Types

type AnyTuple added in v2.10.0

type AnyTuple [2]any

AnyTuple for test.

type BadReaderWriter

type BadReaderWriter struct{}

BadReaderWriter for test.

func (*BadReaderWriter) Exists

func (rw *BadReaderWriter) Exists() bool

Exists for test.

func (*BadReaderWriter) Kind

func (rw *BadReaderWriter) Kind() string

Kind for test.

func (*BadReaderWriter) Read

func (rw *BadReaderWriter) Read() ([]byte, error)

Read for test.

func (*BadReaderWriter) Write

func (rw *BadReaderWriter) Write(_ []byte, _ os.FileMode) error

Write for test.

type Cache

type Cache struct {
	Value string
}

func (*Cache) Contains

func (c *Cache) Contains(_ string) bool

func (*Cache) Delete

func (c *Cache) Delete(_ string) error

func (*Cache) Fetch

func (c *Cache) Fetch(_ string) (string, error)

func (*Cache) FetchMulti

func (c *Cache) FetchMulti(_ []string) map[string]string

func (*Cache) Flush

func (c *Cache) Flush() error

func (*Cache) Save

func (c *Cache) Save(_, _ string, _ time.Duration) error

type Client

type Client struct {
	Lifecycle    di.Lifecycle
	Logger       *logger.Logger
	Tracer       *tracer.Config
	Transport    *transport.Config
	TLS          *tls.Config
	ID           id.Generator
	RoundTripper http.RoundTripper
	Meter        *metrics.Meter
	Generator    token.Generator
	HTTPLimiter  *hl.Client
	GRPCLimiter  *gl.Client
	Compression  bool
}

Client for test.

func (*Client) NewGRPC

func (c *Client) NewGRPC() *grpc.ClientConn

func (*Client) NewHTTP

func (c *Client) NewHTTP() *http.Client

NewHTTP client for test.

func (*Client) NewTracer

func (c *Client) NewTracer() *tracer.Tracer

NewTracer for client.

type EmptyHandler

type EmptyHandler struct{}

EmptyHandler for test.

func (*EmptyHandler) ServeHTTP

func (*EmptyHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type ErrCache

type ErrCache struct{}

func (*ErrCache) Contains

func (*ErrCache) Contains(_ string) bool

func (*ErrCache) Delete

func (*ErrCache) Delete(_ string) error

func (*ErrCache) Fetch

func (*ErrCache) Fetch(_ string) (string, error)

func (*ErrCache) FetchMulti

func (*ErrCache) FetchMulti(_ []string) map[string]string

func (*ErrCache) Flush

func (*ErrCache) Flush() error

func (*ErrCache) Save

func (*ErrCache) Save(_, _ string, _ time.Duration) error

type ErrReaderCloser

type ErrReaderCloser struct{}

ErrReaderCloser for test.

func (*ErrReaderCloser) Close

func (r *ErrReaderCloser) Close() error

Close returns ErrFailed.

func (*ErrReaderCloser) Read

func (r *ErrReaderCloser) Read(_ []byte) (int, error)

Read returns ErrFailed.

type ErrResponseWriter

type ErrResponseWriter struct {
	Code int
}

ErrResponseWriter for test.

func (*ErrResponseWriter) Header

func (w *ErrResponseWriter) Header() http.Header

Header is always empty.

func (*ErrResponseWriter) Write

func (w *ErrResponseWriter) Write([]byte) (int, error)

Write returns ErrFailed.

func (*ErrResponseWriter) WriteHeader

func (w *ErrResponseWriter) WriteHeader(code int)

WriteHeader stored the code in the field Code.

type ErrServer

type ErrServer struct{}

ErrServer for test.

func (*ErrServer) Serve

func (s *ErrServer) Serve() error

func (*ErrServer) Shutdown

func (s *ErrServer) Shutdown(_ context.Context) error

func (*ErrServer) String

func (s *ErrServer) String() string

type Generator

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

Generator for test.

func NewGenerator

func NewGenerator(token string, err error) *Generator

NewGenerator for test.

func (*Generator) Generate

func (g *Generator) Generate(_, _ string) ([]byte, error)

type InvalidMeter

type InvalidMeter struct{ embedded.Meter }

InvalidMeter for test.

func (InvalidMeter) Float64Counter

func (InvalidMeter) Float64Gauge

func (InvalidMeter) Float64Histogram

func (InvalidMeter) Int64Counter

func (InvalidMeter) Int64Gauge

func (InvalidMeter) Int64Histogram

func (InvalidMeter) RegisterCallback

type KeyValue added in v2.10.0

type KeyValue[Key, Value any] struct {
	Key   Key
	Value Value
}

KeyValue for test.

type NoopServer

type NoopServer struct{}

NoopServer for test.

func (*NoopServer) Serve

func (s *NoopServer) Serve() error

func (*NoopServer) Shutdown

func (s *NoopServer) Shutdown(_ context.Context) error

func (*NoopServer) String

func (s *NoopServer) String() string

type Page

type Page struct {
	Title string
	Todos []Todo
}

Page for test.

type Request

type Request struct {
	Name string
}

Request for test.

type Response

type Response struct {
	Meta     meta.Map
	Greeting string
}

Response for test.

func ErrorNotMappedSayHello

func ErrorNotMappedSayHello(_ context.Context, _ *Request) (*Response, error)

ErrorNotMappedSayHello for test.

func ErrorSayHello

func ErrorSayHello(_ context.Context, _ *Request) (*Response, error)

ErrorSayHello for test.

func NoContent

func NoContent(_ context.Context, _ *Request) (*Response, error)

NoContent for test.

func RestContent

func RestContent(ctx context.Context) (*Response, error)

RestContent for test.

func RestError

func RestError(_ context.Context) (*Response, error)

RestError for test.

func RestInvalidStatusCode

func RestInvalidStatusCode(ctx context.Context) (*Response, error)

RestInvalidStatusCode for test.

func RestNoContent

func RestNoContent(_ context.Context) (*Response, error)

RestNoContent for test.

func RestRequestContent

func RestRequestContent(ctx context.Context, req *Request) (*Response, error)

RestRequestContent for test.

func RestRequestError

func RestRequestError(_ context.Context, _ *Request) (*Response, error)

RestRequestError for test.

func RestRequestInvalidStatusCode

func RestRequestInvalidStatusCode(ctx context.Context, _ *Request) (*Response, error)

RestRequestInvalidStatusCode for test.

func RestRequestNoContent

func RestRequestNoContent(_ context.Context, _ *Request) (*Response, error)

RestRequestNoContent for test.

func SuccessSayHello

func SuccessSayHello(ctx context.Context, r *Request) (*Response, error)

SuccessSayHello for test.

type Server

type Server struct {
	Lifecycle       di.Lifecycle
	Meter           *metrics.Meter
	Verifier        token.Verifier
	Mux             *http.ServeMux
	HTTPServer      *th.Server
	GRPCServer      *grpc.Server
	DebugServer     *debug.Server
	TransportConfig *transport.Config
	DebugConfig     *debug.Config
	Tracer          *tracer.Config
	GRPCLimiter     *gl.Server
	HTTPLimiter     *hl.Server
	Logger          *logger.Logger
	ID              id.Generator
	RegisterHTTP    bool
	RegisterGRPC    bool
	RegisterDebug   bool
}

Server for test.

func (*Server) Register

func (s *Server) Register()

Register server.

type Service

type Service struct {
	v1.UnimplementedGreeterServiceServer
}

Service ...

func NewService

func NewService() *Service

NewService ...

func (*Service) SayHello

func (s *Service) SayHello(ctx context.Context, req *v1.SayHelloRequest) (*v1.SayHelloResponse, error)

SayHello ...

func (*Service) SayStreamHello

func (s *Service) SayStreamHello(stream v1.GreeterService_SayStreamHelloServer) error

SayStreamHello ...

type Shutdowner

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

func NewShutdowner

func NewShutdowner() *Shutdowner

func (*Shutdowner) Called

func (s *Shutdowner) Called() bool

func (*Shutdowner) Shutdown

func (s *Shutdowner) Shutdown(...di.ShutdownOption) error

type StringTuple added in v2.10.0

type StringTuple [2]string

StringTuple for test.

type Todo

type Todo struct {
	Title string
	Done  bool
}

Todo for test.

type Verifier

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

Verifier for test.

func NewVerifier

func NewVerifier(token string) *Verifier

NewVerifier for test.

func (*Verifier) Verify

func (v *Verifier) Verify(token []byte, aud string) (string, error)

type World

World for test.

func NewWorld

func NewWorld(t fxtest.TB, opts ...WorldOption) *World

NewWorld for test.

func (*World) DebugURL added in v2.73.0

func (w *World) DebugURL(protocol string) string

DebugURL for world.

func (*World) EventsContext

func (w *World) EventsContext(ctx context.Context) context.Context

EventsContext for world.

func (*World) HandleHello added in v2.73.0

func (w *World) HandleHello()

HandleHello for world.

func (*World) HealthServer added in v2.59.0

func (w *World) HealthServer(name, url string) *server.Server

HealthServer for test.

func (*World) NamedDebugURL added in v2.73.0

func (w *World) NamedDebugURL(protocol, path string) string

NamedDebugURL for world.

func (*World) NamedServerURL added in v2.73.0

func (w *World) NamedServerURL(protocol, path string) string

NamedServerURL for world.

func (*World) OpenDatabase

func (w *World) OpenDatabase() (*mssqlx.DBs, error)

OpenDatabase for world.

func (*World) PathDebugURL added in v2.73.0

func (w *World) PathDebugURL(protocol, path string) string

PathDebugURL for world.

func (*World) PathServerURL added in v2.73.0

func (w *World) PathServerURL(protocol, path string) string

PathServerURL for world.

func (*World) Register

func (w *World) Register()

Register all packages.

func (*World) RegisterEvents

func (w *World) RegisterEvents(ctx context.Context)

RegisterEvents for world.

func (*World) ResponseWithBody

func (w *World) ResponseWithBody(ctx context.Context, url, method string, header http.Header, body io.Reader) (*http.Response, string, error)

ResponseWithBody for the world.

func (*World) ResponseWithNoBody

func (w *World) ResponseWithNoBody(ctx context.Context, url, method string, header http.Header) (*http.Response, error)

ResponseWithNoBody for the world.

func (*World) ServerURL added in v2.73.0

func (w *World) ServerURL(protocol string) string

ServerURL for world.

type WorldOption

type WorldOption interface {
	// contains filtered or unexported methods
}

WorldOption for test.

func WithWorldClientLimiter added in v2.73.0

func WithWorldClientLimiter(config *limiter.Config) WorldOption

WithWorldClientLimiter for test.

func WithWorldCompression

func WithWorldCompression() WorldOption

WithWorldCompression for test.

func WithWorldDebug

func WithWorldDebug() WorldOption

WithWorldDebug for test.

func WithWorldGRPC

func WithWorldGRPC() WorldOption

WithWorldGRPC for test.

func WithWorldHTTP

func WithWorldHTTP() WorldOption

WithWorldHTTP for test.

func WithWorldLogger

func WithWorldLogger(logger *logger.Logger) WorldOption

WithWorldLogger for test.

func WithWorldLoggerConfig

func WithWorldLoggerConfig(config string) WorldOption

WithWorldLoggerConfig for test.

func WithWorldPGConfig

func WithWorldPGConfig(config *pg.Config) WorldOption

WithWorldPGConfig for test.

func WithWorldRest

func WithWorldRest() WorldOption

WithWorldRest for test.

func WithWorldRoundTripper

func WithWorldRoundTripper(rt http.RoundTripper) WorldOption

WithWorldRoundTripper for test.

func WithWorldSecure

func WithWorldSecure() WorldOption

WithWorldSecure for test.

func WithWorldServerLimiter added in v2.73.0

func WithWorldServerLimiter(config *limiter.Config) WorldOption

WithWorldServerLimiter for test.

func WithWorldTelemetry

func WithWorldTelemetry(kind string) WorldOption

WithWorldTelemetry for test.

func WithWorldToken

func WithWorldToken(generator token.Generator, verifier token.Verifier) WorldOption

WithWorldToken for test.

Directories

Path Synopsis
greet
v1

Jump to

Keyboard shortcuts

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