testutil

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil provides utility functions and types for testing.

Index

Constants

View Source
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
)
View Source
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

func GetFreeTCPPort() (int, error)

GetFreeTCPPort asks the kernel for a free open port that is ready to use.

func P added in v0.1.0

func P[T any](v T) *T

P is a utility function that returns a pointer to the value passed in.

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 NewBase added in v0.1.0

func NewBase(tb testing.TB) *Base

NewBase creates a new instance of Base.

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

func (b *Base) GetFreeTCPPort() int

GetFreeTCPPort returns a free TCP port that is ready to use.

func (*Base) UseEtcd added in v0.1.0

func (b *Base) UseEtcd(config any) *Etcd

UseEtcd is a method that initializes and starts an etcd instance for testing purposes.

type Controller

type Controller interface {
	RoutesInfo() gin.RoutesInfo
}

Controller is an interface that defines the methods for a controller.

type ControllerBase

type ControllerBase struct {
	*Base

	Router *gin.Engine
}

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 NewEtcd added in v0.1.0

func NewEtcd(base *Base) *Etcd

NewEtcd creates a new instance of Etcd.

func (*Etcd) Configure added in v0.1.0

func (e *Etcd) Configure(config any)

Configure configures the etcd instance with the provided configuration.

func (*Etcd) Info added in v0.1.0

func (e *Etcd) Info() map[string]string

Info returns information about the etcd instance.

func (*Etcd) IsAlive added in v0.1.0

func (e *Etcd) IsAlive(ctx context.Context) bool

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

func (e *Etcd) IsReady(ctx context.Context) bool

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

func (*Etcd) Name added in v0.1.0

func (e *Etcd) Name() string

Name returns the name of the etcd instance.

func (*Etcd) Start added in v0.1.0

func (e *Etcd) Start()

Start starts the etcd instance.

func (*Etcd) Stop added in v0.1.0

func (e *Etcd) Stop()

Stop stops the etcd instance.

func (*Etcd) WaitUntilReady added in v0.1.0

func (e *Etcd) WaitUntilReady(ctx context.Context) error

WaitUntilReady waits until etcd is ready.

type UnsupportedPlatformError added in v0.1.0

type UnsupportedPlatformError struct {
	OS   string
	Arch string
}

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.

Jump to

Keyboard shortcuts

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