-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·107 lines (90 loc) · 3.53 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·107 lines (90 loc) · 3.53 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
#!/usr/bin/env bash
CONTAINER_NAME=borm_test
USER=test
PASSWORD=test
# Function to clean up the container
cleanup() {
echo "Stopping and removing container..."
docker stop ${CONTAINER_NAME} >/dev/null 2>&1
docker rm ${CONTAINER_NAME} >/dev/null 2>&1
exit $((TEST_FAILED ? 1 : 0))
}
# Set up trap to call cleanup function on script exit
trap cleanup EXIT INT TERM
# Function to parse command line argumentsppa
parse_args() {
VITEST_ARGS=()
for arg in "$@"
do
case $arg in
-link=*)
# We'll ignore this parameter now
;;
*)
VITEST_ARGS+=("$arg")
;;
esac
done
}
# Parse the command line arguments
parse_args "$@"
# Check if BORM_TEST_SURREALDB_LINK_MODE is set and valid
if [ -z "$BORM_TEST_SURREALDB_LINK_MODE" ]; then
echo "Error: BORM_TEST_SURREALDB_LINK_MODE environment variable is not set"
exit 1
elif [ "$BORM_TEST_SURREALDB_LINK_MODE" != "edges" ] && [ "$BORM_TEST_SURREALDB_LINK_MODE" != "refs" ]; then
echo "Error: BORM_TEST_SURREALDB_LINK_MODE must be either 'edges' or 'refs'"
exit 1
fi
# Set LINK based on BORM_TEST_SURREALDB_LINK_MODE
if [ "$BORM_TEST_SURREALDB_LINK_MODE" == "edges" ]; then
LINK="edges"
else
LINK="refs"
fi
# Set variables based on LINK
SCHEMA_FILE="./tests/adapters/surrealDB/mocks/${LINK}Schema.surql"
DATA_FILE="./tests/adapters/surrealDB/mocks/${LINK}Data.surql"
NAMESPACE="test_${LINK}"
# Start the container
docker run --detach --rm --pull always -v $(pwd)/tests:/tests -p 8000:8000 --name $CONTAINER_NAME surrealdb/surrealdb:v2.3.7 start --strict --allow-all -u $USER -p $PASSWORD --bind 0.0.0.0:8000
until [ "`docker inspect -f {{.State.Running}} $CONTAINER_NAME`"=="true" ]; do
sleep 0.1;
done;
# Setup surrealdb database for the surrealdb test
# Create the namespace, database, and user dynamically
docker exec -i $CONTAINER_NAME ./surreal sql -u $USER -p $PASSWORD <<EOF
DEFINE NAMESPACE $NAMESPACE;
USE NS $NAMESPACE;
DEFINE DATABASE test;
DEFINE USER $USER ON NAMESPACE PASSWORD '$PASSWORD' ROLES OWNER;
EOF
# Create the schema
docker exec -i $CONTAINER_NAME ./surreal import -u $USER -p $PASSWORD --namespace $NAMESPACE --database test --endpoint http://localhost:8000 $SCHEMA_FILE
# Insert data
docker exec -i $CONTAINER_NAME ./surreal import -u $USER -p $PASSWORD --namespace $NAMESPACE --database test --endpoint http://localhost:8000 $DATA_FILE
# Setup surrealdb database for the multidb test
# Create the namespace, database, and user
docker exec -i $CONTAINER_NAME ./surreal sql -u $USER -p $PASSWORD <<EOF
DEFINE NAMESPACE multi_db_test;
USE NS multi_db_test;
DEFINE DATABASE test;
DEFINE USER $USER ON NAMESPACE PASSWORD '$PASSWORD' ROLES OWNER;
EOF
# Create the schema
docker exec -i $CONTAINER_NAME ./surreal import -u $USER -p $PASSWORD --namespace multi_db_test --database test --endpoint http://localhost:8000 ./tests/multidb/mocks/schema.surql
# Insert data
docker exec -i $CONTAINER_NAME ./surreal import -u $USER -p $PASSWORD --namespace multi_db_test --database test --endpoint http://localhost:8000 ./tests/multidb/mocks/data.surql
# Run tests and capture output
if CONTAINER_NAME=${CONTAINER_NAME} npx vitest run "${VITEST_ARGS[@]}"; then
echo "Tests passed. Container ${CONTAINER_NAME} is still running."
TEST_FAILED=false
else
echo "Tests failed. Container ${CONTAINER_NAME} is still running."
TEST_FAILED=true
fi
echo "Press Ctrl+C to stop the script and remove the container."
# Keep the script running, which keeps the container alive
while true; do
sleep 1
done