test

package
v1.452.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 82 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Environment for test.
	Environment = env.Environment("dev")

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

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

	// UserAgent for test.
	UserAgent = env.UserAgent(string(Name) + "/" + string(Version))
)

Variables

View Source
var (
	// ErrGenerate for test.
	ErrGenerate = errors.New("token error")

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

	// ErrFailed for test.
	ErrFailed = errors.New("failed")
)
View Source
var (
	//go:embed views/*.tmpl
	//go:embed static/*.txt
	Views embed.FS

	// Model for test.
	Model = PageData{
		Title: "My TODO list",
		Todos: []Todo{
			{Title: "Task 1", Done: false},
			{Title: "Task 2", Done: true},
			{Title: "Task 3", Done: true},
		},
	}
)

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(),
})

Encoder for tests.

View Source
var FS = os.NewFS()

FS used for tests.

BufferPool for test.

Functions

func Address

func Address() string

Address returns a random address for tests.

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 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 NewEd25519

func NewEd25519() *ed25519.Config

NewEd25519 for test.

func NewEncoder

func NewEncoder(err error) encoding.Encoder

NewEncoder for test.

func NewHMAC

func NewHMAC() *hmac.Config

NewHMAC for test.

func NewHook

func NewHook() *hooks.Config

NewHook for test.

func NewInputConfig

func NewInputConfig(set *cmd.FlagSet) *cmd.InputConfig

NewInputConfig for test.

func NewInsecureConfig

func NewInsecureConfig() *tls.Config

NewSecureClientConfig for test.

func NewInsecureDebugConfig

func NewInsecureDebugConfig() *debug.Config

NewInsecureDebugConfig for test.

func NewInsecureTransportConfig

func NewInsecureTransportConfig() *transport.Config

NewInsecureTransportConfig for test.

func NewLimiterConfig

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

NewLimiterConfig for test.

func NewLogger

func NewLogger(lc fx.Lifecycle) *zap.Logger

NewLogger for test.

func NewMeter

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

NewMeter for test.

func NewMeterProvider

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

NewMeterProvider for test.

func NewOTLPMeter

func NewOTLPMeter(lc fx.Lifecycle) metric.Meter

NewOTLPMeter for test.

func NewOTLPMeterProvider

func NewOTLPMeterProvider(lc fx.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 NewOutputConfig

func NewOutputConfig(set *cmd.FlagSet) *cmd.OutputConfig

NewOutputConfig for test.

func NewPGConfig

func NewPGConfig() *pg.Config

NewPGConfig for test.

func NewPrometheusMeter

func NewPrometheusMeter(lc fx.Lifecycle) metric.Meter

NewPrometheusMeter for test.

func NewPrometheusMeterProvider

func NewPrometheusMeterProvider(lc fx.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() *ssh.Config

NewSSH for test.

func NewSecureDebugConfig

func NewSecureDebugConfig() *debug.Config

NewInsecureDebugConfig 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 NewToken

func NewToken(kind, secret string) *token.Config

NewToken for test.

func NewTracer

func NewTracer(lc fx.Lifecycle, config *tracer.Config, logger *zap.Logger) trace.Tracer

NewTracer for test.

func Path

func Path(path string) string

Path for test.

func RegisterHandlers

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

RegisterHandlers for test.

func RegisterRequestHandlers

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

RegisterRequestHandlers 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 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    fx.Lifecycle
	Logger       *zap.Logger
	Tracer       *tracer.Config
	Transport    *transport.Config
	TLS          *tls.Config
	ID           id.Generator
	RoundTripper http.RoundTripper
	Meter        metric.Meter
	Generator    token.Generator
	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() trace.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 ErrFS

type ErrFS struct{}

ErrFS for test.

func (*ErrFS) IsNotExist

func (f *ErrFS) IsNotExist(err error) bool

func (*ErrFS) PathExists

func (f *ErrFS) PathExists(_ string) bool

func (*ErrFS) ReadFile

func (f *ErrFS) ReadFile(_ string) (string, error)

func (*ErrFS) WriteFile

func (*ErrFS) WriteFile(_ string, _ string, _ os.FileMode) error

type ErrProto

type ErrProto struct{}

ErrProto for test.

func (ErrProto) ProtoReflect

func (ErrProto) ProtoReflect() protoreflect.Message

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) IsEnabled

func (s *ErrServer) IsEnabled() bool

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(ctx context.Context) (context.Context, []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 NoopServer

type NoopServer struct{}

NoopServer for test.

func (*NoopServer) IsEnabled

func (s *NoopServer) IsEnabled() bool

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 PageData

type PageData struct {
	Title string
	Todos []Todo
}

PageData 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)

RestNoContent for test.

func RestError

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

RestError 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 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       fx.Lifecycle
	Meter           metric.Meter
	Verifier        token.Verifier
	Mux             *http.ServeMux
	HTTPServer      *th.Server
	GRPCServer      *tg.Server
	DebugServer     *debug.Server
	TransportConfig *transport.Config
	DebugConfig     *debug.Config
	Tracer          *tracer.Config
	Limiter         *limiter.Limiter
	Logger          *zap.Logger
	ID              id.Generator
	VerifyAuth      bool
	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
	// contains filtered or unexported fields
}

Service ...

func NewService

func NewService(verifyAuth bool) *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(...fx.ShutdownOption) error

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(ctx context.Context, token []byte) (context.Context, error)

type World

type World struct {
	*fxtest.Lifecycle
	*http.ServeMux
	*zap.Logger
	Tracer *tracer.Config
	PG     *pg.Config
	*Server
	*Client
	*events.Event
	*eh.Receiver
	cc.Cache
	Sender client.Client
	Rest   *resty.Client
}

World for test.

func NewWorld

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

NewWorld for test.

func (*World) DebugHost

func (w *World) DebugHost() string

DebugHost for world.

func (*World) EventsContext

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

EventsContext for world.

func (*World) OpenDatabase

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

OpenDatabase for world.

func (*World) Register

func (w *World) Register()

func (*World) RegisterEvents

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

RegisterEvents for world.

func (*World) ResponseWithBody

func (w *World) ResponseWithBody(ctx context.Context, protocol, address, method, path 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, protocol, address, method, path string, header http.Header, body io.Reader) (*http.Response, error)

HTTPResponseNoBody for the world.

func (*World) ServerHost

func (w *World) ServerHost() string

ServerHost for world.

type WorldOption

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

WorldOption for test.

func WithWorldCompression

func WithWorldCompression() WorldOption

WithWorldLimiter 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 WithWorldLimiter

func WithWorldLimiter(config *limiter.Config) WorldOption

WithWorldLimiter for test.

func WithWorldLogger

func WithWorldLogger(logger *zap.Logger) WorldOption

WithWorldLogger for test.

func WithWorldPGConfig

func WithWorldPGConfig(config *pg.Config) WorldOption

WithWorldRedisConfig 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 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