helpers

package
v1.0.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CleanupManager

type CleanupManager struct {
	// contains filtered or unexported fields
}

CleanupManager orchestrates resource cleanup for tests

func NewCleanupManager

func NewCleanupManager(t *testing.T, ctx *TestContext) *CleanupManager

NewCleanupManager creates a new cleanup manager

func (*CleanupManager) AssertNoLeaks

func (cm *CleanupManager) AssertNoLeaks()

AssertNoLeaks checks for resource leaks after cleanup - No running Docker containers with devnet labels - No processes from test home directory - No leftover files in temp directory

func (*CleanupManager) Cleanup

func (cm *CleanupManager) Cleanup()

Cleanup performs cleanup of all tracked resources Resources are cleaned up in order: containers → processes → directories

func (*CleanupManager) CleanupDevnet

func (cm *CleanupManager) CleanupDevnet() error

CleanupDevnet performs devnet-specific cleanup - Stops all running validators - Removes devnet data directory - Stops Docker containers matching devnet patterns

func (*CleanupManager) TrackContainer

func (cm *CleanupManager) TrackContainer(container testcontainers.Container)

TrackContainer registers a Docker container for cleanup

func (*CleanupManager) TrackDirectory

func (cm *CleanupManager) TrackDirectory(dir string)

TrackDirectory registers a directory for cleanup

func (*CleanupManager) TrackProcess

func (cm *CleanupManager) TrackProcess(process *os.Process)

TrackProcess registers a process for cleanup

type CommandResult

type CommandResult struct {
	ExitCode int           // Command exit code
	Stdout   string        // Standard output
	Stderr   string        // Standard error
	Duration time.Duration // Execution duration
	Error    error         // Error if command failed to start
}

CommandResult captures the output and metadata from a command execution

func (*CommandResult) Failed

func (r *CommandResult) Failed() bool

Failed returns true if the command exited with non-zero code

func (*CommandResult) Success

func (r *CommandResult) Success() bool

Success returns true if the command exited with code 0

type CommandRunner

type CommandRunner struct {
	// contains filtered or unexported fields
}

CommandRunner executes devnet-builder commands with various options

func NewCommandRunner

func NewCommandRunner(t *testing.T, ctx *TestContext) *CommandRunner

NewCommandRunner creates a new command runner for the given test context

func (*CommandRunner) AssertStderrContains

func (r *CommandRunner) AssertStderrContains(result *CommandResult, expected string)

AssertStderrContains asserts that stderr contains the expected string

func (*CommandRunner) AssertStdoutContains

func (r *CommandRunner) AssertStdoutContains(result *CommandResult, expected string)

AssertStdoutContains asserts that stdout contains the expected string

func (*CommandRunner) ExpectExitCode

func (r *CommandRunner) ExpectExitCode(expectedCode int, args ...string) *CommandResult

ExpectExitCode executes a command and asserts the exit code matches

func (*CommandRunner) MustFail

func (r *CommandRunner) MustFail(args ...string) *CommandResult

MustFail executes a command and fails the test if it succeeds

func (*CommandRunner) MustRun

func (r *CommandRunner) MustRun(args ...string) *CommandResult

MustRun executes a command and fails the test if it doesn't succeed

func (*CommandRunner) Run

func (r *CommandRunner) Run(args ...string) *CommandResult

Run executes a devnet-builder command and returns the result Example: Run("deploy", "--validators", "4", "--mode", "docker")

func (*CommandRunner) RunWithContext

func (r *CommandRunner) RunWithContext(ctx context.Context, args ...string) *CommandResult

RunWithContext executes a command with a custom context

func (*CommandRunner) RunWithTimeout

func (r *CommandRunner) RunWithTimeout(timeout time.Duration, args ...string) *CommandResult

RunWithTimeout executes a command with a custom timeout

func (*CommandRunner) StartBackground

func (r *CommandRunner) StartBackground(args ...string) *exec.Cmd

StartBackground starts a command in the background and returns the process Caller is responsible for stopping the process (registered as cleanup)

func (*CommandRunner) WaitForOutput

func (r *CommandRunner) WaitForOutput(timeout time.Duration, pollInterval time.Duration, args []string, expected string) error

WaitForOutput polls command output until expected string appears or timeout

type GitHubAsset

type GitHubAsset struct {
	Name        string `json:"name"`
	DownloadURL string `json:"browser_download_url"`
	Size        int    `json:"size"`
}

GitHubAsset represents a release asset

type GitHubRelease

type GitHubRelease struct {
	TagName     string        `json:"tag_name"`
	Name        string        `json:"name"`
	Draft       bool          `json:"draft"`
	Prerelease  bool          `json:"prerelease"`
	CreatedAt   string        `json:"created_at"`
	PublishedAt string        `json:"published_at"`
	Assets      []GitHubAsset `json:"assets"`
}

GitHubRelease represents a GitHub release

type MockGitHubAPI

type MockGitHubAPI struct {
	// contains filtered or unexported fields
}

MockGitHubAPI provides a mock GitHub API server for testing This eliminates dependency on actual GitHub API and allows testing version/release logic

