Skip to content

Commit 4a437ce

Browse files
authored
Merge pull request #2977 from joejstuart/macos_acceptance
Macos acceptance test fixes and documentation
2 parents 6e91c81 + 97c71e0 commit 4a437ce

File tree

6 files changed

+1162
-6
lines changed

6 files changed

+1162
-6
lines changed

acceptance/snaps/snaps.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ func MatchSnapshot(ctx context.Context, qualifier, text string, vars map[string]
151151
}
152152

153153
scenario := ctx.Value(testenv.Scenario).(*godog.Scenario)
154-
155154
snapshot := strings.TrimSuffix(filepath.Base(scenario.Uri), filepath.Ext(scenario.Uri))
156155

157156
formatText := true

acceptance/testenv/testenv.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"os/exec"
2828
"path"
2929
"runtime"
30-
"sync"
3130
"testing"
3231

3332
"github.com/testcontainers/testcontainers-go"
@@ -55,9 +54,10 @@ var (
5554
)
5655

5756
var (
58-
version sync.Once
5957
ecVersion = "undefined"
6058
ecVersionErr error
59+
// Add a flag to track if version has been initialized
60+
versionInitialized bool
6161
)
6262

6363
// Persist persists the environment stored in context in a ".persisted" file as JSON
@@ -258,15 +258,17 @@ func TestContainersRequest(ctx context.Context, req testcontainers.ContainerRequ
258258

259259
// CLIVersion returns the version of the CLI, useful for matching in snapshots
260260
func CLIVersion(ctx context.Context) (string, error) {
261-
version.Do(func() {
261+
// For individual test runs, we need to ensure the version is always fresh
262+
// Check if we're in a test context and if the version needs to be refreshed
263+
if !versionInitialized || ecVersion == "undefined" {
262264
ec := path.Join("dist", fmt.Sprintf("ec_%s_%s", runtime.GOOS, runtime.GOARCH))
263265

264266
cmd := exec.CommandContext(ctx, ec, "version", "--json")
265267
var stdout bytes.Buffer
266268
cmd.Stdout = &stdout
267269

268270
if ecVersionErr = cmd.Run(); ecVersionErr != nil {
269-
return
271+
return ecVersion, ecVersionErr
270272
}
271273

272274
ver := struct {
@@ -277,7 +279,8 @@ func CLIVersion(ctx context.Context) (string, error) {
277279
}
278280

279281
ecVersion = ver.Version
280-
})
282+
versionInitialized = true
283+
}
281284

282285
return ecVersion, ecVersionErr
283286
}

hack/macos/README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Podman Machine Setup Scripts
2+
3+
This directory contains automated scripts for setting up and running acceptance tests on macOS with Podman machine.
4+
5+
## Location
6+
These scripts are located in `hack/macos/` and should be run from the repository root.
7+
8+
## Scripts Overview
9+
10+
### 1. `setup-podman-machine.sh`
11+
**Purpose**: Complete automated setup of Podman machine for acceptance tests
12+
13+
**What it does**:
14+
- Checks prerequisites (podman, kind, kubectl)
15+
- Cleans up existing podman machine
16+
- Creates new podman machine with optimal settings (4 CPUs, 8GB RAM, 500GB disk)
17+
- Fixes keyring quota issue (critical for avoiding "Disk quota exceeded" errors)
18+
- Creates required networks (testcontainers)
19+
- Configures DNS resolution (rekor.localhost, apiserver.localhost, tuf.localhost)
20+
- Creates environment setup script
21+
- Tests the setup
22+
23+
**Usage**:
24+
```bash
25+
# From repository root
26+
./hack/macos/setup-podman-machine.sh
27+
```
28+
29+
### 2. `run-acceptance-tests.sh`
30+
**Purpose**: Run acceptance tests with proper environment setup
31+
32+
**What it does**:
33+
- Checks if setup was completed
34+
- Loads environment variables
35+
- Optionally cleans up test resources
36+
- Runs tests with configurable parallelism and timeout
37+
- Supports running specific test patterns
38+
39+
**Usage**:
40+
```bash
41+
# From repository root
42+
# Run all tests
43+
./hack/macos/run-acceptance-tests.sh
44+
45+
# Run with custom settings
46+
./hack/macos/run-acceptance-tests.sh -p 2 -t 30m
47+
48+
# Run specific tests
49+
./hack/macos/run-acceptance-tests.sh "TestFeatures/conftest"
50+
51+
# Clean up and run
52+
./hack/macos/run-acceptance-tests.sh -c "TestFeatures/OPA"
53+
```
54+
55+
## Quick Start
56+
57+
1. **Initial Setup** (run once):
58+
```bash
59+
./hack/macos/setup-podman-machine.sh
60+
```
61+
62+
2. **Run Tests**:
63+
```bash
64+
./hack/macos/run-acceptance-tests.sh
65+
```
66+
67+
## Environment Variables
68+
69+
The setup script creates `setup-test-env.sh` with these variables:
70+
- `KIND_EXPERIMENTAL_PROVIDER=podman`
71+
- `TESTCONTAINERS_RYUK_DISABLED=true`
72+
- `TESTCONTAINERS_HOST_OVERRIDE=localhost`
73+
- `DOCKER_HOST=unix:///var/run/docker.sock`
74+
75+
## Troubleshooting
76+
77+
### Quick Fixes
78+
79+
1. **"Disk quota exceeded" errors**:
80+
- The setup script automatically fixes this with `kernel.keys.maxkeys=20000`
81+
- If you still get errors, run: `podman machine ssh "sudo sysctl -w kernel.keys.maxkeys=20000"`
82+
83+
2. **"Network not found" errors**:
84+
- The setup script creates the required `testcontainers` network
85+
- If missing, run: `podman network create testcontainers`
86+
87+
3. **DNS resolution issues**:
88+
- The setup script adds required entries to `/etc/hosts`
89+
- If missing, add: `127.0.0.1 rekor.localhost`, `127.0.0.1 apiserver.localhost`, and `127.0.0.1 tuf.localhost`
90+
91+
4. **TLS handshake timeouts**:
92+
- These are usually from stale Kubernetes connections
93+
- Clean up with: `kind delete cluster --all`
94+
95+
### Comprehensive Troubleshooting
96+
97+
For detailed troubleshooting, performance optimization, and advanced configuration, see:
98+
**[TROUBLESHOOTING.md](TROUBLESHOOTING.md)** - Complete guide to manual setup, troubleshooting, and optimization
99+
100+
### Manual Cleanup
101+
102+
If you need to start over:
103+
```bash
104+
# Stop and remove podman machine
105+
podman machine stop
106+
podman machine rm podman-machine-default
107+
108+
# Clean up system
109+
podman system prune -a -f
110+
111+
# Re-run setup
112+
./hack/macos/setup-podman-machine.sh
113+
```
114+
115+
## Script Features
116+
117+
- **Colorized output** for easy reading
118+
- **Error handling** with proper exit codes
119+
- **Prerequisite checking** before setup
120+
- **Automatic cleanup** of existing resources
121+
- **Environment validation** after setup
122+
- **Flexible test execution** with various options
123+
124+
## Dependencies
125+
126+
- `podman` (installed via Homebrew)
127+
- `kind` (installed via Homebrew)
128+
- `kubectl` (installed via Homebrew)
129+
- `sudo` access (for /etc/hosts modification)
130+
131+
Install missing dependencies:
132+
```bash
133+
brew install podman kind kubectl
134+
```

0 commit comments

Comments
 (0)