upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/README.md
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-05 07:09:41 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-05 07:17:47 +0000
commitcb466fbc02b83c5788def5fef73f93573f5c1f70 (patch)
treeeb9d0293d2be16b8c4ed8a3a278ed9207f54b52d /grasp-audit/README.md
parent74c7b090a6ec7f749a3a79dcb0c9a0a6bc198702 (diff)
test: improve test script with unique names and random ports
- Remove python3 dependency for port selection - Use RANDOM for port selection in range 20000-30000 - Use unique container names based on PID: grasp-audit-run-294183 - Use unique temp directories: grasp-audit-run-XXXXXXXXXX - Ensures parallel test runs don't conflict
Diffstat (limited to 'grasp-audit/README.md')
-rw-r--r--grasp-audit/README.md90
1 files changed, 59 insertions, 31 deletions
diff --git a/grasp-audit/README.md b/grasp-audit/README.md
index a2b0024..7c0450b 100644
--- a/grasp-audit/README.md
+++ b/grasp-audit/README.md
@@ -142,13 +142,18 @@ Some NIP-01 smoke tests (like `send_receive_event`) will fail because ngit-relay
142non-Git events. This is expected behavior - the validation tests should still pass. 142non-Git events. This is expected behavior - the validation tests should still pass.
143 143
144```bash 144```bash
145# 1. Create temporary directories for clean state 145# 1. Create temporary directory with unique name for clean state
146mkdir -p /tmp/ngit-test/{repos,blossom,relay-db,logs} 146TEST_DIR=$(mktemp -d -t grasp-audit-run-XXXXXXXXXX)
147mkdir -p "$TEST_DIR"/{repos,blossom,relay-db,logs}
147 148
148# 2. Start ngit-relay with fresh data (using port 8082 to avoid conflicts) 149# 2. Pick a random port to avoid conflicts
150PORT=$((20000 + RANDOM % 10000))
151
152# 3. Start ngit-relay with fresh data
153CONTAINER_NAME="grasp-audit-run-$"
149docker run --rm -d \ 154docker run --rm -d \
150 --name ngit-relay-test \ 155 --name "$CONTAINER_NAME" \
151 -p 8082:8081 \ 156 -p "$PORT:8081" \
152 -e NGIT_DOMAIN=localhost \ 157 -e NGIT_DOMAIN=localhost \
153 -e NGIT_RELAY_NAME="ngit-relay test instance" \ 158 -e NGIT_RELAY_NAME="ngit-relay test instance" \
154 -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \ 159 -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \
@@ -157,17 +162,17 @@ docker run --rm -d \
157 -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \ 162 -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \
158 -e NGIT_PROACTIVE_SYNC_NOSTR=false \ 163 -e NGIT_PROACTIVE_SYNC_NOSTR=false \
159 -e NGIT_LOG_LEVEL=INFO \ 164 -e NGIT_LOG_LEVEL=INFO \
160 -v /tmp/ngit-test/repos:/srv/ngit-relay/repos \ 165 -v "$TEST_DIR/repos:/srv/ngit-relay/repos" \
161 -v /tmp/ngit-test/blossom:/srv/ngit-relay/blossom \ 166 -v "$TEST_DIR/blossom:/srv/ngit-relay/blossom" \
162 -v /tmp/ngit-test/relay-db:/srv/ngit-relay/relay-db \ 167 -v "$TEST_DIR/relay-db:/srv/ngit-relay/relay-db" \
163 -v /tmp/ngit-test/logs:/var/log/ngit-relay \ 168 -v "$TEST_DIR/logs:/var/log/ngit-relay" \
164 ghcr.io/danconwaydev/ngit-relay:latest 169 ghcr.io/danconwaydev/ngit-relay:latest
165 170
166# 3. Wait for relay to start 171# 4. Wait for relay to start
167sleep 3 172sleep 3
168 173
169# 4. Run tests against ngit-relay on port 8082 174# 5. Run tests against ngit-relay
170RELAY_URL=ws://localhost:8082 cargo test --ignored 175RELAY_URL="ws://localhost:$PORT" cargo test --ignored
171 176
172# Expected results when testing against ngit-relay: 177# Expected results when testing against ngit-relay:
173# - โœ“ websocket_connection (basic connectivity) 178# - โœ“ websocket_connection (basic connectivity)
@@ -187,9 +192,10 @@ RELAY_URL=ws://localhost:8082 cargo test --ignored
187# The test will exit with an error, but the validation tests passing 192# The test will exit with an error, but the validation tests passing
188# is what matters for GRASP compliance. 193# is what matters for GRASP compliance.
189 194
190# 5. Stop and cleanup 195# 6. Stop and cleanup
191docker stop ngit-relay-test 196docker stop "$CONTAINER_NAME"
192rm -rf /tmp/ngit-test 197docker run --rm -v "$TEST_DIR:/data" alpine sh -c "rm -rf /data/*" 2>/dev/null || true
198rm -rf "$TEST_DIR"
193``` 199```
194 200
195**Why fresh directories?** 201**Why fresh directories?**
@@ -235,14 +241,37 @@ Save this as `test-ngit-relay.sh`:
235#!/bin/bash 241#!/bin/bash
236set -e 242set -e
237 243
238echo "๐Ÿงน Cleaning up old test data..." 244# Create temporary directory with random name
239rm -rf /tmp/ngit-test 245TEST_DIR=$(mktemp -d -t grasp-audit-run-XXXXXXXXXX)
240mkdir -p /tmp/ngit-test/{repos,blossom,relay-db,logs} 246# Pick a random port in the range 20000-30000
247PORT=$((20000 + RANDOM % 10000))
248
249echo "๐Ÿงน Using temporary directory: $TEST_DIR"
250echo "๐Ÿ”Œ Using port: $PORT"
251
252# Cleanup function
253cleanup() {
254 echo "๐Ÿ›‘ Stopping relay..."
255 docker stop "grasp-audit-run-$" 2>/dev/null || true
256
257 echo "๐Ÿงน Cleaning up temporary directory..."
258 docker run --rm -v "$TEST_DIR:/data" alpine sh -c "rm -rf /data/*" 2>/dev/null || true
259 rm -rf "$TEST_DIR"
260}
261
262# Set trap to cleanup on exit
263trap cleanup EXIT
264
265echo "๐Ÿ“ Creating data directories..."
266mkdir -p "$TEST_DIR"/{repos,blossom,relay-db,logs}
241 267
242echo "๐Ÿš€ Starting ngit-relay..." 268echo "๐Ÿš€ Starting ngit-relay..."
269# Remove any existing container with this name
270CONTAINER_NAME="grasp-audit-run-$"
271docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
243docker run --rm -d \ 272docker run --rm -d \
244 --name ngit-relay-test \ 273 --name "$CONTAINER_NAME" \
245 -p 8081:8081 \ 274 -p "$PORT:8081" \
246 -e NGIT_DOMAIN=localhost \ 275 -e NGIT_DOMAIN=localhost \
247 -e NGIT_RELAY_NAME="ngit-relay test instance" \ 276 -e NGIT_RELAY_NAME="ngit-relay test instance" \
248 -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \ 277 -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \
@@ -251,23 +280,22 @@ docker run --rm -d \
251 -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \ 280 -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \
252 -e NGIT_PROACTIVE_SYNC_NOSTR=false \ 281 -e NGIT_PROACTIVE_SYNC_NOSTR=false \
253 -e NGIT_LOG_LEVEL=INFO \ 282 -e NGIT_LOG_LEVEL=INFO \
254 -v /tmp/ngit-test/repos:/srv/ngit-relay/repos \ 283 -v "$TEST_DIR/repos:/srv/ngit-relay/repos" \
255 -v /tmp/ngit-test/blossom:/srv/ngit-relay/blossom \ 284 -v "$TEST_DIR/blossom:/srv/ngit-relay/blossom" \
256 -v /tmp/ngit-test/relay-db:/srv/ngit-relay/relay-db \ 285 -v "$TEST_DIR/relay-db:/srv/ngit-relay/relay-db" \
257 -v /tmp/ngit-test/logs:/var/log/ngit-relay \ 286 -v "$TEST_DIR/logs:/var/log/ngit-relay" \
258 ghcr.io/danconwaydev/ngit-relay:latest 287 ghcr.io/danconwaydev/ngit-relay:latest
259 288
260echo "โณ Waiting for relay to start..." 289echo "โณ Waiting for relay to start..."
261sleep 3 290sleep 3
262 291
263echo "๐Ÿงช Running tests..." 292echo "๐Ÿงช Running tests..."
264cargo test --ignored 293echo ""
265 294echo "Note: ngit-relay only accepts Git-related events (NIP-34)."
266echo "๐Ÿ›‘ Stopping relay..." 295echo "Some NIP-01 smoke tests will fail (expected behavior)."
267docker stop ngit-relay-test 296echo "Validation tests should pass."
268 297echo ""
269echo "๐Ÿงน Cleaning up..." 298RELAY_URL="ws://localhost:$PORT" cargo test --lib -- --ignored --nocapture
270rm -rf /tmp/ngit-test
271 299
272echo "โœ… Done!" 300echo "โœ… Done!"
273``` 301```