func NewMockGitHubAPI

func NewMockGitHubAPI(t *testing.T) *MockGitHubAPI

NewMockGitHubAPI creates a new mock GitHub API server

func (*MockGitHubAPI) AddDefaultReleases

func (m *MockGitHubAPI) AddDefaultReleases()

AddDefaultReleases adds common test releases

func (*MockGitHubAPI) AddRelease

func (m *MockGitHubAPI) AddRelease(release GitHubRelease)

AddRelease adds a mock release to the API

func (*MockGitHubAPI) ClearReleases

func (m *MockGitHubAPI) ClearReleases()

ClearReleases removes all mock releases

func (*MockGitHubAPI) GetLatestRelease

func (m *MockGitHubAPI) GetLatestRelease() *GitHubRelease

GetLatestRelease returns the latest non-prerelease release

func (*MockGitHubAPI) GetReleaseByTag

func (m *MockGitHubAPI) GetReleaseByTag(tag string) *GitHubRelease

GetReleaseByTag returns a release by tag name

func (*MockGitHubAPI) SimulateAPIError

func (m *MockGitHubAPI) SimulateAPIError(statusCode int, message string)

SimulateAPIError simulates a GitHub API error response

func (*MockGitHubAPI) SimulateRateLimit

func (m *MockGitHubAPI) SimulateRateLimit()

SimulateRateLimit simulates GitHub API rate limiting

func (*MockGitHubAPI) URL

func (m *MockGitHubAPI) URL() string

URL returns the base URL of the mock GitHub API server

type MockSnapshotServer

type MockSnapshotServer struct {
	// contains filtered or unexported fields
}

MockSnapshotServer provides a mock HTTP server for snapshot downloads This eliminates the 2-10 minute download time in tests by serving local fixtures

func NewMockSnapshotServer

func NewMockSnapshotServer(t *testing.T) *MockSnapshotServer

NewMockSnapshotServer creates a new mock snapshot server The server serves snapshot files from tests/e2e/testdata/snapshots/

func (*MockSnapshotServer) GetRequestCount

func (m *MockSnapshotServer) GetRequestCount(filename string) int

GetRequestCount returns the number of requests received for a specific file Useful for verifying caching behavior

func (*MockSnapshotServer) SimulateDownloadFailure

func (m *MockSnapshotServer) SimulateDownloadFailure(filename string)

SimulateDownloadFailure simulates a download failure (e.g., 500 error)

func (*MockSnapshotServer) SimulateNetworkTimeout

func (m *MockSnapshotServer) SimulateNetworkTimeout(filename string)

SimulateNetworkTimeout simulates a network timeout by closing connection

func (*MockSnapshotServer) SimulateSlowDownload

func (m *MockSnapshotServer) SimulateSlowDownload(filename string, delayMS int)

SimulateSlowDownload simulates a slow download by adding delay

func (*MockSnapshotServer) SnapshotURL

func (m *MockSnapshotServer) SnapshotURL(filename string) string

SnapshotURL returns the full URL for a snapshot file Example: SnapshotURL("mainnet-snapshot.tar.gz") → "http://localhost:xxxxx/mainnet-snapshot.tar.gz"

func (*MockSnapshotServer) URL

func (m *MockSnapshotServer) URL() string

URL returns the base URL of the mock server

func (*MockSnapshotServer) WithCustomHandler

func (m *MockSnapshotServer) WithCustomHandler(pattern string, handler http.HandlerFunc)

WithCustomHandler allows setting a custom HTTP handler for specific paths This is useful for testing error scenarios (e.g., network failures, corrupted downloads)

type StateValidator

type StateValidator struct {
	// contains filtered or unexported fields
}

StateValidator validates devnet state (filesystem, processes, Docker containers)

func NewStateValidator

func NewStateValidator(t *testing.T, ctx *TestContext) *StateValidator

NewStateValidator creates a new state validator

func (*StateValidator) AssertDirectoryExists

func (v *StateValidator) AssertDirectoryExists(subpath string)

AssertDirectoryExists asserts that a directory exists

func (*StateValidator) AssertDirectoryNotExists

func (v *StateValidator) AssertDirectoryNotExists(subpath string)

AssertDirectoryNotExists asserts that a directory does not exist

func (*StateValidator) AssertDockerContainerExists

func (v *StateValidator) AssertDockerContainerExists(containerName string)

AssertDockerContainerExists asserts that a Docker container exists (running or stopped)

func (*StateValidator) AssertDockerContainerNotExists

func (v *StateValidator) AssertDockerContainerNotExists(containerName string)

AssertDockerContainerNotExists asserts that a Docker container does not exist

func (*StateValidator) AssertDockerContainerNotRunning

func (v *StateValidator) AssertDockerContainerNotRunning(containerName string)

AssertDockerContainerNotRunning asserts that a Docker container is not running

func (*StateValidator) AssertDockerContainerRunning

func (v *StateValidator) AssertDockerContainerRunning(containerName string)

AssertDockerContainerRunning asserts that a Docker container is running

