1
+ #! /bin/bash
2
+
3
+ # Color output
4
+ RED=' \033[0;31m'
5
+ GREEN=' \033[0;32m'
6
+ YELLOW=' \033[1;33m'
7
+ NC=' \033[0m' # No Color
8
+
9
+ # Get script directory
10
+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
11
+ SCHEMA_PATH=" $SCRIPT_DIR /../../schema.sql"
12
+
13
+ echo -e " ${YELLOW} Starting PostgreSQL test environment...${NC} "
14
+
15
+ # Determine Docker Compose command
16
+ if [[ " $OSTYPE " == " darwin" * ]]; then
17
+ DOCKER_COMPOSE_CMD=" docker compose"
18
+ else
19
+ DOCKER_COMPOSE_CMD=" docker-compose"
20
+ fi
21
+
22
+ # Stop any existing containers
23
+ echo -e " ${YELLOW} Cleaning up existing containers...${NC} "
24
+ $DOCKER_COMPOSE_CMD -f docker-compose.test.yml down
25
+
26
+ # Start fresh container
27
+ echo -e " ${YELLOW} Starting PostgreSQL container...${NC} "
28
+ $DOCKER_COMPOSE_CMD -f docker-compose.test.yml up -d
29
+
30
+ # Function to check if PostgreSQL is ready
31
+ check_postgres () {
32
+ $DOCKER_COMPOSE_CMD -f docker-compose.test.yml exec -T postgres-test pg_isready -U postgres
33
+ }
34
+
35
+ # Wait for PostgreSQL to be ready
36
+ echo -e " ${YELLOW} Waiting for PostgreSQL to be ready...${NC} "
37
+ RETRIES=30
38
+ until check_postgres || [ $RETRIES -eq 0 ]; do
39
+ echo -e " ${YELLOW} Waiting for PostgreSQL to be ready... ($RETRIES attempts left)${NC} "
40
+ RETRIES=$(( RETRIES- 1 ))
41
+ sleep 1
42
+ done
43
+
44
+ if [ $RETRIES -eq 0 ]; then
45
+ echo -e " ${RED} Failed to connect to PostgreSQL${NC} "
46
+ $DOCKER_COMPOSE_CMD -f docker-compose.test.yml logs
47
+ exit 1
48
+ fi
49
+
50
+ echo -e " ${GREEN} PostgreSQL is ready!${NC} "
51
+
52
+ # Load schema
53
+ echo -e " ${YELLOW} Loading database schema...${NC} "
54
+ if [ ! -f " $SCHEMA_PATH " ]; then
55
+ echo -e " ${RED} Schema file not found at: $SCHEMA_PATH ${NC} "
56
+ exit 1
57
+ fi
58
+
59
+ $DOCKER_COMPOSE_CMD -f docker-compose.test.yml exec -T postgres-test psql -U postgres -d eliza_test -f - < " $SCHEMA_PATH "
60
+ if [ $? -ne 0 ]; then
61
+ echo -e " ${RED} Failed to load schema${NC} "
62
+ exit 1
63
+ fi
64
+ echo -e " ${GREEN} Schema loaded successfully!${NC} "
65
+
66
+ # Run the tests
67
+ echo -e " ${YELLOW} Running tests...${NC} "
68
+ pnpm vitest vector-extension.test.ts
69
+
70
+ # Capture test exit code
71
+ TEST_EXIT_CODE=$?
72
+
73
+ # Clean up
74
+ echo -e " ${YELLOW} Cleaning up test environment...${NC} "
75
+ $DOCKER_COMPOSE_CMD -f docker-compose.test.yml down
76
+
77
+ # Exit with test exit code
78
+ if [ $TEST_EXIT_CODE -eq 0 ]; then
79
+ echo -e " ${GREEN} Tests completed successfully!${NC} "
80
+ else
81
+ echo -e " ${RED} Tests failed!${NC} "
82
+ fi
83
+
84
+ exit $TEST_EXIT_CODE
0 commit comments