testhelpers

package
v0.0.73 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testhelpers provides common testing utilities for devloop.

This package contains shared testing functionality used across devloop's test suite: - Test context management with automatic cleanup - Network port allocation for testing - Temporary directory management - Test timeout enforcement

Test Context

WithTestContext provides a standardized way to run tests with temporary directories:

func TestMyFunction(t *testing.T) {
	testhelpers.WithTestContext(t, 5*time.Second, func(t *testing.T, tmpDir string) {
		// Test code here runs in a temporary directory
		// Automatic cleanup happens when test completes
	})
}

Port Allocation

FindAvailablePort helps with network testing:

port, err := testhelpers.FindAvailablePort()
if err != nil {
	t.Fatal(err)
}
// Use port for test server

Features

- Automatic temporary directory creation and cleanup - Test timeout enforcement to prevent hanging tests - Dynamic port allocation for network tests - Consistent test environment setup

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAvailablePort

func FindAvailablePort() (int, error)

FindAvailablePort finds an available port for testing purposes. Returns a port number that is currently available for binding.

func WithTestContext

func WithTestContext(t *testing.T, timeout time.Duration, testFunc func(t *testing.T, tmpDir string))

WithTestContext creates a temporary directory for a test, changes the CWD to it, and ensures everything is cleaned up afterward. It also enforces a timeout.

Types

This section is empty.

Jump to

Keyboard shortcuts

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