This document explains the testing system for the Minexus project, including unit tests, integration tests, and best practices for development and CI/CD workflows.
The Minexus project uses a conditional testing system that separates fast unit tests from slower integration tests. This allows developers to run quick tests during development while ensuring comprehensive testing before releases.
All test commands automatically run in the test environment (MINEXUS_ENV=test) and use the test configuration file (.env.test) for consistent test behavior.
- Fast execution (typically < 5 seconds)
- No external dependencies (no Docker, database, or network services)
- Run by default with
make test - Focus on individual components and business logic
- Slower execution (typically 30-60 seconds)
- Require Docker services (Nexus server, Minion clients, PostgreSQL database)
- Run conditionally with
SLOW_TESTS=1 make test - Test end-to-end workflows and service interactions
# Run unit tests only (fast, for development) - automatically uses MINEXUS_ENV=test
make test
# Run all tests including integration tests (comprehensive) - automatically uses MINEXUS_ENV=test
SLOW_TESTS=1 make test
# Generate coverage report - automatically uses MINEXUS_ENV=test
make cover
# Generate coverage report including integration tests - automatically uses MINEXUS_ENV=test
SLOW_TESTS=1 make coverEnvironment Note: All test commands automatically set MINEXUS_ENV=test and load the test configuration from .env.test. No manual environment configuration is required for testing.
| Command | Description | Duration | Dependencies | Environment |
|---|---|---|---|---|
make test |
Unit tests only | ~5s | None | MINEXUS_ENV=test |
SLOW_TESTS=1 make test |
All tests | ~60s | Docker | MINEXUS_ENV=test |
make cover |
Unit test coverage | ~5s | None | MINEXUS_ENV=test |
SLOW_TESTS=1 make cover |
Full coverage | ~60s | Docker | MINEXUS_ENV=test |
# Generate HTML coverage report and open in browser (uses MINEXUS_ENV=test)
make cover-html
# Generate HTML coverage report including integration tests (uses MINEXUS_ENV=test)
SLOW_TESTS=1 make cover-html
# CI/CD coverage output (percentage only) (uses MINEXUS_ENV=test)
make cover-ci# Comprehensive release testing (includes integration tests) (uses MINEXUS_ENV=test)
make release
# Code quality checks (without tests) (uses MINEXUS_ENV=test)
make auditAll test commands automatically set MINEXUS_ENV=test to ensure consistent test behavior:
- Automatic Setting: Test targets set
MINEXUS_ENV=testwithout manual intervention - Configuration File: Uses
.env.testfor test-specific configuration - Isolation: Ensures tests don't interfere with development or production environments
Controls whether integration tests are executed:
- Not set (default): Only unit tests run
- Set to any value: Integration tests are included
# These are equivalent ways to enable integration tests (all use MINEXUS_ENV=test automatically)
SLOW_TESTS=1 make test
SLOW_TESTS=true make test
SLOW_TESTS=yes make test
export SLOW_TESTS=1 && make test# Fast feedback loop during development (automatically uses MINEXUS_ENV=test)
make test# Comprehensive testing before push (automatically uses MINEXUS_ENV=test)
SLOW_TESTS=1 make test# Check unit test coverage (automatically uses MINEXUS_ENV=test)
make cover
# Check comprehensive coverage (automatically uses MINEXUS_ENV=test)
SLOW_TESTS=1 make cover-html- Test Isolation: All tests run in test environment to avoid affecting dev/prod configurations
- Configuration: Ensure
.env.testfile exists with appropriate test settings - Database: Test environment uses separate test database (typically
minexus_test)
name: Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.23.1
# Unit tests (fast) - automatically uses MINEXUS_ENV=test
- name: Run unit tests
run: make test
# Integration tests (comprehensive) - automatically uses MINEXUS_ENV=test
- name: Run integration tests
run: SLOW_TESTS=1 make test
# Coverage report - automatically uses MINEXUS_ENV=test
- name: Generate coverage
run: SLOW_TESTS=1 make cover-ciCI Environment Notes:
- All test commands automatically use
MINEXUS_ENV=test - Ensure
.env.testfile is available or provide test configuration via environment variables - Test database and services are isolated from production
# For CI environments with Docker support
- name: Run comprehensive tests
run: |
# Integration tests automatically start Docker services and use MINEXUS_ENV=test
SLOW_TESTS=1 make testIntegration tests automatically manage Docker Compose services:
- Service Detection: Checks if required services are running
- Automatic Startup: Starts Nexus, Minion, and PostgreSQL if needed
- Health Checks: Waits for services to be ready before testing
- Cleanup: Services remain running for subsequent test runs
- nexus_db: PostgreSQL database with schema initialization
- nexus_server: Nexus gRPC server (port 11972 for minions)
- minion_1: Test minion client connected to Nexus
Integration tests cover:
- Console Commands: Help, version, minion listing
- Shell Commands: Remote command execution via minions
- File Commands: File operations on remote systems
- System Commands: System information gathering
- Error Handling: Invalid commands and edge cases
- Database Integrity: Data consistency and relationships
# Check service status
docker compose ps
# View service logs
docker compose logs nexus
docker compose logs minion
# Restart services
docker compose down && docker compose up -d# Check if port 11972 is in use
lsof -i :11972
# Or use netcat
nc -z localhost 11972# Check database connectivity
docker compose exec nexus_db pg_isready -U postgres
# Connect to database directly
docker compose exec nexus_db psql -U postgres -d minexus# Keep Docker services running between test runs
docker compose up -d
# Use unit tests for rapid iteration
make test# Use Docker layer caching
# Run unit tests first (fast feedback)
# Run integration tests in parallel when possibleminexus/
├── integration_test.go # Integration tests (conditional execution)
├── run_tests.sh # Test runner script
├── cmd/
│ ├── console/console_test.go # Console unit tests
│ ├── minion/minion_test.go # Minion unit tests
│ └── nexus/nexus_test.go # Nexus unit tests
└── internal/
├── minion/minion_test.go # Internal minion tests
└── nexus/nexus_test.go # Internal nexus tests
coverage.out # Coverage data
coverage.html # HTML coverage report
- Write unit tests first - Fast feedback during development
- Add integration tests for workflows - End-to-end validation
- Use descriptive test names - Clear test purpose
- Test error conditions - Validate error handling
- Keep tests isolated - No dependencies between tests
- Use test environment - All tests automatically run with
MINEXUS_ENV=test - Test configuration - Ensure
.env.testexists with proper test settings - Environment isolation - Tests don't interfere with dev/prod environments
- Document prerequisites - Clear setup instructions
- Automate service management - Reduce manual steps
- Provide cleanup procedures - Easy environment reset
- Separate fast and slow tests - Optimize feedback loops
- Use appropriate timeouts - Handle slow operations
- Cache dependencies - Reduce CI execution time
- Generate coverage reports - Track test effectiveness
# Test specific packages only
go test ./internal/nexus/... -v
# Test with race detection
go test -race ./... -v
# Test with verbose output and timeout
SLOW_TESTS=1 go test -v -timeout 300s ./...
# Run specific integration test
SLOW_TESTS=1 go test -run TestIntegrationSuite/ConsoleCommands -v# Enable debug logging during tests
DEBUG=1 SLOW_TESTS=1 make test
# Run tests with additional logging
go test -v -args -debug ./...# Start services manually
docker compose up -d nexus minion
# Run tests against existing services
SLOW_TESTS=1 make test
# Stop services
docker compose down