Skip to content

Commit aab8fb6

Browse files
authored
Merge pull request ghostunnel#678 from ghostunnel/claude/setup-go-integration-tests-1FT6X
Update AGENTS.md with Go toolchain setup and integration test instructions
2 parents 9c19b22 + 940a801 commit aab8fb6

2 files changed

Lines changed: 70 additions & 26 deletions

File tree

CONTRIBUTING.md

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,55 @@ When submitting code, please make efforts to follow existing conventions and
77
style in order to keep the code as readable as possible. Please also make sure
88
all tests pass by running `mage test:all`, and format your code with `go fmt`.
99

10+
## Go Toolchain Setup
11+
12+
This project requires the Go version specified in `go.mod`. If the default `go`
13+
on PATH is older, builds will fail with a version mismatch error.
14+
15+
**Claude Code (cloud environment):** Multiple Go versions are installed
16+
side-by-side under `/usr/local/`. The default `/usr/local/go/` may be older
17+
than what this project requires. Check for a matching version (e.g.
18+
`/usr/local/go<VERSION>/bin/go`) and prepend it to your PATH:
19+
20+
```bash
21+
# Find available Go versions
22+
ls /usr/local/go*/bin/go
23+
24+
# Use the version that matches go.mod (check with: grep '^go ' go.mod)
25+
export PATH="/usr/local/go<VERSION>/bin:$PATH"
26+
go version
27+
```
28+
29+
Mage is available as a Go tool dependency (no separate install needed):
30+
31+
```bash
32+
go tool mage -l # list all targets
33+
```
34+
1035
## Build & Test Commands
1136

12-
This project uses [mage](https://magefile.org) as the build system (defined in `magefile.go`):
37+
This project uses [mage](https://magefile.org) as the build system (defined in `magefile.go`).
38+
Invoke it via `go tool mage` (not a standalone `mage` binary):
1339

1440
```bash
15-
mage go:build # Build binary
16-
mage go:lint # Run golangci-lint (config: .golangci.yml)
17-
mage test:all # Unit + integration tests with merged coverage
18-
mage test:unit # Go unit tests only
19-
mage test:integration # Python integration tests only
20-
mage test:docker # Full suite in Docker (includes PKCS#11/SoftHSM)
21-
mage test:keys # Generate test certificates in test-keys/
22-
mage docker:build # Build Docker images
23-
mage -l # List all available targets
41+
go tool mage go:build # Build binary
42+
go tool mage go:lint # Run golangci-lint (config: .golangci.yml)
43+
go tool mage test:all # Unit + integration tests with merged coverage
44+
go tool mage test:unit # Go unit tests only
45+
go tool mage test:integration # Python integration tests only
46+
go tool mage test:docker # Full suite in Docker (includes PKCS#11/SoftHSM)
47+
go tool mage test:keys # Generate test certificates in test-keys/
48+
go tool mage docker:build # Build Docker images
49+
go tool mage -l # List all available targets
2450
```
2551

2652
### Running a Single Test
2753

2854
```bash
29-
go test -v -run TestName ./... # Single Go unit test
30-
go test -v ./auth/... # All tests in a package
31-
cd tests && python3 test-name.py # Single integration test
55+
go test -v -run TestName ./... # Single Go unit test
56+
go test -v ./auth/... # All tests in a package
57+
go tool mage test:single test-server-pem-rsa # Single integration test (via mage)
58+
cd tests && python3 test-server-pem-rsa.py # Single integration test (directly)
3259
```
3360

3461
### Linting
@@ -52,14 +79,30 @@ run checks on a live instance. If you are adding new features or changing
5279
existing behavior, please add/update the integration tests in the `tests/`
5380
directory accordingly. The tests use the `tests/common.py` helper module.
5481

55-
Integration tests run in parallel by default (up to `NumCPU`, capped at 16 by default).
56-
Set `GHOSTUNNEL_TEST_PARALLEL` to control the number of concurrent tests (may exceed the default cap):
82+
### Prerequisites
83+
84+
1. **Go** at the version specified in `go.mod` on PATH (see "Go Toolchain Setup" above).
85+
2. **Python 3** with packages used by the test harness (typically already available).
86+
3. **Test certificates** must be generated before the first run:
87+
88+
```bash
89+
go tool mage test:keys # generates certs in test-keys/
90+
```
91+
92+
### Running Integration Tests
5793

5894
```bash
59-
GHOSTUNNEL_TEST_PARALLEL=4 mage test:integration
95+
go tool mage test:integration # all integration tests
96+
go tool mage test:single test-server-pem-rsa # single test by name
97+
GHOSTUNNEL_TEST_PARALLEL=4 go tool mage test:integration # control parallelism
6098
```
6199

62-
Test certificates are generated in `test-keys/` via `mage test:keys`.
100+
Integration tests run in parallel by default (up to `NumCPU`, capped at 16).
101+
Set `GHOSTUNNEL_TEST_PARALLEL` to control the number of concurrent tests (may exceed the default cap).
102+
103+
The integration test runner first builds a coverage-instrumented test binary
104+
(`go test -c`), then runs each `tests/test-*.py` script against that binary.
105+
Each Python test starts a ghostunnel process, exercises it, and verifies behavior.
63106

64107
## Architecture Overview
65108

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ started is to use a package like [cloudflare/cfssl](https://github.com/cloudflar
6464
For testing and development purposes, you can generate test certificates using:
6565

6666
# Generate test certificates and keys
67-
mage test:keys
67+
go tool mage test:keys
6868

6969
This will create a `test-keys` directory with all the necessary certificates and keys
7070
for testing. **Note: These are test certificates only and should NOT be used in production.**
@@ -78,16 +78,17 @@ built directly via Github Actions on the latest available images. If you need
7878
compatibility for specific OS versions we recommend building yourself.
7979

8080
Ghostunnel uses the [mage][mage] build system, a make/rake-like build tool using
81-
Go. You can build Ghostunnel with the [mage][mage] commands shown below.
81+
Go. Mage is available as a Go tool dependency (no separate install needed). You
82+
can build Ghostunnel with the commands shown below.
8283

8384
# Compile binary
84-
mage go:build
85+
go tool mage go:build
8586

8687
# Build containers
87-
mage docker:build
88+
go tool mage docker:build
8889

89-
You can also run `mage -l` to view all build targets and add `-v` to mage commands
90-
to get more verbose output.
90+
You can also run `go tool mage -l` to view all build targets and add `-v` to
91+
mage commands to get more verbose output.
9192

9293
[rel]: https://github.com/ghostunnel/ghostunnel/releases
9394
[hub]: https://hub.docker.com/r/ghostunnel/ghostunnel
@@ -101,11 +102,11 @@ suite requires Python 3.
101102
To run tests:
102103

103104
# Option 1: run unit & integration tests locally
104-
mage test:all
105+
go tool mage test:all
105106

106107
# Option 2: run unit & integration tests in a Docker container
107108
# This also runs PKCS#11 integration tests using SoftHSM in the container
108-
mage test:docker
109+
go tool mage test:docker
109110

110111
# Open coverage information in browser
111112
go tool cover -html coverage/all.profile
@@ -153,7 +154,7 @@ information. In this example, we assume that the CN of the client cert we want
153154
to accept connections from is `client`.
154155

155156
**Note:** Before running the examples below, make sure you have generated the test
156-
certificates by running `mage test:keys` (see the [Getting Started](#getting-started)
157+
certificates by running `go tool mage test:keys` (see the [Getting Started](#getting-started)
157158
section above).
158159

159160
Start a backend server:

0 commit comments

Comments
 (0)