test

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

README

Integration Tests

This directory contains integration tests, test scripts, and test helpers designed to provide comprehensive end-to-end testing capabilities for the application.

Overview

Our integration testing framework extends the standard testscript functionality with custom commands and enhancements tailored to our specific testing needs. These tests validate the complete application workflow, from binary execution to complex text processing scenarios.

Documentation

For comprehensive information on testing methodologies, setup, and best practices, please refer to our testing documentation.

Custom Testscript Commands

We have extended the standard testscript command set with several custom commands to enhance testing capabilities:

Text Processing Commands
txtproc - Advanced Text Processing

Provides flexible text processing capabilities for manipulating test files and outputs.

Available Operations:

Operation Description Usage
replace Replace literal text strings txtproc replace 'old_text' 'new_text' input.txt output.txt
replace-regex Replace using regular expressions txtproc replace-regex 'pattern' 'replacement' input.txt output.txt
remove-lines Remove lines matching a pattern txtproc remove-lines 'pattern' input.txt output.txt
remove-regex Remove text matching regex pattern txtproc remove-regex 'pattern' input.txt output.txt
extract-lines Extract lines matching a pattern txtproc extract-lines 'pattern' input.txt output.txt
extract-regex Extract text matching regex pattern txtproc extract-regex 'pattern' input.txt output.txt

Examples:

# Replace version numbers in output
txtproc replace 'v1.0.0' 'v2.0.0' app_output.txt expected.txt

# Extract error messages using regex
txtproc extract-regex 'ERROR: .*' log.txt errors.txt

# Remove debug lines from output
txtproc remove-lines 'DEBUG:' verbose_output.txt clean_output.txt
Utility Commands
sleep - Execution Delay

Pauses test execution for a specified duration, useful for timing-sensitive tests or waiting for asynchronous operations.

Usage:

sleep <duration>

Supported Duration Formats:

  • ns - nanoseconds
  • us - microseconds
  • ms - milliseconds
  • s - seconds
  • m - minutes
  • h - hours

Examples:

# Wait for 1 second
sleep 1s

# Wait for 500 milliseconds
sleep 500ms

# Wait for 2 minutes
sleep 2m

# Wait for background process
sleep 100ms
dlv - Debug Integration

Runs the specified binary with Delve debugger support for interactive debugging during tests.

Usage:

dlv <app_name>

Prerequisites:

  • Binary must be compiled with debug headers (-gcflags="all=-N -l")
  • Delve must be installed in the testing environment

Examples:

# Debug the main application
dlv launchr

Command Overrides

Enhanced kill Command

We override the default testscript kill command to provide broader signal support beyond the standard implementation.

Enhanced Features:

  • Support for additional POSIX signals
  • Cross-platform signal handling
  • Improved process termination reliability

Usage:

# Standard termination
kill bg-name

# Graceful shutdown with SIGTERM
kill -TERM bg-name

Writing Integration Tests

Basic Test Structure

Integration tests use the txtar format to bundle test scripts with their required files. See examples.

Best Practices
Test Organization
  • Group related tests in logical directories
  • Use descriptive test file names
  • Include both positive and negative test cases
File Management
  • Keep test files small and focused
  • Use meaningful fixture names
  • Clean up temporary files when possible
Error Handling
  • Test error conditions explicitly
  • Verify error messages and exit codes
  • Use ! exec for commands expected to fail
Performance Considerations
  • Use sleep judiciously to avoid slow tests
  • Prefer deterministic waits over arbitrary delays
  • Consider using make test-short for development

Contributing

When adding new integration tests:

  1. Follow the existing naming conventions
  2. Include comprehensive test documentation
  3. Test on multiple platforms when relevant
  4. Add appropriate error handling
  5. Update this README if adding new custom commands

Documentation

Overview

Package test contains functionality to test the application with testscript.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmdDlv

func CmdDlv(ts *testscript.TestScript, neg bool, args []string)

CmdDlv implements a custom testscript command for debugging with Delve

func CmdKill

func CmdKill(ts *testscript.TestScript, neg bool, args []string)

CmdKill is an override of [github.com/rogpeppe/go-internal/testscript.(*TestScript).cmdKill]. It supports more kill signals than the original.

func CmdSleep

func CmdSleep(ts *testscript.TestScript, neg bool, args []string)

CmdSleep pauses execution for a specified duration

func CmdTxtProc

func CmdTxtProc(ts *testscript.TestScript, neg bool, args []string)

CmdTxtProc provides flexible text processing capabilities

func CmdsTestScript

func CmdsTestScript() map[string]func(ts *testscript.TestScript, neg bool, args []string)

CmdsTestScript provides custom commands for testscript execution.

func SetupEnvDocker

func SetupEnvDocker(env *testscript.Env) error

SetupEnvDocker configures docker backend in the test environment.

func SetupEnvRandom

func SetupEnvRandom(env *testscript.Env) error

SetupEnvRandom sets up a random environment variable.

func SetupWSL

func SetupWSL(t *testing.T) func(env *testscript.Env) error

SetupWSL sets up a work dir env variable using WSL mount path.

func SetupWorkDirUnixWin

func SetupWorkDirUnixWin(env *testscript.Env) error

SetupWorkDirUnixWin sets up a work dir env variable in unix style.

Types

This section is empty.

Directories

Path Synopsis
Package plugins includes all test plugins.
Package plugins includes all test plugins.
testactions
Package testactions contains actions that help to test the app.
Package testactions contains actions that help to test the app.

Jump to

Keyboard shortcuts

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