Documentation
¶
Index ¶
- Constants
- func CleanupAllTestContainers(ctx context.Context) error
- func ContainerLabels(t TestingT) map[string]string
- func DockerClient(t TestingT) *client.Client
- func FindFreePort() (string, error)
- func HTTPClient() *http.Client
- func UniqueContainerName(t TestingT, prefix string) string
- func WaitForServer(url string, timeout time.Duration) error
- func WaitForShutdown(done <-chan error, timeout time.Duration) error
- type DefraTestConfig
- type ServerConfig
- type StartServer
- type StatusResponse
- type TestingT
Constants ¶
const (
// CleanupLabel is used to identify resources created by tests
CleanupLabel = "shelf-test"
)
Variables ¶
This section is empty.
Functions ¶
func CleanupAllTestContainers ¶
CleanupAllTestContainers removes ALL shelf-test containers. Use sparingly - mainly for cleaning up after interrupted test runs.
func ContainerLabels ¶
ContainerLabels returns labels to apply to test containers. These labels are used for cleanup.
func DockerClient ¶
DockerClient creates a Docker client and registers cleanup for test containers. It cleans up any orphaned containers from previous interrupted runs with the same test name.
func FindFreePort ¶
FindFreePort finds an available TCP port and returns it as a string.
func HTTPClient ¶
HTTPClient returns an HTTP client for making requests.
func UniqueContainerName ¶
UniqueContainerName generates a unique container name for a test. Format: shelf-test-<testname>-<random>
func WaitForServer ¶
WaitForServer polls the /api/status endpoint until DefraDB is healthy.
Types ¶
type DefraTestConfig ¶
DefraTestConfig holds DefraDB container configuration without importing defra package. This breaks the import cycle between testutil and defra.
type ServerConfig ¶
type ServerConfig struct {
Host string
Port string
DefraDataPath string
ConfigFile string
DefraConfig DefraTestConfig
Logger *slog.Logger
}
ServerConfig returns configuration values for creating a test server. This avoids importing the server package directly.
func NewServerConfig ¶
func NewServerConfig(t *testing.T) ServerConfig
NewServerConfig creates configuration for a test server with unique ports.
func (ServerConfig) URL ¶
func (c ServerConfig) URL() string
URL returns the server URL for the given config.
type StartServer ¶
type StartServer struct {
Cancel context.CancelFunc
Done <-chan error
}
StartServer is a helper type for managing server lifecycle in tests. Usage:
cfg := testutil.NewServerConfig(t)
srv, err := server.New(server.Config{...from cfg...})
starter := testutil.StartServer{Cancel: cancel, Done: done}
t.Cleanup(func() { starter.Stop() })
func (*StartServer) Stop ¶
func (s *StartServer) Stop()
Stop cancels the server context and waits for shutdown.
type StatusResponse ¶
type StatusResponse struct {
Server string `json:"server"`
Providers struct {
OCR []string `json:"ocr"`
LLM []string `json:"llm"`
} `json:"providers"`
Defra struct {
Container string `json:"container"`
Health string `json:"health"`
URL string `json:"url"`
} `json:"defra"`
}
StatusResponse matches the server's StatusResponse structure.
func GetStatus ¶
func GetStatus(url string) (*StatusResponse, error)
GetStatus fetches the /api/status endpoint and returns the parsed response.