Add gitlab ci support
[oweals/peertube.git] / scripts / clean / server / test.sh
1 #!/bin/sh
2
3 set -eu
4
5 recreateDB () {
6   dbname="peertube_test$1"
7
8   dropdb --if-exists "$dbname" 2>&1
9
10   createdb -O peertube "$dbname"
11   psql -c "CREATE EXTENSION pg_trgm;" "$dbname" &
12   psql -c "CREATE EXTENSION unaccent;" "$dbname" &
13 }
14
15 removeFiles () {
16   rm -rf "./test$1" "./config/local-test.json" "./config/local-test-$1.json" ~/.config/PeerTube/CLI-$1
17 }
18
19 dropRedis () {
20   port=$((9000+$1))
21   host="localhost"
22
23   if [ ! -z ${GITLAB_CI+x} ]; then
24     host="redis"
25   fi
26
27   redis-cli -h "$host" KEYS "bull-localhost:$port*" | grep -v empty | xargs --no-run-if-empty redis-cli -h "$host" DEL
28   redis-cli -h "$host" KEYS "redis-localhost:$port*" | grep -v empty | xargs --no-run-if-empty redis-cli -h "$host" DEL
29   redis-cli -h "$host" KEYS "*redis-localhost:$port-" | grep -v empty | xargs --no-run-if-empty redis-cli -h "$host" DEL
30 }
31
32 seq=$(seq 1 6)
33
34 if [ ! -z ${1+x} ]; then
35   seq=$1
36 fi
37
38
39 for i in $seq; do
40   recreateDB "$i" &
41   dropRedis "$i" &
42   removeFiles "$i" &
43 done
44
45 wait