Skip to content

Commit 3e8dcac

Browse files
committed
test: [Web4 CLI #537] Complete Functional Testing (Domains & Deployments)
- Add comprehensive Web4 CLI functional test suite - Implement 7-phase testing (Registration → Deployment → Persistence → Updates → Rollback → Deletion → Error Handling) - Create automated test site generator with version tracking - Add CLI command wrappers with proper parsing - Implement state verification and persistence testing - Add comprehensive error handling and edge case testing - Include bug report template and test documentation - Test manifest architecture (web4_manifest_cid vs manifest_cid) - Validate persistence across node restarts (CRITICAL requirement) - Test version rollback functionality - Verify domain registration/deletion workflows - All tests use proper CLI command execution and validation Test Files: - web4_functional.rs: 28+ test scenarios across 7 phases - web4_functional/test_env.rs: Isolated test environment management - web4_functional/cli_executor.rs: CLI command wrapper with parsing - web4_functional/site_generator.rs: Automated test site creation - web4_functional/state_verifier.rs: State verification utilities - scripts/run_web4_functional_tests.sh: Automated test runner with reporting - tests/WEB4_FUNCTIONAL_TESTING.md: Complete testing documentation - tests/web4_functional_bug_report_template.md: Bug report template Completes requirement: Test: Web4 CLI Complete Functional Testing (Domains & Deployments) #537
1 parent d6900bf commit 3e8dcac

File tree

11 files changed

+3551
-0
lines changed

11 files changed

+3551
-0
lines changed
Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
#!/bin/bash
2+
3+
###############################################################################
4+
# Web4 CLI Functional Testing Runner
5+
#
6+
# Comprehensive test suite for Web4 CLI domain and deployment functionality.
7+
# Executes 7-phase testing covering: Registration → Deployment → Persistence →
8+
# Updates → Rollback → Deletion → Error Handling
9+
#
10+
# Usage:
11+
# ./run_web4_functional_tests.sh [phase] [options]
12+
#
13+
# Examples:
14+
# ./run_web4_functional_tests.sh # Run all tests
15+
# ./run_web4_functional_tests.sh registration # Run registration phase only
16+
# ./run_web4_functional_tests.sh --verbose # Run with verbose output
17+
# ./run_web4_functional_tests.sh --nocapture # Show println! output
18+
#
19+
###############################################################################
20+
21+
set -e
22+
23+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
25+
TEST_PHASE="${1:-all}"
26+
VERBOSE="${VERBOSE:-0}"
27+
NOCAPTURE="${NOCAPTURE:-0}"
28+
29+
# Color codes for output
30+
RED='\033[0;31m'
31+
GREEN='\033[0;32m'
32+
YELLOW='\033[1;33m'
33+
BLUE='\033[0;34m'
34+
NC='\033[0m' # No Color
35+
36+
###############################################################################
37+
# Utility Functions
38+
###############################################################################
39+
40+
log_info() {
41+
echo -e "${BLUE}[INFO]${NC} $*"
42+
}
43+
44+
log_success() {
45+
echo -e "${GREEN}[✓]${NC} $*"
46+
}
47+
48+
log_error() {
49+
echo -e "${RED}[✗]${NC} $*"
50+
}
51+
52+
log_warning() {
53+
echo -e "${YELLOW}[⚠]${NC} $*"
54+
}
55+
56+
log_section() {
57+
echo ""
58+
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}"
59+
echo -e "${BLUE} $*${NC}"
60+
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}"
61+
}
62+
63+
print_usage() {
64+
cat << EOF
65+
${BLUE}Web4 CLI Functional Testing Runner${NC}
66+
67+
${GREEN}Usage:${NC}
68+
$(basename "$0") [PHASE] [OPTIONS]
69+
70+
${GREEN}Phases:${NC}
71+
all Run all test phases (default)
72+
registration Test domain registration functionality
73+
deployment Test site deployment and manifest validation
74+
persistence Test state persistence across restarts
75+
updates Test version management and updates
76+
rollback Test version rollback functionality
77+
deletion Test domain deletion and cleanup
78+
errors Test error handling and edge cases
79+
integration Test complete workflows and integration scenarios
80+
81+
${GREEN}Options:${NC}
82+
--verbose Show detailed test output
83+
--nocapture Display println! output from tests
84+
--release Build and test in release mode
85+
--help Show this help message
86+
87+
${GREEN}Environment Variables:${NC}
88+
RUST_LOG=<level> Set logging level (debug, info, warn, error)
89+
TEST_THREADS=N Number of parallel test threads (default: 1 for isolation)
90+
91+
${GREEN}Examples:${NC}
92+
# Run all tests with verbose output
93+
$(basename "$0") all --verbose
94+
95+
# Run registration tests only, display println output
96+
$(basename "$0") registration --nocapture
97+
98+
# Run with debug logging
99+
RUST_LOG=debug $(basename "$0") all
100+
101+
# Run specific test
102+
cargo test --test web4_functional registration_ -- --nocapture
103+
104+
EOF
105+
}
106+
107+
###############################################################################
108+
# Build and Dependency Checks
109+
###############################################################################
110+
111+
check_dependencies() {
112+
log_info "Checking dependencies..."
113+
114+
if ! command -v cargo &> /dev/null; then
115+
log_error "Cargo not found. Please install Rust."
116+
exit 1
117+
fi
118+
119+
if ! command -v jq &> /dev/null; then
120+
log_warning "jq not found. Some output parsing features will be limited."
121+
fi
122+
123+
log_success "All required dependencies found"
124+
}
125+
126+
build_tests() {
127+
log_info "Building test suite..."
128+
129+
cd "$PROJECT_ROOT"
130+
131+
local build_cmd="cargo build --tests"
132+
if [[ "$BUILD_MODE" == "release" ]]; then
133+
build_cmd="$build_cmd --release"
134+
fi
135+
136+
if ! $build_cmd 2>&1 | grep -E "(Compiling|Finished|error)" ; then
137+
log_error "Build failed"
138+
return 1
139+
fi
140+
141+
log_success "Test suite built successfully"
142+
}
143+
144+
###############################################################################
145+
# Test Execution
146+
###############################################################################
147+
148+
run_all_tests() {
149+
log_section "Running Complete Web4 CLI Functional Test Suite"
150+
151+
local test_cmd="cargo test --test web4_functional"
152+
153+
[[ "$NOCAPTURE" == "1" ]] && test_cmd="$test_cmd --nocapture"
154+
[[ "$BUILD_MODE" == "release" ]] && test_cmd="$test_cmd --release"
155+
156+
cd "$PROJECT_ROOT/zhtp-cli"
157+
158+
if $test_cmd -- --test-threads=1; then
159+
log_success "All tests passed!"
160+
return 0
161+
else
162+
log_error "Some tests failed"
163+
return 1
164+
fi
165+
}
166+
167+
run_phase_tests() {
168+
local phase="$1"
169+
local phase_name=""
170+
local test_filter=""
171+
172+
case "$phase" in
173+
registration)
174+
phase_name="Domain Registration"
175+
test_filter="registration_"
176+
;;
177+
deployment)
178+
phase_name="Deployment"
179+
test_filter="deployment_"
180+
;;
181+
persistence)
182+
phase_name="Persistence"
183+
test_filter="persistence_"
184+
;;
185+
updates)
186+
phase_name="Updates"
187+
test_filter="updates_"
188+
;;
189+
rollback)
190+
phase_name="Rollback"
191+
test_filter="rollback_"
192+
;;
193+
deletion)
194+
phase_name="Deletion"
195+
test_filter="deletion_"
196+
;;
197+
errors)
198+
phase_name="Error Handling"
199+
test_filter="error_"
200+
;;
201+
integration)
202+
phase_name="Integration"
203+
test_filter="integration_"
204+
;;
205+
*)
206+
log_error "Unknown phase: $phase"
207+
return 1
208+
;;
209+
esac
210+
211+
log_section "Running Phase: $phase_name"
212+
213+
local test_cmd="cargo test --test web4_functional $test_filter"
214+
215+
[[ "$NOCAPTURE" == "1" ]] && test_cmd="$test_cmd --nocapture"
216+
[[ "$BUILD_MODE" == "release" ]] && test_cmd="$test_cmd --release"
217+
218+
cd "$PROJECT_ROOT/zhtp-cli"
219+
220+
if $test_cmd -- --test-threads=1; then
221+
log_success "Phase '$phase_name' completed successfully!"
222+
return 0
223+
else
224+
log_error "Phase '$phase_name' had failures"
225+
return 1
226+
fi
227+
}
228+
229+
###############################################################################
230+
# Test Reporting
231+
###############################################################################
232+
233+
generate_test_report() {
234+
log_section "Test Execution Summary"
235+
236+
log_info "Test Suite: Web4 CLI Functional Testing"
237+
log_info "Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
238+
log_info "Test Count: Comprehensive (7 phases, 25+ test scenarios)"
239+
log_info "Coverage Areas:"
240+
log_info " • Domain Registration (unique, duplicates, metadata)"
241+
log_info " • Deployment (files, manifests, validation)"
242+
log_info " • Persistence (state across restarts)"
243+
log_info " • Updates (versions, content changes)"
244+
log_info " • Rollback (previous versions)"
245+
log_info " • Deletion (cleanup, isolation)"
246+
log_info " • Error Handling (invalid input, edge cases)"
247+
log_info " • Integration (complete workflows)"
248+
249+
if [[ "$TEST_RESULT" == "0" ]]; then
250+
log_success "All tests passed successfully"
251+
else
252+
log_error "Some tests failed - see output above for details"
253+
fi
254+
}
255+
256+
###############################################################################
257+
# Main Entry Point
258+
###############################################################################
259+
260+
main() {
261+
# Parse arguments
262+
while [[ $# -gt 0 ]]; do
263+
case $1 in
264+
--help|-h)
265+
print_usage
266+
exit 0
267+
;;
268+
--verbose)
269+
VERBOSE=1
270+
shift
271+
;;
272+
--nocapture)
273+
NOCAPTURE=1
274+
shift
275+
;;
276+
--release)
277+
BUILD_MODE="release"
278+
shift
279+
;;
280+
all|registration|deployment|persistence|updates|rollback|deletion|errors|integration)
281+
TEST_PHASE="$1"
282+
shift
283+
;;
284+
*)
285+
log_error "Unknown option: $1"
286+
print_usage
287+
exit 1
288+
;;
289+
esac
290+
done
291+
292+
# Execution flow
293+
log_info "Web4 CLI Functional Testing Suite"
294+
log_info "=================================="
295+
296+
check_dependencies
297+
build_tests
298+
299+
TEST_RESULT=0
300+
301+
if [[ "$TEST_PHASE" == "all" ]]; then
302+
run_all_tests || TEST_RESULT=$?
303+
else
304+
run_phase_tests "$TEST_PHASE" || TEST_RESULT=$?
305+
fi
306+
307+
generate_test_report
308+
309+
exit $TEST_RESULT
310+
}
311+
312+
# Run main function
313+
main "$@"

0 commit comments

Comments
 (0)