-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·1216 lines (1117 loc) · 44.5 KB
/
test.sh
File metadata and controls
executable file
·1216 lines (1117 loc) · 44.5 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Load environment variables from .env file
set -a
if [ -f .env ]; then
# shellcheck disable=SC1091
. .env
fi
set +a
# Set CGO environment variables for packages that need C dependencies (like gosseract)
export CGO_CPPFLAGS="-I/opt/homebrew/include -I/opt/homebrew/Cellar/leptonica/1.86.0/include -I/opt/homebrew/Cellar/tesseract/5.5.1/include"
export CGO_LDFLAGS="-L/opt/homebrew/lib"
# Weave CLI Test Suite
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${BLUE}[TEST]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_help() {
echo -e "${BLUE}Weave CLI Test Suite${NC}"
echo ""
echo "Usage: ./test.sh [COMMAND] [FLAGS]"
echo ""
echo "Commands:"
echo " unit Run only unit tests"
echo " integration Run only integration tests"
echo " stack Run weave stack integration tests"
echo " fast Run fast tests (unit + mock integration)"
echo " all Run all tests (unit + integration)"
echo " coverage Run tests with coverage report"
echo " help Show this help message"
echo ""
echo "Flags for 'integration' command:"
echo " --weaviate Run only Weaviate integration tests"
echo " --milvus Run only Milvus integration tests"
echo " --supabase Run only Supabase integration tests"
echo " --mongodb Run only MongoDB integration tests"
echo " --chroma Run only Chroma integration tests"
echo " --qdrant Run only Qdrant integration tests"
echo " --neo4j Run only Neo4j integration tests"
echo " --pinecone Run only Pinecone integration tests"
echo " --mcp Run only MCP integration tests"
echo " --skip Skip specified tests (e.g., --skip mcp,weaviate,neo4j,pinecone)"
echo ""
echo "Examples:"
echo " ./test.sh unit # Run only unit tests"
echo " ./test.sh integration # Run all integration tests"
echo " ./test.sh stack # Run weave stack tests only"
echo " ./test.sh stack integration # Run stack tests + all integration tests"
echo " ./test.sh stack integration --weaviate # Run stack tests + Weaviate integration"
echo " ./test.sh integration --weaviate # Run only Weaviate integration tests"
echo " ./test.sh integration --milvus # Run only Milvus integration tests"
echo " ./test.sh integration --supabase # Run only Supabase integration tests"
echo " ./test.sh integration --mongodb # Run only MongoDB integration tests"
echo " ./test.sh integration --chroma # Run only Chroma integration tests"
echo " ./test.sh integration --qdrant # Run only Qdrant integration tests"
echo " ./test.sh integration --neo4j # Run only Neo4j integration tests"
echo " ./test.sh integration --pinecone # Run only Pinecone integration tests"
echo " ./test.sh integration --mcp # Run only MCP integration tests"
echo " ./test.sh integration --skip mcp,weaviate,neo4j,pinecone # Skip MCP, Weaviate, Neo4j, and Pinecone tests"
echo " ./test.sh fast # Run fast tests (unit + mock integration)"
echo " ./test.sh all # Run all tests"
echo " ./test.sh coverage # Run tests with coverage report"
echo " ./test.sh # Run unit tests (default)"
echo ""
echo "Test Categories:"
echo " Unit Tests:"
echo " - Configuration management testing"
echo " - Mock client testing"
echo " - Utility function testing"
echo ""
echo " Integration Tests:"
echo " - Weaviate client testing (requires WEAVIATE_URL, WEAVIATE_API_KEY, OPENAI_API_KEY)"
echo " - Milvus client testing (requires Milvus running locally at localhost:19530)"
echo " - Supabase client testing (requires SUPABASE_DATABASE_URL, SUPABASE_DATABASE_KEY)"
echo " - MongoDB client testing (requires MONGODB_URI, MONGODB_DATABASE)"
echo " - Chroma client testing (requires Chroma running locally at localhost:8000)"
echo " - Qdrant client testing (requires Qdrant running locally at localhost:6333)"
echo " - Neo4j client testing (requires Neo4j running locally at localhost:7687, NEO4J_PASSWORD)"
echo " - Pinecone client testing (requires PINECONE_API_KEY, OPENAI_API_KEY)"
echo " - MCP server testing (requires OPENAI_API_KEY, WEAVE_MCP_STDIO_PATH)"
echo " - CLI command testing"
echo " - End-to-end workflow testing"
}
# Initialize variables
RUN_UNIT_TESTS=false
RUN_INTEGRATION_TESTS=false
RUN_COVERAGE=false
# Global variables for integration test summary (must be global for trap handler)
declare -a vdb_names=()
declare -a vdb_status=()
declare -a vdb_passed=()
declare -a vdb_failed=()
total_suites=0
passed_suites=0
failed_suites=0
skipped_suites=0
# Check command line arguments
case "${1:-unit}" in
"unit")
RUN_UNIT_TESTS=true
RUN_INTEGRATION_TESTS=false
RUN_COVERAGE=false
;;
"integration")
RUN_UNIT_TESTS=false
RUN_INTEGRATION_TESTS=true
RUN_COVERAGE=false
;;
"stack")
# Stack tests handled separately below
;;
"fast")
RUN_UNIT_TESTS=true
RUN_INTEGRATION_TESTS=true
RUN_COVERAGE=false
;;
"all")
RUN_UNIT_TESTS=true
RUN_INTEGRATION_TESTS=true
RUN_COVERAGE=false
;;
"coverage")
RUN_UNIT_TESTS=false
RUN_INTEGRATION_TESTS=false
RUN_COVERAGE=true
;;
"help"|"-h"|"--help")
print_help
exit 0
;;
*)
print_error "Unknown command: $1"
echo ""
print_help
exit 1
;;
esac
# Function to run unit tests
run_unit_tests() {
print_header "Running Unit Tests..."
# Check if Go is installed
if ! command -v go >/dev/null 2>&1; then
print_error "Go is not installed. Please install Go 1.21 or later."
exit 1
fi
# Run unit tests
print_status "Running unit tests..."
if go test -v -timeout=30s ./tests/... ./src/pkg/vectordb/mongodb/... -run="TestConfig|TestMock|TestWeaviateClient|TestFactory|TestDocumentConversion|TestGetTimeout|TestGetDefaultSchema|TestValidateSchema|TestMongoDBFactory|TestMongoDBClient"; then
print_success "Unit tests passed!"
else
print_error "Unit tests failed!"
exit 1
fi
}
# Function to run integration tests
run_integration_tests() {
print_header "Running Integration Tests..."
# Check if Go is installed
if ! command -v go >/dev/null 2>&1; then
print_error "Go is not installed. Please install Go 1.21 or later."
exit 1
fi
# Reset global counters and arrays for this test run
total_suites=0
passed_suites=0
failed_suites=0
skipped_suites=0
vdb_names=()
vdb_status=()
vdb_passed=()
vdb_failed=()
# Trap to ensure summary is always printed (even on Ctrl+C or error)
trap 'print_integration_summary; trap - EXIT' EXIT INT TERM
# Parse integration test flags
local run_weaviate=false
local run_milvus=false
local run_supabase=false
local run_mongodb=false
local run_chroma=false
local run_qdrant=false
local run_neo4j=false
local run_pinecone=false
local run_mcp=false
local run_all=true
# Skip flags
local skip_weaviate=false
local skip_milvus=false
local skip_supabase=false
local skip_mongodb=false
local skip_chroma=false
local skip_qdrant=false
local skip_neo4j=false
local skip_pinecone=false
local skip_mcp=false
local in_skip_mode=false
# Check for specific flags
for arg in "$@"; do
# Check if we're in skip mode (collecting tests to skip)
if [ "$in_skip_mode" = true ]; then
# Handle comma-separated values
IFS=',' read -ra SKIP_ITEMS <<< "$arg"
for item in "${SKIP_ITEMS[@]}"; do
case "$item" in
weaviate)
skip_weaviate=true
;;
milvus)
skip_milvus=true
;;
supabase)
skip_supabase=true
;;
mongodb)
skip_mongodb=true
;;
chroma)
skip_chroma=true
;;
qdrant)
skip_qdrant=true
;;
neo4j)
skip_neo4j=true
;;
pinecone)
skip_pinecone=true
;;
mcp)
skip_mcp=true
;;
esac
done
# Check if this arg starts with -- to exit skip mode
if [[ "$arg" == --* ]]; then
in_skip_mode=false
else
# Only process one skip argument then exit skip mode
in_skip_mode=false
continue
fi
fi
case "$arg" in
--weaviate)
run_weaviate=true
run_all=false
;;
--milvus)
run_milvus=true
run_all=false
;;
--supabase)
run_supabase=true
run_all=false
;;
--mongodb)
run_mongodb=true
run_all=false
;;
--chroma)
run_chroma=true
run_all=false
;;
--qdrant)
run_qdrant=true
run_all=false
;;
--neo4j)
run_neo4j=true
run_all=false
;;
--pinecone)
run_pinecone=true
run_all=false
;;
--mcp)
run_mcp=true
run_all=false
;;
--skip)
in_skip_mode=true
;;
esac
done
# If run_all is true, enable all tests
if [ "$run_all" = true ]; then
run_weaviate=true
run_milvus=true
run_supabase=true
run_mongodb=true
run_chroma=true
run_qdrant=true
run_neo4j=true
run_pinecone=true
run_mcp=true
# Run fast integration tests (mock only)
print_status "Running fast integration tests (mock)..."
total_suites=$((total_suites + 1))
if go test -v -timeout=10s -count=1 ./tests/... -run="TestMock"; then
print_success "Fast integration tests passed!"
passed_suites=$((passed_suites + 1))
else
print_warning "Fast integration tests failed"
failed_suites=$((failed_suites + 1))
fi
fi
# Apply skip flags
if [ "$skip_weaviate" = true ]; then
run_weaviate=false
print_status "Skipping Weaviate tests (--skip)"
fi
if [ "$skip_milvus" = true ]; then
run_milvus=false
print_status "Skipping Milvus tests (--skip)"
fi
if [ "$skip_supabase" = true ]; then
run_supabase=false
print_status "Skipping Supabase tests (--skip)"
fi
if [ "$skip_mongodb" = true ]; then
run_mongodb=false
print_status "Skipping MongoDB tests (--skip)"
fi
if [ "$skip_chroma" = true ]; then
run_chroma=false
print_status "Skipping Chroma tests (--skip)"
fi
if [ "$skip_qdrant" = true ]; then
run_qdrant=false
print_status "Skipping Qdrant tests (--skip)"
fi
if [ "$skip_neo4j" = true ]; then
run_neo4j=false
print_status "Skipping Neo4j tests (--skip)"
fi
if [ "$skip_pinecone" = true ]; then
run_pinecone=false
print_status "Skipping Pinecone tests (--skip)"
fi
if [ "$skip_mcp" = true ]; then
run_mcp=false
print_status "Skipping MCP tests (--skip)"
fi
# Run Weaviate integration tests if requested
if [ "$run_weaviate" = true ]; then
if [ -n "$WEAVIATE_URL" ] && [ -n "$WEAVIATE_API_KEY" ] && [ -n "$OPENAI_API_KEY" ]; then
print_status "Running Weaviate integration tests..."
total_suites=$((total_suites + 1))
vdb_names+=("Weaviate")
# Capture test output to count tests
output=$(go test -v -timeout=2m -count=1 ./tests/... -run="TestWeaviate(Integration|FactoryIntegration|VectorDBRegistry|ConnectionSpeed|ErrorHandling)$" 2>&1)
exit_code=$?
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "Weaviate integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
print_warning "Weaviate integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
echo "$output"
else
print_warning "Skipping Weaviate integration tests - credentials not configured"
print_status "Set WEAVIATE_URL, WEAVIATE_API_KEY, and OPENAI_API_KEY to run Weaviate tests"
vdb_names+=("Weaviate")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run Milvus integration tests if requested
if [ "$run_milvus" = true ]; then
# Check if Milvus is running locally (port 19530) or cloud credentials exist
local milvus_available=false
local milvus_host="${MILVUS_ADDRESS:-localhost}"
local milvus_port="19530"
# Parse host:port if address contains colon
if [[ "$milvus_host" == *":"* ]]; then
milvus_port="${milvus_host#*:}"
milvus_host="${milvus_host%:*}"
fi
# Check if we can connect to Milvus port (timeout 2 seconds)
if nc -z -w 2 "$milvus_host" "$milvus_port" 2>/dev/null; then
milvus_available=true
elif [ -f "./tools/vdb/local/milvus.sh" ] && ./tools/vdb/local/milvus.sh status &>/dev/null; then
milvus_available=true
fi
if [ "$milvus_available" = true ] || [ -n "$MILVUS_CLOUD_ADDRESS" ]; then
if [ "$milvus_available" = true ]; then
print_status "Running Milvus integration tests (local)..."
else
print_status "Running Milvus integration tests (cloud)..."
fi
total_suites=$((total_suites + 1))
vdb_names+=("Milvus")
# Use shorter timeout - Milvus tests should complete quickly
output=$(go test -v -timeout=3m -count=1 ./tests/... -run="TestMilvus" 2>&1)
exit_code=$?
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "Milvus integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
print_warning "Milvus integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
echo "$output"
else
print_warning "Skipping Milvus integration tests - Milvus not running"
print_status "Start Milvus with: ./tools/vdb/local/milvus.sh start"
vdb_names+=("Milvus")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run Supabase integration tests if requested
if [ "$run_supabase" = true ]; then
if [ -n "$SUPABASE_DATABASE_URL" ] && [ -n "$SUPABASE_DATABASE_KEY" ]; then
print_status "Running Supabase integration tests..."
total_suites=$((total_suites + 1))
vdb_names+=("Supabase")
output=$(go test -v -timeout=2m -count=1 ./tests/... -run="TestSupabase" 2>&1)
exit_code=$?
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "Supabase integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
print_warning "Supabase integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
echo "$output"
else
print_warning "Skipping Supabase integration tests - credentials not configured"
print_status "Set SUPABASE_DATABASE_URL and SUPABASE_DATABASE_KEY to run Supabase tests"
vdb_names+=("Supabase")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run MongoDB integration tests if requested
if [ "$run_mongodb" = true ]; then
if [ -n "$MONGODB_URI" ]; then
print_status "Running MongoDB integration tests..."
total_suites=$((total_suites + 1))
vdb_names+=("MongoDB")
output=$(go test -v -timeout=2m -count=1 ./tests/... -run="TestMongoDB" 2>&1)
exit_code=$?
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "MongoDB integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
print_warning "MongoDB integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
echo "$output"
else
print_warning "Skipping MongoDB integration tests - credentials not configured"
print_status "Set MONGODB_URI and MONGODB_DATABASE to run MongoDB tests"
vdb_names+=("MongoDB")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run Chroma integration tests if requested
if [ "$run_chroma" = true ]; then
# Check if Chroma is running locally (port 8000)
local chroma_available=false
local chroma_url="${CHROMA_URL:-http://localhost:8000}"
local chroma_host="localhost"
local chroma_port="8000"
# Parse host:port from URL
if [[ "$chroma_url" =~ ://([^:/]+):([0-9]+) ]]; then
chroma_host="${BASH_REMATCH[1]}"
chroma_port="${BASH_REMATCH[2]}"
elif [[ "$chroma_url" =~ ://([^:/]+) ]]; then
chroma_host="${BASH_REMATCH[1]}"
fi
# Check if we can connect to Chroma port
if nc -z -w 2 "$chroma_host" "$chroma_port" 2>/dev/null; then
chroma_available=true
fi
if [ "$chroma_available" = true ] || [ -n "$CHROMA_API_KEY" ]; then
if [ "$chroma_available" = true ]; then
print_status "Running Chroma integration tests (local)..."
else
print_status "Running Chroma integration tests (cloud)..."
fi
total_suites=$((total_suites + 1))
vdb_names+=("Chroma")
# Run tests with live output to avoid appearance of hanging
go test -v -timeout=2m -count=1 -tags=integration ./tests -run="TestChroma" 2>&1 | tee /tmp/chroma_test_output.txt
exit_code=${PIPESTATUS[0]}
output=$(cat /tmp/chroma_test_output.txt)
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
# Check if failures are due to quota limits
quota_failures=$(echo "$output" | grep -c "Quota exceeded" 2>/dev/null || true)
if [ $exit_code -eq 0 ]; then
print_success "Chroma integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
if [ "$quota_failures" -gt 0 ]; then
print_warning "Chroma integration tests failed"
print_status "Note: ${quota_failures} test(s) failed due to Chroma Cloud free tier quota limits (300 documents/request)"
else
print_warning "Chroma integration tests failed"
fi
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
# Output already shown via tee, clean up temp file
rm -f /tmp/chroma_test_output.txt
else
print_warning "Skipping Chroma integration tests - Chroma not running"
print_status "Start Chroma with: podman run -d -p 8000:8000 chromadb/chroma:0.6.2"
vdb_names+=("Chroma")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run Qdrant integration tests if requested
if [ "$run_qdrant" = true ]; then
# Check if Qdrant is running locally (port 6333 HTTP, 6334 gRPC)
local qdrant_available=false
local qdrant_host="localhost"
local qdrant_port="6333"
# Check if we can connect to Qdrant HTTP port
if nc -z -w 2 "$qdrant_host" "$qdrant_port" 2>/dev/null; then
qdrant_available=true
fi
if [ "$qdrant_available" = true ] || [ -n "$QDRANT_API_KEY" ]; then
if [ "$qdrant_available" = true ]; then
print_status "Running Qdrant integration tests (local)..."
else
print_status "Running Qdrant integration tests (cloud)..."
fi
total_suites=$((total_suites + 1))
vdb_names+=("Qdrant")
# Run tests with live output
go test -v -timeout=2m -count=1 -tags=integration ./tests -run="TestQdrant" 2>&1 | tee /tmp/qdrant_test_output.txt
exit_code=${PIPESTATUS[0]}
output=$(cat /tmp/qdrant_test_output.txt)
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "Qdrant integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
print_warning "Qdrant integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
# Clean up temp file
rm -f /tmp/qdrant_test_output.txt
else
print_warning "Skipping Qdrant integration tests - Qdrant not running"
print_status "Start Qdrant with: podman run -d -p 6333:6333 -p 6334:6334 qdrant/qdrant:latest"
vdb_names+=("Qdrant")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run Neo4j integration tests if requested
if [ "$run_neo4j" = true ]; then
# Check if Neo4j is running locally (port 7687 Bolt)
local neo4j_available=false
local neo4j_host="localhost"
local neo4j_port="7687"
# Check if we can connect to Neo4j Bolt port
if nc -z -w 2 "$neo4j_host" "$neo4j_port" 2>/dev/null; then
neo4j_available=true
fi
# Check for required environment variables
if [ "$neo4j_available" = true ] && [ -n "$NEO4J_PASSWORD" ]; then
print_status "Running Neo4j integration tests (local)..."
total_suites=$((total_suites + 1))
vdb_names+=("Neo4j")
# Run tests with live output
go test -v -timeout=2m -count=1 -tags=integration ./tests -run="TestNeo4j" 2>&1 | tee /tmp/neo4j_test_output.txt
exit_code=${PIPESTATUS[0]}
output=$(cat /tmp/neo4j_test_output.txt)
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "Neo4j integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
print_warning "Neo4j integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
# Clean up temp file
rm -f /tmp/neo4j_test_output.txt
else
print_warning "Skipping Neo4j integration tests - Neo4j not running or credentials not configured"
print_status "Start Neo4j with: ./tools/vdb/local/neo4j.sh start"
print_status "Set NEO4J_PASSWORD environment variable"
vdb_names+=("Neo4j")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run Pinecone integration tests if requested
if [ "$run_pinecone" = true ]; then
if [ -n "$PINECONE_API_KEY" ] && [ -n "$OPENAI_API_KEY" ]; then
print_status "Running Pinecone integration tests (cloud)..."
total_suites=$((total_suites + 1))
vdb_names+=("Pinecone")
# Run tests with live output
go test -v -timeout=5m -count=1 -tags=integration ./tests -run="TestPinecone" 2>&1 | tee /tmp/pinecone_test_output.txt
exit_code=${PIPESTATUS[0]}
output=$(cat /tmp/pinecone_test_output.txt)
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "Pinecone integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
print_warning "Pinecone integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
# Clean up temp file
rm -f /tmp/pinecone_test_output.txt
else
print_warning "Skipping Pinecone integration tests - credentials not configured"
print_status "Set PINECONE_API_KEY and OPENAI_API_KEY to run Pinecone tests"
vdb_names+=("Pinecone")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run MCP integration tests if requested
if [ "$run_mcp" = true ]; then
if [ -n "$OPENAI_API_KEY" ] && [ -n "$WEAVE_MCP_STDIO_PATH" ]; then
print_status "Running MCP integration tests..."
total_suites=$((total_suites + 1))
vdb_names+=("MCP")
output=$(go test -v -tags=integration -timeout=5m -count=1 ./tests -run="TestMCP" 2>&1)
exit_code=$?
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "MCP integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
print_warning "MCP integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
echo "$output"
else
print_warning "Skipping MCP integration tests - configuration not provided"
print_status "Set OPENAI_API_KEY and WEAVE_MCP_STDIO_PATH to run MCP tests"
vdb_names+=("MCP")
vdb_status+=("SKIP")
vdb_passed+=("0")
vdb_failed+=("0")
skipped_suites=$((skipped_suites + 1))
fi
fi
# Run CLI integration tests (--top_k_images, multi-collection, etc.)
# These tests auto-detect available VDB and work with existing collections
if [ "$run_all" = true ]; then
print_status "Running CLI integration tests..."
total_suites=$((total_suites + 1))
vdb_names+=("CLI Tests")
# Run with live output
go test -v -tags=integration -timeout=10m -count=1 ./tests/integration/... 2>&1 | tee /tmp/cli_test_output.txt
exit_code=${PIPESTATUS[0]}
output=$(cat /tmp/cli_test_output.txt)
pass_count=$(echo "$output" | grep -c "^--- PASS:" 2>/dev/null || true)
fail_count=$(echo "$output" | grep -c "^--- FAIL:" 2>/dev/null || true)
[ -z "$pass_count" ] && pass_count=0
[ -z "$fail_count" ] && fail_count=0
if [ $exit_code -eq 0 ]; then
print_success "CLI integration tests passed!"
passed_suites=$((passed_suites + 1))
vdb_status+=("PASS")
else
# Check if all tests were skipped
skip_count=$(echo "$output" | grep -c "Skipping.*No vector database" 2>/dev/null || true)
if [ "$skip_count" -gt 0 ] && [ "$fail_count" -eq 0 ]; then
print_warning "CLI integration tests skipped - no VDB credentials configured"
skipped_suites=$((skipped_suites + 1))
vdb_status+=("SKIP")
else
print_warning "CLI integration tests failed"
failed_suites=$((failed_suites + 1))
vdb_status+=("FAIL")
fi
fi
vdb_passed+=("$pass_count")
vdb_failed+=("$fail_count")
# Clean up temp file
rm -f /tmp/cli_test_output.txt
fi
# Call summary function
print_integration_summary
# Clear trap and return exit code based on results
trap - EXIT
if [ $failed_suites -gt 0 ]; then
return 1
fi
return 0
}
# Function to print integration test summary
# This is a separate function so it can be called by trap handlers
print_integration_summary() {
# Only print if we have vdb_names (i.e., tests have started running)
if [ ${#vdb_names[@]} -eq 0 ]; then
return
fi
# Print detailed summary
echo ""
echo ""
print_header "═══════════════════════════════════════════════════════════════"
print_header " INTEGRATION TEST SUMMARY "
print_header "═══════════════════════════════════════════════════════════════"
echo ""
# Print table header
printf " %-15s %-12s %-20s\n" "VDB" "STATUS" "TESTS"
echo " ─────────────────────────────────────────────"
# Print results for each VDB
for i in "${!vdb_names[@]}"; do
status="${vdb_status[$i]}"
passed="${vdb_passed[$i]}"
failed="${vdb_failed[$i]}"
case "$status" in
"PASS")
status_color="${GREEN}✓ PASS${NC}"
test_info="${GREEN}${passed} ✅${NC}"
;;
"FAIL")
status_color="${RED}✗ FAIL${NC}"
if [ "$failed" -gt 0 ]; then
test_info="${GREEN}${passed} ✅${NC} ${RED}${failed} ❌${NC}"
else
test_info="${GREEN}${passed} ✅${NC}"
fi
;;
"SKIP")
status_color="${YELLOW}○ SKIP${NC}"
test_info="${YELLOW}-${NC}"
;;
esac
printf " %-15s " "${vdb_names[$i]}"
echo -e "$status_color $test_info"
done
echo " ─────────────────────────────────────────"
echo ""
# Print totals
echo " Summary:"
echo -e " Total Suites: $total_suites"
echo -e " ${GREEN}Passed: $passed_suites${NC}"
echo -e " ${RED}Failed: $failed_suites${NC}"
echo -e " ${YELLOW}Skipped: $skipped_suites${NC}"
echo ""
if [ $failed_suites -eq 0 ] && [ $passed_suites -gt 0 ]; then
echo -e " ${GREEN}════════════════════════════════════════════════════════════${NC}"
echo -e " ${GREEN} ✓ ALL INTEGRATION TESTS PASSED! ${NC}"
echo -e " ${GREEN}════════════════════════════════════════════════════════════${NC}"
elif [ $failed_suites -gt 0 ]; then
echo -e " ${RED}════════════════════════════════════════════════════════════${NC}"
echo -e " ${RED} ✗ SOME TESTS FAILED ${NC}"
echo -e " ${RED}════════════════════════════════════════════════════════════${NC}"
print_warning "Failures may be due to network issues, cloud configuration, quota limits, or test flakiness"
else
echo -e " ${YELLOW}════════════════════════════════════════════════════════════${NC}"
echo -e " ${YELLOW} ○ ALL TESTS SKIPPED - Check configuration ${NC}"
echo -e " ${YELLOW}════════════════════════════════════════════════════════════${NC}"
fi
echo ""
}
# Function to run fast tests
run_fast_tests() {
print_header "Running Fast Tests..."
# Check if Go is installed
if ! command -v go >/dev/null 2>&1; then
print_error "Go is not installed. Please install Go 1.21 or later."
exit 1
fi
# Run unit tests
print_status "Running unit tests..."
if go test -v -timeout=30s ./tests/... ./src/pkg/vectordb/mongodb/... -run="TestConfig|TestMock|TestWeaviateClient|TestFactory|TestDocumentConversion|TestGetTimeout|TestGetDefaultSchema|TestValidateSchema|TestMongoDBFactory|TestMongoDBClient"; then
print_success "Unit tests passed!"
else
print_error "Unit tests failed!"
exit 1
fi
# Run fast integration tests (mock only)
print_status "Running fast integration tests (mock)..."
if go test -v -timeout=10s ./tests/... -run="TestMock"; then
print_success "Fast integration tests passed!"
else
print_warning "Fast integration tests failed"
fi
print_success "Fast tests completed!"
}
# Function to run coverage tests
run_coverage_tests() {
print_header "Running Coverage Analysis..."
# Check if Go is installed
if ! command -v go >/dev/null 2>&1; then
print_error "Go is not installed. Please install Go 1.21 or later."
exit 1
fi
# Create coverage directory
mkdir -p coverage
# Run tests with coverage (only unit tests and mock integration tests)
print_status "Running tests with coverage..."
if go test -coverprofile=coverage/coverage.out -covermode=atomic ./tests/... -run="TestConfig|TestMock|TestCLI|TestFastMock|TestFastConfig"; then
print_status "Generating coverage report..."
# Generate HTML coverage report
go tool cover -html=coverage/coverage.out -o coverage/coverage.html
# Generate text coverage report
go tool cover -func=coverage/coverage.out > coverage/coverage.txt
print_success "Coverage analysis completed!"
print_status "Coverage files available in:"
echo " - coverage/coverage.html (HTML report)"
echo " - coverage/coverage.txt (Text report)"
echo " - coverage/coverage.out (Raw coverage data)"
else
print_error "Coverage analysis failed!"
exit 1
fi
}
# Function to create basic integration tests (currently unused)
# create_integration_tests() {
# print_status "Creating basic integration test structure..."
#
# # Create tests directory structure