Skip to content

Commit a430a58

Browse files
test: add staging smoke-test workflow tests
Implements tests for Issue #922 to verify smoke-test configuration, CI workflow triggers, and deployment verification process. Tests verify: - Smoke-test script coverage of critical endpoints - Proper exit code handling - Environment-specific configuration - CI workflow post-deploy triggers - Failure alerting configuration - Response validation and timeout handling - Independent executability and reusability
1 parent fd55d32 commit a430a58

1 file changed

Lines changed: 286 additions & 0 deletions

File tree

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
#!/usr/bin/env bash
2+
3+
################################################################################
4+
# Tests for Issue #922: Staging Environment Smoke-Test Workflow
5+
#
6+
# Tests verify that:
7+
# - Smoke-test script is properly structured
8+
# - CI workflow triggers smoke-tests on deploy
9+
# - Failure alerts are configured
10+
# - Deployment verification process is documented
11+
#
12+
# Run with: ./scripts/test_smoke_test_workflow.sh
13+
################################################################################
14+
15+
set -e
16+
17+
# Color output
18+
RED='\033[0;31m'
19+
GREEN='\033[0;32m'
20+
YELLOW='\033[1;33m'
21+
BLUE='\033[0;34m'
22+
NC='\033[0m'
23+
24+
test_count=0
25+
pass_count=0
26+
fail_count=0
27+
28+
log_test() {
29+
echo -e "${BLUE}[TEST]${NC} $*"
30+
((test_count++))
31+
}
32+
33+
log_pass() {
34+
echo -e "${GREEN}✓ PASS${NC} $*"
35+
((pass_count++))
36+
}
37+
38+
log_fail() {
39+
echo -e "${RED}✗ FAIL${NC} $*"
40+
((fail_count++))
41+
}
42+
43+
# Test 1: Smoke-test script exists
44+
test_smoke_test_exists() {
45+
log_test "Smoke-test script should exist"
46+
47+
if [[ -f scripts/smoke-test.sh ]] && [[ -x scripts/smoke-test.sh ]]; then
48+
log_pass "smoke-test.sh exists and is executable"
49+
else
50+
log_fail "smoke-test.sh missing or not executable"
51+
fi
52+
}
53+
54+
# Test 2: Smoke-test covers critical endpoints
55+
test_smoke_test_coverage() {
56+
log_test "Smoke-test should cover critical API endpoints"
57+
58+
local required_endpoints=(
59+
"/api/v1/ips"
60+
"/api/v1/swaps"
61+
"/api/v1/stats"
62+
)
63+
64+
local coverage_count=0
65+
for endpoint in "${required_endpoints[@]}"; do
66+
if grep -q "$endpoint" scripts/smoke-test.sh; then
67+
((coverage_count++))
68+
fi
69+
done
70+
71+
if [[ $coverage_count -eq ${#required_endpoints[@]} ]]; then
72+
log_pass "Smoke-test covers all critical endpoints ($coverage_count/${#required_endpoints[@]})"
73+
else
74+
log_fail "Smoke-test missing some endpoints ($coverage_count/${#required_endpoints[@]})"
75+
fi
76+
}
77+
78+
# Test 3: Smoke-test has proper exit codes
79+
test_smoke_test_exit_codes() {
80+
log_test "Smoke-test should have proper exit codes"
81+
82+
# Check for exit 0 on success and exit 1 on failure
83+
if grep -q "exit 1" scripts/smoke-test.sh && grep -q "exit 0\|exit$" scripts/smoke-test.sh; then
84+
log_pass "Smoke-test has proper exit code handling"
85+
else
86+
log_fail "Smoke-test may not have proper exit codes"
87+
fi
88+
}
89+
90+
# Test 4: Smoke-test handles environment variables
91+
test_smoke_test_env_vars() {
92+
log_test "Smoke-test should accept environment variables"
93+
94+
# Check for API_URL and NETWORK env vars
95+
if grep -q "API_URL\|NETWORK" scripts/smoke-test.sh; then
96+
log_pass "Smoke-test accepts environment configuration"
97+
else
98+
log_fail "Smoke-test doesn't use environment variables"
99+
fi
100+
}
101+
102+
# Test 5: CI workflow includes post-deploy trigger
103+
test_ci_workflow_post_deploy_trigger() {
104+
log_test "CI workflow should have post-deploy trigger configuration"
105+
106+
local ci_file=".github/workflows/ci.yml"
107+
if [[ -f "$ci_file" ]]; then
108+
# Check for deployment trigger or workflow_dispatch
109+
if grep -q "deployment\|workflow_dispatch\|push" "$ci_file"; then
110+
log_pass "CI workflow has trigger configuration"
111+
else
112+
log_fail "CI workflow may lack post-deploy trigger"
113+
fi
114+
else
115+
log_fail "CI workflow file not found"
116+
fi
117+
}
118+
119+
# Test 6: Workflow failure alerting is configured
120+
test_workflow_failure_alerting() {
121+
log_test "Workflow should have failure alert configuration"
122+
123+
# Check for notification or failure step
124+
local ci_file=".github/workflows/ci.yml"
125+
if [[ -f "$ci_file" ]]; then
126+
if grep -q "failure\|notify\|alert" "$ci_file"; then
127+
log_pass "Workflow has failure handling configured"
128+
else
129+
log_fail "Workflow lacks failure alerting"
130+
fi
131+
fi
132+
}
133+
134+
# Test 7: Deployment verification documentation
135+
test_deployment_guide_exists() {
136+
log_test "Deployment guide should exist and be documented"
137+
138+
# Check for deployment guide
139+
if [[ -f docs/deployment-guide.md ]]; then
140+
log_pass "Deployment guide exists"
141+
else
142+
# Check if it should be created
143+
if [[ ! -f docs/deployment-guide.md ]]; then
144+
log_fail "Deployment guide not found at docs/deployment-guide.md"
145+
fi
146+
fi
147+
}
148+
149+
# Test 8: Smoke-test response parsing
150+
test_smoke_test_response_validation() {
151+
log_test "Smoke-test should validate API responses"
152+
153+
# Check for response validation (grep on response or jq parsing)
154+
if grep -q "RESPONSE\|jq\|grep" scripts/smoke-test.sh; then
155+
log_pass "Smoke-test validates API responses"
156+
else
157+
log_fail "Smoke-test may not validate responses properly"
158+
fi
159+
}
160+
161+
# Test 9: Smoke-test timeout handling
162+
test_smoke_test_timeout_handling() {
163+
log_test "Smoke-test should have timeout configuration"
164+
165+
# curl should have timeout flags
166+
if grep -q "curl.*--max-time\|curl.*-m\|timeout" scripts/smoke-test.sh; then
167+
log_pass "Smoke-test has timeout handling"
168+
else
169+
log_fail "Smoke-test lacks timeout protection"
170+
fi
171+
}
172+
173+
# Test 10: Deployment flow includes smoke-test
174+
test_deployment_flow_includes_smoke_test() {
175+
log_test "Deployment flow should include smoke-test invocation"
176+
177+
# Check if any deploy script mentions smoke-test
178+
if grep -q "smoke-test" scripts/deploy.sh scripts/deploy_testnet.sh 2>/dev/null; then
179+
log_pass "Deployment scripts reference smoke-test"
180+
else
181+
# Document requirement
182+
log_fail "Deployment scripts should invoke smoke-test"
183+
fi
184+
}
185+
186+
# Test 11: Environment-specific smoke-test configuration
187+
test_environment_specific_config() {
188+
log_test "Smoke-test should support multiple environments"
189+
190+
# Check for network/environment configuration
191+
if grep -q "\$NETWORK\|\$API_URL\|\$ENVIRONMENT" scripts/smoke-test.sh; then
192+
log_pass "Smoke-test supports environment configuration"
193+
else
194+
log_fail "Smoke-test may not support multiple environments"
195+
fi
196+
}
197+
198+
# Test 12: Smoke-test logging
199+
test_smoke_test_logging() {
200+
log_test "Smoke-test should have proper logging output"
201+
202+
# Check for echo statements or logging
203+
if grep -q "echo\|===\|Test" scripts/smoke-test.sh; then
204+
log_pass "Smoke-test has logging and output"
205+
else
206+
log_fail "Smoke-test lacks logging"
207+
fi
208+
}
209+
210+
# Test 13: Dry-run support for smoke-tests
211+
test_smoke_test_dry_run() {
212+
log_test "Smoke-test should support dry-run mode"
213+
214+
# Check for dry-run or --dry-run flag support
215+
if grep -q "dry.run\|DRY_RUN" scripts/smoke-test.sh; then
216+
log_pass "Smoke-test supports dry-run mode"
217+
else
218+
# Document requirement
219+
log_fail "Smoke-test should support dry-run for safety"
220+
fi
221+
}
222+
223+
# Test 14: Smoke-test can be run independently
224+
test_smoke_test_independence() {
225+
log_test "Smoke-test should be runnable independently"
226+
227+
# Should not require deployment as prerequisite
228+
if [[ -x scripts/smoke-test.sh ]]; then
229+
log_pass "Smoke-test is independently executable"
230+
else
231+
log_fail "Smoke-test is not independently executable"
232+
fi
233+
}
234+
235+
# Test 15: Workflow reusability
236+
test_workflow_is_reusable() {
237+
log_test "Smoke-test workflow should be reusable"
238+
239+
# Should have parameters for different scenarios
240+
local ci_file=".github/workflows/ci.yml"
241+
if [[ -f "$ci_file" ]]; then
242+
# Check for inputs or on: parameters
243+
if grep -q "on:\|inputs:" "$ci_file"; then
244+
log_pass "Workflow has reusable configuration"
245+
else
246+
log_fail "Workflow may not be reusable"
247+
fi
248+
fi
249+
}
250+
251+
# Main execution
252+
main() {
253+
echo ""
254+
echo -e "${BLUE}=== Smoke-Test Workflow Tests ===${NC}"
255+
echo ""
256+
257+
test_smoke_test_exists
258+
test_smoke_test_coverage
259+
test_smoke_test_exit_codes
260+
test_smoke_test_env_vars
261+
test_ci_workflow_post_deploy_trigger
262+
test_workflow_failure_alerting
263+
test_deployment_guide_exists
264+
test_smoke_test_response_validation
265+
test_smoke_test_timeout_handling
266+
test_deployment_flow_includes_smoke_test
267+
test_environment_specific_config
268+
test_smoke_test_logging
269+
test_smoke_test_dry_run
270+
test_smoke_test_independence
271+
test_workflow_is_reusable
272+
273+
echo ""
274+
echo -e "${BLUE}=== Test Results ===${NC}"
275+
echo "Total: $test_count | Passed: $pass_count | Failed: $fail_count"
276+
277+
if [[ $fail_count -eq 0 ]]; then
278+
echo -e "${GREEN}All tests passed!${NC}"
279+
exit 0
280+
else
281+
echo -e "${RED}Some tests failed or documented requirements.${NC}"
282+
exit 1
283+
fi
284+
}
285+
286+
main

0 commit comments

Comments
 (0)