This document outlines the testing workflow for the go-plsql-statement-splitter project.
The project includes a test script that can be used to run tests locally. The script is located at scripts/test.sh and supports the following options:
./scripts/test.sh [flags]
Flags:
-v Verbose mode
-r Run tests with race detection
-c Generate coverage report
-a Run all checks (equivalent to -v -r -c)The script will exit with a non-zero status code if any of the tests fail, making it suitable for use in CI/CD pipelines and Git hooks.
Run basic tests:
./scripts/test.shRun tests in verbose mode with race detection:
./scripts/test.sh -v -rRun all checks (tests, race detection, coverage):
./scripts/test.sh -aTo generate a coverage report:
./scripts/test.sh -cTo view the coverage report in your browser:
go tool cover -html=coverage.outThe project uses Git hooks to ensure tests pass before commits are made. To set up Git hooks, run:
./scripts/setup-git-hooks.shThis will install a pre-commit hook that runs tests before each commit. If tests fail, the commit will be aborted.
The project uses GitHub Actions for continuous integration. The following workflows are configured:
-
Test Workflow - Runs tests on push to main branch and on pull requests
- Runs standard tests
- Runs tests with race detection
- Performs linting
-
Coverage Workflow - Generates code coverage reports
- Uploads coverage reports to Codecov
-
Security Scanning - Performs security checks
- Runs gosec to detect security issues
- Scans dependencies for vulnerabilities
When adding new features or fixing bugs, please include tests for the new functionality. Tests should be placed in the appropriate package directory with a _test.go suffix.
For example:
- Core package tests go in
pkg/splitter/*_test.go - Internal tests go in
internal/parser/*_test.go - Test samples go in
test/samples/
SQL sample files for testing are maintained in the test/samples directory. If you're adding support for new SQL constructs, please add sample files to test the new functionality.
Performance benchmarks are included in the test suite. To run benchmarks:
go test -bench=. ./...To compare benchmark results before and after changes, you can use the benchcmp tool:
# Install benchcmp
go install golang.org/x/tools/cmd/benchcmp@latest
# Run benchmarks before changes and save results
go test -bench=. ./... > bench-before.txt
# Make changes, then run benchmarks again
go test -bench=. ./... > bench-after.txt
# Compare results
benchcmp bench-before.txt bench-after.txt