File size: 4,165 Bytes
6a7089a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | # Testing
## Quick Start with dev
The `dev` developer toolkit is the easiest way to run checks and tests:
```bash
./dev # Interactive picker
./dev test # All tests (unit + E2E)
./dev test unit # Unit tests only
./dev e2e # E2E tests (both curl and CLI)
./dev e2e orchestrator # Orchestrator-heavy E2E tests only
./dev e2e curl # E2E curl tests only
./dev e2e cli # E2E CLI tests only
./dev check # All checks (format, vet, build, lint)
./dev check go # Go checks only
./dev check security # Gosec security scan
./dev format dashboard # Run Prettier on dashboard sources
./dev doctor # Setup dev environment
```
## Unit Tests
```bash
go test ./...
# or
./dev test unit
```
Unit tests are standard Go tests that validate individual packages and functions without launching a full server.
## E2E Tests
End-to-end tests launch a real pinchtab server with Chrome and run e2e-level tests against it.
### Curl Tests (HTTP API)
```bash
./dev e2e curl
```
Runs 183 HTTP-level tests using curl against the server. Tests the REST API, navigation, snapshots, and other HTTP endpoints.
### CLI Tests
```bash
./dev e2e cli
```
Runs CLI e2e tests. Tests the command-line interface directly.
### Both E2E Test Suites
```bash
./dev e2e
```
Runs all E2E tests (curl + CLI, 224 tests total).
### Orchestrator E2E Suite
```bash
./dev e2e orchestrator
```
Runs the orchestration-focused curl scenarios, including multi-instance flows and remote bridge attachment against the dedicated `pinchtab-bridge` Compose service.
## Environment Variables
| Variable | Default | Description |
|---|---|---|
| `CI` | _(unset)_ | Set to `true` for longer health check timeouts (60s vs 30s) |
### Temp Directory Layout
Each E2E test run creates a single temp directory under `/tmp/pinchtab-test-*/`:
```
/tmp/pinchtab-test-123456789/
βββ pinchtab # Compiled test binary
βββ state/ # Dashboard state (profiles, instances)
βββ profiles/ # Chrome user-data directories
```
Everything is cleaned up automatically when tests finish.
## Test File Structure
E2E tests are organized in two directories:
- **`tests/e2e/scenarios/*.sh`** β HTTP curl-based tests (183 tests)
- Test the REST API directly
- Use Docker Compose: `tests/e2e/docker-compose.yml`
- **`tests/e2e/scenarios-orchestrator/*.sh`** β orchestration-heavy curl tests
- Test multi-instance flows and remote bridge attachment
- Use Docker Compose: `tests/e2e/docker-compose-orchestrator.yml`
- **`tests/e2e/scenarios-cli/*.sh`** β CLI e2e tests (41 tests)
- Test the command-line interface
- Use Docker Compose: `tests/e2e/docker-compose.cli.yml`
Each test is a standalone bash script that:
1. Starts the test server (or uses existing)
2. Runs curl or CLI commands
3. Asserts expected output or exit codes
4. Cleans up
## Writing New E2E Tests
Create a new bash script in `tests/e2e/scenarios/` (for curl tests) or `tests/e2e/scenarios-cli/` (for CLI tests):
### Example: Simple Curl Test
```bash
#!/bin/bash
# tests/e2e/scenarios/test-my-feature.sh
set -e # Exit on error
# Source helpers
. "$(dirname "$0")/../helpers.sh"
# Test setup
SERVER_URL="http://localhost:9867"
# Start server if needed
start_test_server
# Run test
echo "Testing my feature..."
RESPONSE=$(curl -s "$SERVER_URL/health")
if [ "$(echo "$RESPONSE" | jq -r '.status')" != "ok" ]; then
echo "β Health check failed"
exit 1
fi
echo "β
Test passed"
```
### Example: CLI Test
```bash
#!/bin/bash
# tests/e2e/scenarios-cli/test-my-cli.sh
set -e
# Source helpers
. "$(dirname "$0")/../helpers.sh"
# Test the CLI
echo "Testing pinchtab CLI..."
OUTPUT=$($PINCHTAB_BIN --version)
if [[ ! "$OUTPUT" =~ pinchtab ]]; then
echo "β Version output incorrect"
exit 1
fi
echo "β
CLI test passed"
```
## Coverage
Generate coverage for unit tests:
```bash
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
```
Note: E2E tests are black-box tests and don't contribute to code coverage metrics directly.
|