-
Notifications
You must be signed in to change notification settings - Fork 60
/
unit_test.sh
executable file
·62 lines (49 loc) · 1.52 KB
/
unit_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
#!/bin/bash
set -ex
export CONTAINER_NAME="rbac-pr-check"
export IMAGE_TAG="rbac:pr-check"
# spin up the db for integration tests
DB_CONTAINER="rbac-$(uuidgen)"
echo "Spinning up container: ${DB_CONTAINER}"
docker run -d \
--name $DB_CONTAINER \
-p 5432 \
-e POSTGRESQL_USER=root \
-e POSTGRESQL_PASSWORD=root \
-e POSTGRESQL_DATABASE=rbac \
quay.io/cloudservices/postgresql-rds:14
PORT=$(docker inspect $DB_CONTAINER | grep HostPort | sort | uniq | grep -o [0-9]*)
echo "DB Listening on Port: ${PORT}"
export DATABASE_HOST=localhost
export DATABASE_PORT=$PORT
export DATABASE_USER=root
export DATABASE_PASSWORD=root
export DATABASE_NAME=rbac
echo "Running tests...here we go"
# Build PR_CHECK Image
docker build -f './Dockerfile-pr-check' --label $CONTAINER_NAME --tag $IMAGE_TAG .
# Build PR_Check Container
docker run -i --rm --name $CONTAINER_NAME \
-e DATABASE_NAME=$DATABASE_NAME \
-e DATABASE_HOST=$DATABASE_HOST \
-e DATABASE_PORT=$DATABASE_PORT \
-e DATABASE_USER=$DATABASE_USER \
-e DATABASE_PASSWORD=$DATABASE_PASSWORD \
--net=host \
$IMAGE_TAG tox
OUT_CODE=$?
echo "Killing DB Container..."
docker kill $DB_CONTAINER
echo "Removing DB Container..."
docker rm -f $DB_CONTAINER
if [[ $OUT_CODE != 0 ]]; then
exit 1
fi
# Pass Jenkins dummy artifacts as it needs
# an xml output to consider the job a success.
mkdir -p $WORKSPACE/artifacts
cat << EOF > $WORKSPACE/artifacts/junit-dummy.xml
<testsuite tests="1">
<testcase classname="dummy" name="dummytest"/>
</testsuite>
EOF