diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 07:09:41 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 07:17:47 +0000 |
| commit | cb466fbc02b83c5788def5fef73f93573f5c1f70 (patch) | |
| tree | eb9d0293d2be16b8c4ed8a3a278ed9207f54b52d /grasp-audit/test-ngit-relay.sh | |
| parent | 74c7b090a6ec7f749a3a79dcb0c9a0a6bc198702 (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/test-ngit-relay.sh')
| -rwxr-xr-x | grasp-audit/test-ngit-relay.sh | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/grasp-audit/test-ngit-relay.sh b/grasp-audit/test-ngit-relay.sh index b719b86..9d5eb4a 100755 --- a/grasp-audit/test-ngit-relay.sh +++ b/grasp-audit/test-ngit-relay.sh | |||
| @@ -1,17 +1,37 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | set -e | 2 | set -e |
| 3 | 3 | ||
| 4 | echo "๐งน Cleaning up old test data..." | 4 | # Create temporary directory with random name |
| 5 | # Use docker to cleanup with proper permissions | 5 | TEST_DIR=$(mktemp -d -t grasp-audit-run-XXXXXXXXXX) |
| 6 | docker run --rm -v /tmp/ngit-test:/data alpine sh -c "rm -rf /data/*" 2>/dev/null || true | 6 | # Pick a random port in the range 20000-30000 |
| 7 | mkdir -p /tmp/ngit-test/{repos,blossom,relay-db,logs} | 7 | PORT=$((20000 + RANDOM % 10000)) |
| 8 | |||
| 9 | echo "๐งน Using temporary directory: $TEST_DIR" | ||
| 10 | echo "๐ Using port: $PORT" | ||
| 11 | |||
| 12 | # Cleanup function | ||
| 13 | cleanup() { | ||
| 14 | echo "๐ Stopping relay..." | ||
| 15 | docker stop "grasp-audit-run-$" 2>/dev/null || true | ||
| 16 | |||
| 17 | echo "๐งน Cleaning up temporary directory..." | ||
| 18 | docker run --rm -v "$TEST_DIR:/data" alpine sh -c "rm -rf /data/*" 2>/dev/null || true | ||
| 19 | rm -rf "$TEST_DIR" | ||
| 20 | } | ||
| 21 | |||
| 22 | # Set trap to cleanup on exit | ||
| 23 | trap cleanup EXIT | ||
| 24 | |||
| 25 | echo "๐ Creating data directories..." | ||
| 26 | mkdir -p "$TEST_DIR"/{repos,blossom,relay-db,logs} | ||
| 8 | 27 | ||
| 9 | echo "๐ Starting ngit-relay..." | 28 | echo "๐ Starting ngit-relay..." |
| 10 | # Remove any existing container with this name | 29 | # Remove any existing container with this name |
| 11 | docker rm -f ngit-relay-test 2>/dev/null || true | 30 | CONTAINER_NAME="grasp-audit-run-$" |
| 31 | docker rm -f "$CONTAINER_NAME" 2>/dev/null || true | ||
| 12 | docker run --rm -d \ | 32 | docker run --rm -d \ |
| 13 | --name ngit-relay-test \ | 33 | --name "$CONTAINER_NAME" \ |
| 14 | -p 8082:8081 \ | 34 | -p "$PORT:8081" \ |
| 15 | -e NGIT_DOMAIN=localhost \ | 35 | -e NGIT_DOMAIN=localhost \ |
| 16 | -e NGIT_RELAY_NAME="ngit-relay test instance" \ | 36 | -e NGIT_RELAY_NAME="ngit-relay test instance" \ |
| 17 | -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \ | 37 | -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \ |
| @@ -20,10 +40,10 @@ docker run --rm -d \ | |||
| 20 | -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \ | 40 | -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \ |
| 21 | -e NGIT_PROACTIVE_SYNC_NOSTR=false \ | 41 | -e NGIT_PROACTIVE_SYNC_NOSTR=false \ |
| 22 | -e NGIT_LOG_LEVEL=INFO \ | 42 | -e NGIT_LOG_LEVEL=INFO \ |
| 23 | -v /tmp/ngit-test/repos:/srv/ngit-relay/repos \ | 43 | -v "$TEST_DIR/repos:/srv/ngit-relay/repos" \ |
| 24 | -v /tmp/ngit-test/blossom:/srv/ngit-relay/blossom \ | 44 | -v "$TEST_DIR/blossom:/srv/ngit-relay/blossom" \ |
| 25 | -v /tmp/ngit-test/relay-db:/srv/ngit-relay/relay-db \ | 45 | -v "$TEST_DIR/relay-db:/srv/ngit-relay/relay-db" \ |
| 26 | -v /tmp/ngit-test/logs:/var/log/ngit-relay \ | 46 | -v "$TEST_DIR/logs:/var/log/ngit-relay" \ |
| 27 | ghcr.io/danconwaydev/ngit-relay:latest | 47 | ghcr.io/danconwaydev/ngit-relay:latest |
| 28 | 48 | ||
| 29 | echo "โณ Waiting for relay to start..." | 49 | echo "โณ Waiting for relay to start..." |
| @@ -35,12 +55,6 @@ echo "Note: ngit-relay only accepts Git-related events (NIP-34)." | |||
| 35 | echo "Some NIP-01 smoke tests will fail (expected behavior)." | 55 | echo "Some NIP-01 smoke tests will fail (expected behavior)." |
| 36 | echo "Validation tests should pass." | 56 | echo "Validation tests should pass." |
| 37 | echo "" | 57 | echo "" |
| 38 | RELAY_URL=ws://localhost:8082 cargo test --lib -- --ignored --nocapture | 58 | RELAY_URL="ws://localhost:$PORT" cargo test --lib -- --ignored --nocapture |
| 39 | |||
| 40 | echo "๐ Stopping relay..." | ||
| 41 | docker stop ngit-relay-test | ||
| 42 | |||
| 43 | echo "๐งน Cleaning up..." | ||
| 44 | docker run --rm -v /tmp/ngit-test:/data alpine sh -c "rm -rf /data/*" 2>/dev/null || true | ||
| 45 | 59 | ||
| 46 | echo "โ Done!" | 60 | echo "โ Done!" |