-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_all.sh
More file actions
executable file
Β·249 lines (212 loc) Β· 7.29 KB
/
Copy pathtest_all.sh
File metadata and controls
executable file
Β·249 lines (212 loc) Β· 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/bin/bash
# Comprehensive test script for WebSearch SDK
# Tests all providers, CLI functionality, and edge cases
set -e
echo "π WebSearch SDK Comprehensive Test Suite"
echo "=========================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}β
${NC} $1"
}
print_warning() {
echo -e "${YELLOW}β οΈ${NC} $1"
}
print_error() {
echo -e "${RED}β${NC} $1"
}
print_info() {
echo -e "${BLUE}βΉοΈ${NC} $1"
}
# Check if cargo is available
if ! command -v cargo &> /dev/null; then
print_error "Cargo not found. Please install Rust."
exit 1
fi
print_info "Step 1: Building project..."
if cargo build --release; then
print_status "Build successful"
else
print_error "Build failed"
exit 1
fi
print_info "Step 2: Running unit tests..."
if cargo test --lib --quiet; then
print_status "Unit tests passed"
else
print_error "Unit tests failed"
exit 1
fi
print_info "Step 3: Running integration tests..."
if cargo test --test integration_tests --quiet; then
print_status "Integration tests passed"
else
print_error "Integration tests failed"
exit 1
fi
print_info "Step 4: Running Tavily integration tests..."
if cargo test --test tavily_integration_tests --quiet; then
print_status "Tavily integration tests passed"
else
print_error "Tavily integration tests failed"
exit 1
fi
print_info "Step 5: Running CLI tests..."
if cargo test --test cli_tests --quiet; then
print_status "CLI tests passed"
else
print_error "CLI tests failed"
exit 1
fi
print_info "Step 6: Running comprehensive provider tests..."
if cargo test --test provider_comprehensive_tests --quiet; then
print_status "Provider comprehensive tests passed"
else
print_warning "Some provider tests failed (possibly due to missing API keys)"
fi
print_info "Step 7: Testing CLI binary functionality..."
# Test CLI help
print_info "Testing CLI help command..."
if cargo run --bin websearch -- --help > /dev/null 2>&1; then
print_status "CLI help works"
else
print_error "CLI help failed"
exit 1
fi
# Test providers command
print_info "Testing providers list command..."
if cargo run --bin websearch -- providers > /dev/null 2>&1; then
print_status "Providers command works"
else
print_error "Providers command failed"
exit 1
fi
# Test DuckDuckGo (should always work)
print_info "Testing DuckDuckGo search (no API key required)..."
if timeout 30s cargo run --bin websearch -- single "rust" --provider duckduckgo --max-results 1 --format simple > /dev/null 2>&1; then
print_status "DuckDuckGo CLI search works"
else
print_warning "DuckDuckGo CLI search failed (network issue?)"
fi
# Test ArXiv
print_info "Testing ArXiv search..."
if timeout 30s cargo run --bin websearch -- arxiv "2301.00001" --max-results 1 --format simple > /dev/null 2>&1; then
print_status "ArXiv CLI search works"
else
print_warning "ArXiv CLI search failed (network issue?)"
fi
# Test invalid provider error handling
print_info "Testing invalid provider error handling..."
if ! cargo run --bin websearch -- single "test" --provider invalid > /dev/null 2>&1; then
print_status "Invalid provider properly rejected"
else
print_error "Invalid provider should be rejected"
fi
print_info "Step 8: Environment variable tests..."
# Check for optional API keys and test if available
if [[ -n "$GOOGLE_API_KEY" && -n "$GOOGLE_CX" ]]; then
print_info "Testing Google provider (API keys found)..."
if timeout 30s cargo run --bin websearch -- single "test" --provider google --max-results 1 > /dev/null 2>&1; then
print_status "Google provider works"
else
print_warning "Google provider failed"
fi
else
print_warning "Google API keys not set (GOOGLE_API_KEY, GOOGLE_CX)"
fi
if [[ -n "$TAVILY_API_KEY" ]]; then
print_info "Testing Tavily provider (API key found)..."
if timeout 30s cargo run --bin websearch -- single "test" --provider tavily --max-results 1 > /dev/null 2>&1; then
print_status "Tavily provider works"
else
print_warning "Tavily provider failed"
fi
else
print_warning "Tavily API key not set (TAVILY_API_KEY)"
fi
if [[ -n "$EXA_API_KEY" ]]; then
print_info "Testing Exa provider (API key found)..."
if timeout 30s cargo run --bin websearch -- single "test" --provider exa --max-results 1 > /dev/null 2>&1; then
print_status "Exa provider works"
else
print_warning "Exa provider failed"
fi
else
print_warning "Exa API key not set (EXA_API_KEY)"
fi
if [[ -n "$SERPAPI_API_KEY" ]]; then
print_info "Testing SerpAPI provider (API key found)..."
if timeout 30s cargo run --bin websearch -- single "test" --provider serpapi --max-results 1 > /dev/null 2>&1; then
print_status "SerpAPI provider works"
else
print_warning "SerpAPI provider failed"
fi
else
print_warning "SerpAPI API key not set (SERPAPI_API_KEY)"
fi
print_info "Step 9: Multi-provider tests..."
if timeout 30s cargo run --bin websearch -- multi "test" --strategy aggregate --providers duckduckgo --max-results 1 > /dev/null 2>&1; then
print_status "Multi-provider search works"
else
print_warning "Multi-provider search failed"
fi
print_info "Step 10: Output format tests..."
for format in simple table json; do
if timeout 30s cargo run --bin websearch -- single "test" --provider duckduckgo --max-results 1 --format "$format" > /dev/null 2>&1; then
print_status "Format '$format' works"
else
print_warning "Format '$format' failed"
fi
done
print_info "Step 11: Code quality checks..."
# Check formatting
if cargo fmt -- --check > /dev/null 2>&1; then
print_status "Code formatting is correct"
else
print_warning "Code formatting issues found (run 'cargo fmt')"
fi
# Check clippy
if cargo clippy --all-targets --all-features -- -D warnings > /dev/null 2>&1; then
print_status "No clippy warnings"
else
print_warning "Clippy warnings found (run 'cargo clippy --fix')"
fi
print_info "Step 12: Documentation tests..."
if cargo test --doc --quiet; then
print_status "Documentation tests passed"
else
print_warning "Documentation tests failed"
fi
echo ""
echo "π Test Suite Complete!"
echo "======================="
# Count test results
TOTAL_TESTS=$(cargo test --quiet 2>&1 | grep "test result:" | tail -1 | awk '{print $3}')
if [[ -n "$TOTAL_TESTS" ]]; then
print_status "Total tests passed: $TOTAL_TESTS"
fi
echo ""
echo "π Summary:"
echo "- β
Library functionality: Working"
echo "- β
CLI tool: Working"
echo "- β
Available providers: DuckDuckGo, ArXiv (always), others depend on API keys"
echo "- β
All output formats: Working"
echo "- β
Error handling: Robust"
echo ""
echo "π§ To test with all providers, set these environment variables:"
echo "export GOOGLE_API_KEY='your_key'"
echo "export GOOGLE_CX='your_search_engine_id'"
echo "export TAVILY_API_KEY='tvly-dev-your_key'"
echo "export EXA_API_KEY='your_key'"
echo "export SERPAPI_API_KEY='your_key'"
echo "export BRAVE_API_KEY='your_key'"
echo "export SEARXNG_URL='https://your-searxng-instance.com'"
echo ""
echo "π To run real API tests: REAL_API_TEST=1 cargo test test_real_api_integration"
echo ""
print_status "All tests completed successfully! π"