-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·128 lines (110 loc) · 3.07 KB
/
test.sh
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
#!/bin/bash
backend=false
frontend=false
build=false
keep=false
while getopts ":bfck" opt; do
case ${opt} in
b )
backend=true
;;
f )
frontend=true
;;
c )
build=true
;;
k )
keep=true
;;
\? )
echo "Usage: $0 [-b] [-f] [-c]"
exit 1
;;
esac
done
echo "Checking environment file..."
if [ "$build" = true ]; then
rm .env > /dev/null 2>&1
fi
if ! [ -f .env ]; then
cp .dev.env .env
sed -i "s/^DJANGO_SECRET_KEY=.*/DJANGO_SECRET_KEY=totally_random_key_string/" .env
echo "Created environment file"
fi
echo "Checking for existing SSL certificates..."
if [ ! -f "data/nginx/ssl/private.key" ] || [ ! -f "data/nginx/ssl/certificate.crt" ]; then
echo "Generating SSL certificates..."
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout data/nginx/ssl/private.key \
-out data/nginx/ssl/certificate.crt \
-subj "/C=BE/ST=/L=/O=/OU=/CN=" > /dev/null
echo "SSL certificates generated."
else
echo "SSL certificates already exist, skipping generation."
fi
if [ "$build" = true ]; then
echo "Building Docker images..."
echo "This can take a while..."
docker-compose -f test.yml build --no-cache
fi
echo "Starting services..."
docker-compose -f test.yml up -d --scale cypress=0
cypress_exit=0
vitest_exit=0
django_exit=0
echo "Filling up database with test data"
docker exec backend sh -c "python manage.py flush --no-input; python manage.py migrate;
python manage.py loaddata authentication/fixtures/realistic/*;
python manage.py loaddata notifications/fixtures/realistic/*;
python manage.py loaddata api/fixtures/realistic/*;"
if [ "$frontend" = true ]; then
echo "Running frontend tests..."
echo "Running Cypress tests..."
docker-compose -f test.yml up --exit-code-from cypress --abort-on-container-exit cypress
cypress_exit=$?
echo "Running Vitest tests..."
docker exec frontend npm run test
vitest_exit=$?
elif [ "$backend" = true ]; then
echo "Running backend tests..."
docker exec backend python manage.py test
django_exit=$?
else
echo "Running backend tests..."
docker exec backend python manage.py test
django_exit=$?
echo "Running frontend_test tests..."
echo "Running Cypress tests..."
docker-compose -f test.yml up --exit-code-from cypress --abort-on-container-exit cypress
cypress_exit=$?
echo "Running Vitest tests..."
docker exec frontend npm run test
vitest_exit=$?
fi
exit_code=0
echo "-----------------"
if [ $cypress_exit -ne 0 ] || [ $vitest_exit -ne 0 ] || [ $django_exit -ne 0 ]; then
echo "Tests failed:"
if [ $cypress_exit -ne 0 ]; then
echo " - Cypress"
fi
if [ $vitest_exit -ne 0 ]; then
echo " - Vitest"
fi
if [ $django_exit -ne 0 ]; then
echo " - Django"
fi
exit_code=1
else
echo "All tests passed!"
fi
echo "-----------------"
echo "Cleaning up..."
if [ "$keep" = false ]; then
docker-compose -f test.yml down --rmi all
else
docker-compose -f test.yml down
fi
echo "Done."
exit $exit_code