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 ¶
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 ¶
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 ¶
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 (*Suite) Assert ¶
func (s *Suite) Assert() *assert.Assertions
Assert is a helper to access assertions directly if needed (though s.Equal(...) works too)