|
| 1 | +# Testing Workflow |
| 2 | + |
| 3 | +This document outlines the testing workflow for the go-plsql-statement-splitter project. |
| 4 | + |
| 5 | +## Local Testing |
| 6 | + |
| 7 | +### Running Tests |
| 8 | + |
| 9 | +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: |
| 10 | + |
| 11 | +```bash |
| 12 | +./scripts/test.sh [flags] |
| 13 | + |
| 14 | +Flags: |
| 15 | + -v Verbose mode |
| 16 | + -r Run tests with race detection |
| 17 | + -c Generate coverage report |
| 18 | + -a Run all checks (equivalent to -v -r -c) |
| 19 | +``` |
| 20 | + |
| 21 | +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. |
| 22 | + |
| 23 | +### Examples |
| 24 | + |
| 25 | +Run basic tests: |
| 26 | +```bash |
| 27 | +./scripts/test.sh |
| 28 | +``` |
| 29 | + |
| 30 | +Run tests in verbose mode with race detection: |
| 31 | +```bash |
| 32 | +./scripts/test.sh -v -r |
| 33 | +``` |
| 34 | + |
| 35 | +Run all checks (tests, race detection, coverage): |
| 36 | +```bash |
| 37 | +./scripts/test.sh -a |
| 38 | +``` |
| 39 | + |
| 40 | +### Coverage Reports |
| 41 | + |
| 42 | +To generate a coverage report: |
| 43 | +```bash |
| 44 | +./scripts/test.sh -c |
| 45 | +``` |
| 46 | + |
| 47 | +To view the coverage report in your browser: |
| 48 | +```bash |
| 49 | +go tool cover -html=coverage.out |
| 50 | +``` |
| 51 | + |
| 52 | +## Git Hooks |
| 53 | + |
| 54 | +The project uses Git hooks to ensure tests pass before commits are made. To set up Git hooks, run: |
| 55 | + |
| 56 | +```bash |
| 57 | +./scripts/setup-git-hooks.sh |
| 58 | +``` |
| 59 | + |
| 60 | +This will install a pre-commit hook that runs tests before each commit. If tests fail, the commit will be aborted. |
| 61 | + |
| 62 | +## Continuous Integration |
| 63 | + |
| 64 | +The project uses GitHub Actions for continuous integration. The following workflows are configured: |
| 65 | + |
| 66 | +1. **Test Workflow** - Runs tests on push to main branch and on pull requests |
| 67 | + - Runs standard tests |
| 68 | + - Runs tests with race detection |
| 69 | + - Performs linting |
| 70 | + |
| 71 | +2. **Coverage Workflow** - Generates code coverage reports |
| 72 | + - Uploads coverage reports to Codecov |
| 73 | + |
| 74 | +3. **Security Scanning** - Performs security checks |
| 75 | + - Runs gosec to detect security issues |
| 76 | + - Scans dependencies for vulnerabilities |
| 77 | + |
| 78 | +## Adding Tests |
| 79 | + |
| 80 | +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. |
| 81 | + |
| 82 | +For example: |
| 83 | +- Core package tests go in `pkg/splitter/*_test.go` |
| 84 | +- Internal tests go in `internal/parser/*_test.go` |
| 85 | +- Test samples go in `test/samples/` |
| 86 | + |
| 87 | +## Test Sample Files |
| 88 | + |
| 89 | +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. |
| 90 | + |
| 91 | +## Benchmarks |
| 92 | + |
| 93 | +Performance benchmarks are included in the test suite. To run benchmarks: |
| 94 | + |
| 95 | +```bash |
| 96 | +go test -bench=. ./... |
| 97 | +``` |
| 98 | + |
| 99 | +To compare benchmark results before and after changes, you can use the benchcmp tool: |
| 100 | + |
| 101 | +```bash |
| 102 | +# Install benchcmp |
| 103 | +go install golang.org/x/tools/cmd/benchcmp@latest |
| 104 | + |
| 105 | +# Run benchmarks before changes and save results |
| 106 | +go test -bench=. ./... > bench-before.txt |
| 107 | + |
| 108 | +# Make changes, then run benchmarks again |
| 109 | +go test -bench=. ./... > bench-after.txt |
| 110 | + |
| 111 | +# Compare results |
| 112 | +benchcmp bench-before.txt bench-after.txt |
| 113 | +``` |
0 commit comments