testutil

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package testutil provides utility functions and types for testing.

Index

Constants

This section is empty.

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.

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 TestLogWriter added in v0.1.26

type TestLogWriter struct {
	T testing.TB
}

TestLogWriter is an io.Writer that writes to the test log. This is useful for capturing logs in tests, especially when working with libraries that write to io.Writer (e.g., slog.TextHandler).

func (TestLogWriter) Write added in v0.1.26

func (w TestLogWriter) Write(p []byte) (int, error)

Write implements io.Writer by logging to the test.

Jump to

Keyboard shortcuts

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