test-docker.sh raw
1 #!/bin/bash
2 set -e
3
4 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5 PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
6
7 echo "=== ORLY Dgraph Docker Integration Test Suite ==="
8 echo ""
9
10 # Colors for output
11 RED='\033[0;31m'
12 GREEN='\033[0;32m'
13 YELLOW='\033[1;33m'
14 NC='\033[0m' # No Color
15
16 # Function to print colored output
17 print_error() {
18 echo -e "${RED}â $1${NC}"
19 }
20
21 print_success() {
22 echo -e "${GREEN}â
$1${NC}"
23 }
24
25 print_info() {
26 echo -e "${YELLOW}âšī¸ $1${NC}"
27 }
28
29 # Check if docker is available
30 if ! command -v docker &> /dev/null; then
31 print_error "Docker is not installed or not in PATH"
32 exit 1
33 fi
34
35 # Check if docker-compose is available
36 if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
37 print_error "Docker Compose is not installed or not in PATH"
38 exit 1
39 fi
40
41 # Determine docker-compose command
42 if docker compose version &> /dev/null 2>&1; then
43 DOCKER_COMPOSE="docker compose"
44 else
45 DOCKER_COMPOSE="docker-compose"
46 fi
47
48 print_info "Using docker-compose command: $DOCKER_COMPOSE"
49 echo ""
50
51 # Change to scripts directory
52 cd "$SCRIPT_DIR"
53
54 # Parse arguments
55 SKIP_BUILD=false
56 KEEP_RUNNING=false
57 RUN_RELAY_TESTER=false
58
59 while [[ $# -gt 0 ]]; do
60 case $1 in
61 --skip-build)
62 SKIP_BUILD=true
63 shift
64 ;;
65 --keep-running)
66 KEEP_RUNNING=true
67 shift
68 ;;
69 --relay-tester)
70 RUN_RELAY_TESTER=true
71 shift
72 ;;
73 *)
74 echo "Unknown option: $1"
75 echo "Usage: $0 [--skip-build] [--keep-running] [--relay-tester]"
76 exit 1
77 ;;
78 esac
79 done
80
81 # Cleanup function
82 cleanup() {
83 if [ "$KEEP_RUNNING" = false ]; then
84 print_info "Cleaning up containers..."
85 $DOCKER_COMPOSE -f docker-compose-test.yml down
86 print_success "Cleanup complete"
87 else
88 print_info "Containers left running (--keep-running)"
89 echo ""
90 print_info "To stop: cd $SCRIPT_DIR && $DOCKER_COMPOSE -f docker-compose-test.yml down"
91 print_info "View logs: $DOCKER_COMPOSE -f docker-compose-test.yml logs -f"
92 print_info "ORLY: http://localhost:3334"
93 print_info "Dgraph: http://localhost:8080"
94 print_info "Ratel: http://localhost:8000"
95 fi
96 }
97
98 # Set trap for cleanup
99 if [ "$KEEP_RUNNING" = false ]; then
100 trap cleanup EXIT
101 fi
102
103 # Stop any existing containers
104 print_info "Stopping any existing containers..."
105 $DOCKER_COMPOSE -f docker-compose-test.yml down --remove-orphans
106 echo ""
107
108 # Build images if not skipping
109 if [ "$SKIP_BUILD" = false ]; then
110 print_info "Building ORLY docker image..."
111 $DOCKER_COMPOSE -f docker-compose-test.yml build orly
112 print_success "Build complete"
113 echo ""
114 fi
115
116 # Start dgraph
117 print_info "Starting dgraph server..."
118 $DOCKER_COMPOSE -f docker-compose-test.yml up -d dgraph
119
120 # Wait for dgraph to be healthy
121 print_info "Waiting for dgraph to be healthy..."
122 MAX_WAIT=60
123 WAITED=0
124 while [ $WAITED -lt $MAX_WAIT ]; do
125 if docker exec orly-dgraph curl -sf http://localhost:8080/health > /dev/null 2>&1; then
126 print_success "Dgraph is healthy"
127 break
128 fi
129 sleep 2
130 WAITED=$((WAITED + 2))
131 if [ $WAITED -ge $MAX_WAIT ]; then
132 print_error "Dgraph failed to become healthy after ${MAX_WAIT}s"
133 docker logs orly-dgraph
134 exit 1
135 fi
136 done
137 echo ""
138
139 # Start ORLY
140 print_info "Starting ORLY relay with dgraph backend..."
141 $DOCKER_COMPOSE -f docker-compose-test.yml up -d orly
142
143 # Wait for ORLY to be healthy
144 print_info "Waiting for ORLY to be healthy..."
145 MAX_WAIT=60
146 WAITED=0
147 while [ $WAITED -lt $MAX_WAIT ]; do
148 if curl -sf http://localhost:3334/ > /dev/null 2>&1; then
149 print_success "ORLY is healthy and responding"
150 break
151 fi
152 sleep 2
153 WAITED=$((WAITED + 2))
154 if [ $WAITED -ge $MAX_WAIT ]; then
155 print_error "ORLY failed to become healthy after ${MAX_WAIT}s"
156 echo ""
157 print_info "ORLY logs:"
158 docker logs orly-relay
159 exit 1
160 fi
161 done
162 echo ""
163
164 # Check ORLY version
165 print_info "Checking ORLY version..."
166 ORLY_VERSION=$(docker exec orly-relay /app/orly version 2>&1 | head -1 || echo "unknown")
167 echo "ORLY version: $ORLY_VERSION"
168 echo ""
169
170 # Verify dgraph connection
171 print_info "Verifying dgraph connection..."
172 if docker logs orly-relay 2>&1 | grep -q "successfully connected to dgraph"; then
173 print_success "ORLY successfully connected to dgraph"
174 elif docker logs orly-relay 2>&1 | grep -q "dgraph"; then
175 print_info "ORLY dgraph logs:"
176 docker logs orly-relay 2>&1 | grep -i dgraph
177 else
178 print_info "No explicit dgraph connection message (may be using badger)"
179 fi
180 echo ""
181
182 # Basic connectivity test
183 print_info "Testing basic relay connectivity..."
184 if curl -sf http://localhost:3334/ > /dev/null 2>&1; then
185 print_success "ORLY is accessible at http://localhost:3334"
186 else
187 print_error "Failed to connect to ORLY"
188 exit 1
189 fi
190 echo ""
191
192 # Test WebSocket connection
193 print_info "Testing WebSocket connection..."
194 if command -v websocat &> /dev/null; then
195 TEST_REQ='["REQ","test",{"kinds":[1],"limit":1}]'
196 if echo "$TEST_REQ" | timeout 5 websocat ws://localhost:3334 2>/dev/null | grep -q "EOSE"; then
197 print_success "WebSocket connection successful"
198 else
199 print_info "WebSocket test inconclusive (may need events)"
200 fi
201 elif command -v wscat &> /dev/null; then
202 print_info "Testing with wscat..."
203 # wscat test would go here
204 else
205 print_info "WebSocket testing tools not available (install websocat or wscat)"
206 fi
207 echo ""
208
209 # Run relay-tester if requested
210 if [ "$RUN_RELAY_TESTER" = true ]; then
211 print_info "Building relay-tester image..."
212 $DOCKER_COMPOSE -f docker-compose-test.yml build relay-tester
213 echo ""
214
215 print_info "Running relay-tester against ORLY..."
216 if $DOCKER_COMPOSE -f docker-compose-test.yml run --rm relay-tester -url ws://orly:3334; then
217 print_success "Relay-tester passed!"
218 else
219 print_error "Relay-tester failed"
220 echo ""
221 print_info "ORLY logs:"
222 docker logs orly-relay --tail 50
223 exit 1
224 fi
225 echo ""
226 fi
227
228 # Show container status
229 print_info "Container status:"
230 $DOCKER_COMPOSE -f docker-compose-test.yml ps
231 echo ""
232
233 # Show useful information
234 print_success "All tests passed!"
235 echo ""
236 print_info "Endpoints:"
237 echo " ORLY WebSocket: ws://localhost:3334"
238 echo " ORLY HTTP: http://localhost:3334"
239 echo " Dgraph HTTP: http://localhost:8080"
240 echo " Dgraph gRPC: localhost:9080"
241 echo " Ratel UI: http://localhost:8000"
242 echo ""
243
244 if [ "$KEEP_RUNNING" = false ]; then
245 print_info "Containers will be stopped on script exit"
246 else
247 print_info "Containers are running. Use --keep-running flag was set."
248 fi
249
250 exit 0
251