|
1 | 1 | # Test |
2 | 2 |
|
3 | | -## Commands |
| 3 | +## Test Runner |
4 | 4 |
|
5 | | -### Using go test |
| 5 | +The test suite uses `scripts/test.sh` as the unified test runner. It provides consistent behavior across different commands with support for [gotestsum](https://github.com/gotestyourself/gotestsum) (recommended) or plain `go test`. |
6 | 6 |
|
7 | | -1. Run all tests |
| 7 | +### Runner Behavior |
8 | 8 |
|
9 | | -```sh |
10 | | -go test ./... |
11 | | -``` |
| 9 | +By default, the script auto-detects the available runner: |
12 | 10 |
|
13 | | -2. Run unit tests |
| 11 | +1. If `RUNNER` env var is set, use that explicitly |
| 12 | +2. If `gotestsum` is installed, use it (with automatic retries for flaky tests) |
| 13 | +3. Otherwise, fall back to `go test` |
| 14 | + |
| 15 | +To install gotestsum (recommended): |
14 | 16 |
|
15 | 17 | ```sh |
16 | | -go test ./... -short |
| 18 | +go install gotest.tools/gotestsum@latest |
17 | 19 | ``` |
18 | 20 |
|
19 | | -3. Run integration tests |
| 21 | +To force a specific runner: |
20 | 22 |
|
21 | 23 | ```sh |
22 | | -go test ./... -run "Integration" |
| 24 | +RUNNER=go ./scripts/test.sh test # Force go test |
| 25 | +RUNNER=gotestsum ./scripts/test.sh test # Force gotestsum |
23 | 26 | ``` |
24 | 27 |
|
25 | | -### Using Make (requires gotestsum) |
| 28 | +## Commands |
26 | 29 |
|
27 | | -The Makefile uses [gotestsum](https://github.com/gotestyourself/gotestsum) which provides better output formatting and automatic retries for flaky tests. |
| 30 | +### Using the Test Script |
28 | 31 |
|
29 | 32 | ```sh |
30 | | -# Install gotestsum first |
31 | | -go install gotest.tools/gotestsum@latest |
32 | | -``` |
| 33 | +# Run all tests (unit + integration) |
| 34 | +./scripts/test.sh test |
33 | 35 |
|
34 | | -1. Run all tests |
| 36 | +# Run unit tests only (uses -short flag) |
| 37 | +./scripts/test.sh unit |
35 | 38 |
|
36 | | -```sh |
37 | | -make test |
| 39 | +# Run end-to-end tests |
| 40 | +./scripts/test.sh e2e |
| 41 | + |
| 42 | +# Run full suite with all backend combinations |
| 43 | +./scripts/test.sh full |
38 | 44 | ``` |
39 | 45 |
|
40 | | -2. Run unit tests |
| 46 | +### Using Make |
| 47 | + |
| 48 | +The Makefile targets delegate to `scripts/test.sh`: |
41 | 49 |
|
42 | 50 | ```sh |
43 | | -make test/unit |
| 51 | +make test # ./scripts/test.sh test |
| 52 | +make test/unit # ./scripts/test.sh unit |
| 53 | +make test/e2e # ./scripts/test.sh e2e |
| 54 | +make test/full # ./scripts/test.sh full |
44 | 55 | ``` |
45 | 56 |
|
46 | | -3. Run integration tests |
| 57 | +### Using go test Directly |
47 | 58 |
|
48 | 59 | ```sh |
49 | | -make test/integration |
| 60 | +go test ./... # All tests |
| 61 | +go test ./... -short # Unit tests only |
| 62 | +go test ./... -run "Integration" # Integration tests |
50 | 63 | ``` |
51 | 64 |
|
52 | | -#### Make Options |
| 65 | +## Environment Variables |
| 66 | + |
| 67 | +| Variable | Description | Default | |
| 68 | +|----------|-------------|---------| |
| 69 | +| `TEST` | Package(s) to test | `./internal/...` | |
| 70 | +| `RUN` | Filter tests by name pattern | (none) | |
| 71 | +| `TESTARGS` | Additional arguments to pass to test command | (none) | |
| 72 | +| `TESTINFRA` | Set to `1` to use persistent test infrastructure | (none) | |
| 73 | +| `TESTCOMPAT` | Set to `1` to run full backend compatibility suite | (none) | |
| 74 | +| `TESTREDISCLUSTER` | Set to `1` to enable Redis cluster tests | (none) | |
| 75 | +| `RUNNER` | Force test runner: `gotestsum` or `go` | auto-detect | |
53 | 76 |
|
54 | | -1. To test specific package |
| 77 | +### Examples |
55 | 78 |
|
56 | 79 | ```sh |
| 80 | +# Test specific package |
57 | 81 | TEST='./internal/services/api' make test |
58 | | -``` |
59 | 82 |
|
60 | | -2. To run specific tests |
61 | | - |
62 | | -```sh |
| 83 | +# Run specific tests |
63 | 84 | RUN='TestJWT' make test |
64 | | -``` |
65 | | - |
66 | | -3. To pass additional options |
67 | 85 |
|
68 | | -```sh |
| 86 | +# Pass additional options |
69 | 87 | TESTARGS='-v' make test |
70 | | -``` |
71 | 88 |
|
72 | | -Keep in mind you can't use `RUN` along with `make test/integration` as it already uses `-run` option. However, since you're already specifying which test to run, we assume this is a non-issue. |
| 89 | +# Combine options |
| 90 | +RUN='TestListTenant' TEST='./internal/models' TESTINFRA=1 make test |
| 91 | +``` |
73 | 92 |
|
74 | 93 | ## Coverage |
75 | 94 |
|
|
0 commit comments