Documentation
¶
Overview ¶
Package testutil provides utility functions and types for testing.
Index ¶
- Constants
- func GetFreeTCPPort() (int, error)
- func P[T any](v T) *T
- type Base
- type Controller
- type ControllerBase
- type Dependency
- type Etcd
- func (e *Etcd) Configure(config any)
- func (e *Etcd) Info() map[string]string
- func (e *Etcd) IsAlive(ctx context.Context) bool
- func (e *Etcd) IsReady(ctx context.Context) bool
- func (e *Etcd) Name() string
- func (e *Etcd) Start()
- func (e *Etcd) Stop()
- func (e *Etcd) WaitUntilReady(ctx context.Context) error
- type UnsupportedPlatformError
Constants ¶
const ( // DefaultEtcdStartWaitTime is the default wait time for etcd to start. DefaultEtcdStartWaitTime = 10 * time.Second // DefaultEtcdReadyCheckInterval is the default interval for checking if etcd is ready. DefaultEtcdReadyCheckInterval = 500 * time.Millisecond // DefaultEtcdDownloadTimeout is the default timeout for downloading etcd. DefaultEtcdDownloadTimeout = 3 * time.Minute )
const (
// DefaultEtcdVersion is the default version of etcd to use if not specified.
DefaultEtcdVersion = "v3.6.0"
)
Variables ¶
This section is empty.
Functions ¶
func GetFreeTCPPort ¶ added in v0.1.0
GetFreeTCPPort asks the kernel for a free open port that is ready to use.
Types ¶
type Base ¶ added in v0.1.0
type Base struct {
Logger *slog.Logger
Dependencies map[string]Dependency
CacheDir string
// contains filtered or unexported fields
}
Base is a utility struct that provides common resources and utilities for testing.
func (*Base) ForController ¶ added in v0.1.0
func (b *Base) ForController() *ControllerBase
ForController creates a new instance of ControllerBase with a Base.
func (*Base) GetFreeTCPPort ¶ added in v0.1.0
GetFreeTCPPort returns a free TCP port that is ready to use.
type Controller ¶
type Controller interface {
RoutesInfo() gin.RoutesInfo
}
Controller is an interface that defines the methods for a controller.
type ControllerBase ¶
ControllerBase is a struct that provides a base for controllers.
func (*ControllerBase) SetupRouter ¶
func (b *ControllerBase) SetupRouter(controller Controller)
SetupRouter sets up the router for the controller.
type Dependency ¶ added in v0.1.0
type Dependency interface {
Name() string
Configure(config any)
Start()
Stop()
Info() map[string]string
}
Dependency is an interface that represents a dependency in the test environment.
type Etcd ¶ added in v0.1.0
type Etcd struct {
Base *Base
Target string
Binary string
Endpoint *string
// contains filtered or unexported fields
}
Etcd represents an etcd instance for testing purposes. It provides methods to start, stop, and check the status of the etcd instance.
func (*Etcd) Configure ¶ added in v0.1.0
Configure configures the etcd instance with the provided configuration.
func (*Etcd) IsAlive ¶ added in v0.1.0
IsAlive checks if etcd is alive. livez is a liveness endpoint of etcd sinc v3.4.29 ref. https://etcd.io/docs/v3.4/op-guide/monitoring/#health-check
func (*Etcd) IsReady ¶ added in v0.1.0
IsReady checks if etcd is ready to serve requests. readyz is a readiness endpoint of etcd since v3.4.29 ref. https://etcd.io/docs/v3.4/op-guide/monitoring/#health-check
type UnsupportedPlatformError ¶ added in v0.1.0
UnsupportedPlatformError is an error type that indicates the platform is not supported for etcd installation.
func (*UnsupportedPlatformError) Error ¶ added in v0.1.0
func (e *UnsupportedPlatformError) Error() string
UnsupportedPlatformError implements the error interface for UnsupportedPlatformError.