forked from bianster/mysqlfs
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·148 lines (118 loc) · 3.56 KB
/
Copy pathrun-tests.sh
File metadata and controls
executable file
·148 lines (118 loc) · 3.56 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TESTS_DIR="$SCRIPT_DIR/tests"
MYSQLFS_TEST_DB_HOST="${MYSQLFS_TEST_DB_HOST:-localhost}"
MYSQLFS_TEST_DB_NAME="${MYSQLFS_TEST_DB_NAME:-mysqlfs_test}"
MYSQLFS_TEST_DB_USER="${MYSQLFS_TEST_DB_USER:-mysqlfs_test}"
MYSQLFS_TEST_DB_PASS="${MYSQLFS_TEST_DB_PASS:-mysqlfs_test}"
MYSQLFS_TEST_SOCKET="${MYSQLFS_TEST_SOCKET:-}"
MYSQLFS_TEST_ADMIN_USER="${MYSQLFS_TEST_ADMIN_USER:-$MYSQLFS_TEST_DB_USER}"
MYSQLFS_TEST_ADMIN_PASS="${MYSQLFS_TEST_ADMIN_PASS:-$MYSQLFS_TEST_DB_PASS}"
default_build_dir() {
case "$(uname -s)" in
Darwin)
printf '%s\n' "build-macos"
;;
*)
printf '%s\n' "build"
;;
esac
}
find_mysqlfs_test_binary() {
local candidate
local build_dir
if [ -n "${MYSQLFS_TEST_BIN:-}" ]; then
printf '%s\n' "$MYSQLFS_TEST_BIN"
return 0
fi
build_dir="${MYSQLFS_BUILD_DIR:-$(default_build_dir)}"
for candidate in \
"$SCRIPT_DIR/$build_dir/src/mysqlfs" \
"$SCRIPT_DIR/build-macos/src/mysqlfs" \
"$SCRIPT_DIR/build/src/mysqlfs"
do
if [ -x "$candidate" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
find_mysql_socket() {
local candidate
if [ -n "$MYSQLFS_TEST_SOCKET" ]; then
printf '%s\n' "$MYSQLFS_TEST_SOCKET"
return 0
fi
for candidate in \
/tmp/mysql.sock \
/private/tmp/mysql.sock \
/opt/homebrew/var/mysql/mysql.sock \
/var/run/mysql/mysql.sock
do
if [ -S "$candidate" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
init_mysql_admin_args() {
mysql_admin_args=(
-u "$MYSQLFS_TEST_ADMIN_USER"
)
if [ -n "$MYSQLFS_TEST_ADMIN_PASS" ]; then
mysql_admin_args+=("--password=$MYSQLFS_TEST_ADMIN_PASS")
fi
if MYSQLFS_TEST_SOCKET="$(find_mysql_socket)"; then
mysql_admin_args+=("--socket=$MYSQLFS_TEST_SOCKET")
else
mysql_admin_args+=("-h" "$MYSQLFS_TEST_DB_HOST")
fi
}
bootstrap_database() {
echo "Resetting test database $MYSQLFS_TEST_DB_NAME"
mysql "${mysql_admin_args[@]}" <<SQL
DROP DATABASE IF EXISTS \`$MYSQLFS_TEST_DB_NAME\`;
CREATE DATABASE \`$MYSQLFS_TEST_DB_NAME\`;
SQL
echo "Initializing schema with mysqlfs_setup"
DBHost="$MYSQLFS_TEST_DB_HOST" \
DBName="$MYSQLFS_TEST_DB_NAME" \
DBUser="$MYSQLFS_TEST_DB_USER" \
DBPass="$MYSQLFS_TEST_DB_PASS" \
DBSocket="$MYSQLFS_TEST_SOCKET" \
MYSQLFS_SETUP_ASSUME_YES=1 \
"$SCRIPT_DIR/mysqlfs_setup"
echo "Test database is ready."
}
run_test() {
local test_script="$1"
echo
echo "==> Running $(basename "$test_script")"
MYSQLFS_TEST_DB_HOST="$MYSQLFS_TEST_DB_HOST" \
MYSQLFS_TEST_DB_NAME="$MYSQLFS_TEST_DB_NAME" \
MYSQLFS_TEST_DB_USER="$MYSQLFS_TEST_DB_USER" \
MYSQLFS_TEST_DB_PASS="$MYSQLFS_TEST_DB_PASS" \
MYSQLFS_TEST_SOCKET="$MYSQLFS_TEST_SOCKET" \
MYSQLFS_TEST_BIN="$MYSQLFS_TEST_BIN" \
"$test_script"
}
main() {
local test_script
if ! MYSQLFS_TEST_BIN="$(find_mysqlfs_test_binary)"; then
echo "error: mysqlfs test binary not found in the configured build directory" >&2
exit 1
fi
if [ ! -x "$MYSQLFS_TEST_BIN" ]; then
echo "error: mysqlfs test binary not found at $MYSQLFS_TEST_BIN" >&2
exit 1
fi
init_mysql_admin_args
bootstrap_database
for test_script in "$TESTS_DIR"/[0-9][0-9][0-9]-*.sh; do
run_test "$test_script"
done
}
main "$@"