This repository was archived by the owner on Jan 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathrun_e2e_migration_tests.sh
More file actions
executable file
·143 lines (124 loc) · 4.29 KB
/
run_e2e_migration_tests.sh
File metadata and controls
executable file
·143 lines (124 loc) · 4.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
#!/bin/bash -e
# Container names and images (set via command line arguments)
MAGE_CONTAINER=""
MYSQL_CONTAINER=""
POSTGRESQL_CONTAINER=""
# Parse command line arguments
TEST_FILTER=""
while [[ $# -gt 0 ]]; do
case $1 in
-k)
TEST_FILTER="$2"
shift 2
;;
--mage-container)
MAGE_CONTAINER="$2"
shift 2
;;
--mysql-container)
MYSQL_CONTAINER="$2"
shift 2
;;
--postgresql-container)
POSTGRESQL_CONTAINER="$2"
shift 2
;;
--help)
echo "Usage: $0 [-k FILTER] --mage-container CONTAINER [--mysql-container CONTAINER] [--postgresql-container CONTAINER] [--mysql-image IMAGE] [--postgresql-image IMAGE]"
echo " -k FILTER Filter tests by database type (e.g., 'mysql', 'postgresql')"
echo " --mage-container NAME MAGE container name (required)"
echo " --mysql-container NAME MySQL container name (required if mysql tests are run)"
echo " --postgresql-container NAME PostgreSQL container name (required if postgresql tests are run)"
exit 0
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
done
# Validate required arguments based on test filter
if [ -z "$MAGE_CONTAINER" ]; then
echo "Error: MAGE container name is required"
echo "Usage: $0 --mage-container CONTAINER [other options]"
exit 1
fi
# Check if MySQL tests will be run
if [ -z "$TEST_FILTER" ] || [ "$TEST_FILTER" = "mysql" ]; then
if [ -z "$MYSQL_CONTAINER" ]; then
echo "Error: MySQL container name and image are required for MySQL tests"
echo "Usage: $0 --mage-container CONTAINER --mysql-container CONTAINER [other options]"
exit 1
fi
fi
# Check if PostgreSQL tests will be run
if [ -z "$TEST_FILTER" ] || [ "$TEST_FILTER" = "postgresql" ]; then
if [ -z "$POSTGRESQL_CONTAINER" ]; then
echo "Error: PostgreSQL container name and image are required for PostgreSQL tests"
echo "Usage: $0 --mage-container CONTAINER --postgresql-container CONTAINER [other options]"
exit 1
fi
fi
wait_for_service() {
local host=$1
local port=$2
local service_name=$3
local timeout=30
echo "Waiting for $service_name to start..."
counter=0
while [ $counter -lt $timeout ]; do
if nc -z "$host" "$port" 2>/dev/null; then
echo "$service_name is up and running."
return 0
fi
sleep 1
counter=$((counter+1))
done
echo "$service_name failed to start in $timeout seconds"
return 1
}
run_mysql_tests() {
echo "Starting MySQL..."
# Start MySQL using docker compose with inline environment variables
cd e2e_migration/test_mysql
MYSQL_CONTAINER="$MYSQL_CONTAINER" docker compose up -d
sleep 30
if ! wait_for_service "localhost" 3306 "MySQL"; then
MYSQL_CONTAINER="$MYSQL_CONTAINER" docker compose down -v 2>/dev/null || true
cd ../..
return 1
fi
echo "Running MySQL migration tests..."
cd ../..
python3 -m pytest e2e_migration/test_migration.py -v -k mysql
echo "Stopping MySQL..."
cd e2e_migration/test_mysql
MYSQL_CONTAINER="$MYSQL_CONTAINER" docker compose down -v
cd ../..
}
run_postgresql_tests() {
echo "Starting PostgreSQL..."
# Start PostgreSQL using docker compose with inline environment variables
cd e2e_migration/test_postgresql
POSTGRESQL_CONTAINER="$POSTGRESQL_CONTAINER" docker compose up -d
sleep 30
if ! wait_for_service "localhost" 5432 "PostgreSQL"; then
POSTGRESQL_CONTAINER="$POSTGRESQL_CONTAINER" docker compose down -v 2>/dev/null || true
cd ../..
return 1
fi
echo "Running PostgreSQL migration tests..."
cd ../..
python3 -m pytest e2e_migration/test_migration.py -v -k postgresql
echo "Stopping PostgreSQL..."
cd e2e_migration/test_postgresql
POSTGRESQL_CONTAINER="$POSTGRESQL_CONTAINER" docker compose down -v
cd ../..
}
# Main execution
if [ -z "$TEST_FILTER" ] || [ "$TEST_FILTER" = "mysql" ]; then
run_mysql_tests
fi
if [ -z "$TEST_FILTER" ] || [ "$TEST_FILTER" = "postgresql" ]; then
run_postgresql_tests
fi