func (*StateValidator) AssertFileContains

func (v *StateValidator) AssertFileContains(subpath string, expected string)

AssertFileContains asserts that a file contains the expected string

func (*StateValidator) AssertFileExists

func (v *StateValidator) AssertFileExists(subpath string)

AssertFileExists asserts that a file exists at the given path

func (*StateValidator) AssertFileNotExists

func (v *StateValidator) AssertFileNotExists(subpath string)

AssertFileNotExists asserts that a file does not exist at the given path

func (*StateValidator) AssertJSONFileValid

func (v *StateValidator) AssertJSONFileValid(subpath string)

AssertJSONFileValid asserts that a file contains valid JSON

func (*StateValidator) AssertPortListening

func (v *StateValidator) AssertPortListening(port int)

AssertPortListening asserts that a port is listening

func (*StateValidator) AssertPortNotListening

func (v *StateValidator) AssertPortNotListening(port int)

AssertPortNotListening asserts that a port is not listening

func (*StateValidator) AssertProcessNotRunning

func (v *StateValidator) AssertProcessNotRunning(pid int)

AssertProcessNotRunning asserts that a process with the given PID is not running

func (*StateValidator) AssertProcessRunning

func (v *StateValidator) AssertProcessRunning(pid int)

AssertProcessRunning asserts that a process with the given PID is running

func (*StateValidator) AssertValidatorCount

func (v *StateValidator) AssertValidatorCount(expected int)

AssertValidatorCount asserts the number of validator directories

func (*StateValidator) GetValidatorDirs

func (v *StateValidator) GetValidatorDirs() []string

GetValidatorDirs returns all validator directory paths

func (*StateValidator) ReadPIDFile

func (v *StateValidator) ReadPIDFile(pidFile string) int

ReadPIDFile reads a PID from a PID file

func (*StateValidator) WaitForDockerContainer

func (v *StateValidator) WaitForDockerContainer(containerName string, timeout time.Duration) error

WaitForDockerContainer waits for a Docker container to be running (with timeout)

func (*StateValidator) WaitForFile

func (v *StateValidator) WaitForFile(subpath string, timeout time.Duration) error

WaitForFile waits for a file to exist (with timeout)

func (*StateValidator) WaitForNodeReady

func (v *StateValidator) WaitForNodeReady(nodeIndex int, timeout time.Duration) (int, error)

WaitForNodeReady waits for a node to be fully ready (process running + RPC responding)

func (*StateValidator) WaitForPortListening

func (v *StateValidator) WaitForPortListening(port int, timeout time.Duration) error

WaitForPortListening waits for a port to start listening (with timeout)

func (*StateValidator) WaitForProcess

func (v *StateValidator) WaitForProcess(pidFile string, timeout time.Duration) (int, error)

WaitForProcess waits for a process to start (with timeout)

func (*StateValidator) WaitForRPC

func (v *StateValidator) WaitForRPC(port int, timeout time.Duration) error

WaitForRPC waits for RPC endpoint to be ready (responding to status query) This ensures the node is fully started and can accept RPC requests

type TestContext

type TestContext struct {
	HomeDir    string            // Isolated home directory for this test
	BinaryPath string            // Path to devnet-builder binary
	ConfigPath string            // Path to test config file (optional)
	Env        map[string]string // Environment variables for test
	// contains filtered or unexported fields
}

TestContext provides an isolated test environment with automatic cleanup

func NewTestContext

func NewTestContext(t *testing.T) *TestContext

NewTestContext creates a new isolated test environment - Creates a temporary home directory (automatically cleaned up via t.TempDir()) - Sets up environment variables - Registers cleanup handlers

func (*TestContext) AddCleanup

func (ctx *TestContext) AddCleanup(cleanup func())

AddCleanup registers a cleanup function to run when test completes Cleanup functions run in reverse order (LIFO)

func (*TestContext) CreateSubDir

func (ctx *TestContext) CreateSubDir(subpath string) string

CreateSubDir creates a subdirectory within the test home directory

func (*TestContext) FileExists

func (ctx *TestContext) FileExists(subpath string) bool

FileExists checks if a file exists within the test home directory

func (*TestContext) GetEnv

func (ctx *TestContext) GetEnv() []string

GetEnv returns all environment variables as a slice

func (*TestContext) ReadFile

func (ctx *TestContext) ReadFile(subpath string) []byte

ReadFile reads a file from the test home directory

func (*TestContext) RunCleanups

func (ctx *TestContext) RunCleanups()

RunCleanups executes all registered cleanup functions Called automatically via t.Cleanup(), but can be called manually if needed

func (*TestContext) WithConfig

func (ctx *TestContext) WithConfig(configPath string) *TestContext

WithConfig sets a test configuration file path

func (*TestContext) WithEnv

func (ctx *TestContext) WithEnv(key, value string) *TestContext

WithEnv adds or overrides an environment variable

func (*TestContext) WriteFile

func (ctx *TestContext) WriteFile(subpath string, content []byte) string

WriteFile writes content to a file within the test home directory

Jump to

Keyboard shortcuts

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