test

package
v0.0.0-...-d55b4cd Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package test provides testing utilities for Hyperforge packages.

This package includes:

  • Suite: Base test suite with context and testify integration
  • StartPostgres / StartRedis: optional testcontainers helpers (skipped in -short; terminate via t.Cleanup). Prefer memory adapters for unit tests.

Usage:

import "github.com/chris-alexander-pop/go-hyperforge/pkg/test"

type MyTestSuite struct {
	test.Suite
}

func (s *MyTestSuite) TestSomething() {
	s.NoError(doSomething(s.Ctx))
}

func TestMySuite(t *testing.T) {
	test.Run(t, new(MyTestSuite))
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, s suite.TestingSuite)

Run is a helper function to run a suite from a standard Test* function

Example
package main

import (
	"fmt"
)

func main() {
	// Demonstrates the Run entrypoint shape (executed via TestExampleRun).
	fmt.Println("use test.Run(t, new(MySuite))")
}
Output:
use test.Run(t, new(MySuite))

func StartPostgres

func StartPostgres(t *testing.T) (string, func())

StartPostgres spins up a Postgres container for integration tests.

Skips when testing.Short() is set (containers are slow and need Docker). Termination is registered via t.Cleanup; the returned cleanup func is also safe to call explicitly (idempotent after first terminate).

Prefer in-memory adapters for unit tests; use this only when exercising a real Postgres wire protocol.

func StartRedis

func StartRedis(t *testing.T) (string, func())

StartRedis spins up a Redis container for integration tests.

Skips when testing.Short() is set (containers are slow and need Docker). Termination is registered via t.Cleanup; the returned cleanup func is also safe to call explicitly (idempotent after first terminate).

Prefer miniredis or in-memory adapters for unit tests; use this only when exercising a real Redis protocol.

Types

type Suite

type Suite struct {
	suite.Suite
	Ctx context.Context
}

Suite wraps testify's suite with additional helper methods for this project

Example
package main

import (
	"fmt"

	"github.com/chris-alexander-pop/go-hyperforge/pkg/test"
)

func main() {
	// In real tests, call test.Run from a Test* function:
	//   func TestExample(t *testing.T) { test.Run(t, new(exampleSuite)) }
	s := test.NewSuite()
	s.SetupTest()
	fmt.Println(s.Ctx != nil)
}
Output:
true

func NewSuite

func NewSuite() *Suite

NewSuite creates a new test suite

func (*Suite) Assert

func (s *Suite) Assert() *assert.Assertions

Assert is a helper to access assertions directly if needed (though s.Equal(...) works too)

func (*Suite) SetupTest

func (s *Suite) SetupTest()

SetupTest is called before each test in the suite

Jump to

Keyboard shortcuts

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