Skip to content

Testing Guide

This document outlines the testing approach for the MySQL Proxy project.

Quick Start

# Run all tests (excluding CGO-dependent packages) with coverage report
make unit-test

# Run tests for specific modules
make testgo MUTEST=internal/utils,internal/config

# Run tests with coverage report for specific modules
make testgo-cover MUTEST=internal/utils

# View HTML coverage report
open app/coverage.html

Test Organization

Tests are organized by package: - Test files follow the pattern test_*_test.go (e.g., test_crypto_utils_test.go) - All tests reside alongside their corresponding production code - Table-driven tests are used for comprehensive coverage - Mock interfaces are used for external dependencies

Testing Philosophy

  1. Pure Functions First: Focus on testing pure functions without side effects
  2. Testable Code: Extract side effects to make functions testable
  3. Coverage Goals: Aim for >80% coverage in core packages

Current Status

Package Status Coverage Notes
utils ✅ Complete 98.4% Core utilities with pure functions
config ✅ Complete 76.5% Configuration system
parser ✅ Improved 60.1% SQL parsing and normalization
pubsub ✅ Complete 55.1% Pub/Sub system
cache 🚧 WIP 22.2% Memory cache (Redis needs mocking)
sqlutils 🚧 Missing 0% No tests yet
handler 🚧 WIP <10% Needs mocks (CGO dependent)

Overall Coverage: 57.3%

Testing Challenges

Integration Testing

Some packages are challenging to test with standard unit tests:

  • handler package: Requires CGO for Lua scripting engine
  • Not included in make unit-test due to CGO dependency
  • Requires special testing environment with Lua libraries

  • Redis-dependent components:

  • Redis for cache/pubsub requires external services
  • Mock implementations provided for unit testing

  • MySQL protocol implementation:

  • Protocol-level testing requires specialized test fixtures

TODO: Create integration test suite with containerized dependencies that includes all the above components.

End-to-End Testing

TODO: - Create E2E tests using Docker Compose - Implement automated performance benchmarks - Add load testing tools

Contributing Tests

When adding new tests: 1. Name test files as test_*_test.go to match our convention 2. Use table-driven tests for comprehensive test cases 3. Include edge cases and error conditions 4. Mock external dependencies 5. Avoid global state 6. Run make testgo-cover to verify coverage