Skip to content

Commit dde92e2

Browse files
committed
Refactor database test scripts
Consolidate common code Handle differences with openldap on debian and oracle-linux
1 parent 68125ce commit dde92e2

20 files changed

+728
-397
lines changed

.github/workflows/boot-integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ jobs:
2020
options: --privileged --tty --interactive --shm-size=1G
2121
steps:
2222
- name: Set env
23-
run: echo "DB=$(echo ${{ matrix.database }} | sed 's/[-0-9]//g')" >> $GITHUB_ENV
23+
run: echo "PROFILE=$(echo ${{ matrix.database }} | sed 's/-[0-9.]*//g')" >> $GITHUB_ENV
2424
- name: Check out repository code
2525
uses: actions/checkout@v5
2626
- name: Integration tests on container
2727
id: testrun
28-
run: /root/uaa/scripts/integration-tests.sh $DB,default boot
28+
run: /root/uaa/scripts/integration_tests.sh ${PROFILE},default boot
2929
continue-on-error: true
3030
- name: Test result upload
3131
uses: actions/upload-artifact@v4

.github/workflows/integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ jobs:
2020
options: --privileged --tty --interactive --shm-size=1G
2121
steps:
2222
- name: Set env
23-
run: echo "DB=$(echo ${{ matrix.database }} | sed 's/[-0-9]//g')" >> $GITHUB_ENV
23+
run: echo "PROFILE=$(echo ${{ matrix.database }} | sed 's/-[0-9.]*//g')" >> $GITHUB_ENV
2424
- name: Check out repository code
2525
uses: actions/checkout@v5
2626
- name: Integration tests on container
2727
id: testrun
28-
run: /root/uaa/scripts/integration-tests.sh $DB,default
28+
run: /root/uaa/scripts/integration_tests.sh ${PROFILE},default boot
2929
continue-on-error: true
3030
- name: Test result upload
3131
uses: actions/upload-artifact@v4

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ jobs:
2020
options: --privileged --tty --interactive --shm-size=1G
2121
steps:
2222
- name: Set env
23-
run: echo "DB=$(echo ${{ matrix.database }} | sed 's/[-0-9]//g')" >> $GITHUB_ENV
23+
run: echo "PROFILE=$(echo ${{ matrix.database }} | sed 's/-[0-9.]*//g')" >> $GITHUB_ENV
2424
- name: Check out repository code
2525
uses: actions/checkout@v5
2626
- name: JUnit tests on container
2727
id: testrun
28-
run: /root/uaa/scripts/unit-tests.sh $DB,default
28+
run: /root/uaa/scripts/unit_tests.sh ${PROFILE},default
2929
continue-on-error: true
3030
- name: Test result upload
3131
uses: actions/upload-artifact@v4

run-integration-tests.sh

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,37 @@
11
#!/bin/bash
2-
3-
set -xeu -o pipefail
4-
DB="${1:-hsqldb}"
5-
BOOT="${2:-false}"
6-
7-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8-
9-
CONTAINER_SCRIPT_DIR='/root/uaa'
10-
GRADLE_LOCK_DIR='/root/uaa/.gradle/'
11-
12-
case "${DB}" in
13-
hsqldb)
14-
DB_IMAGE_NAME=postgresql # we don't have a container image for hsqldb, and can use any image
15-
PROFILE_NAME="$DB"
16-
;;
17-
18-
percona)
19-
DB_IMAGE_NAME="$DB"
20-
PROFILE_NAME=mysql
21-
;;
22-
23-
postgresql|postgresql-17|postgresql-16|postgresql-15)
24-
DB_IMAGE_NAME="$DB"
25-
PROFILE_NAME=postgresql
26-
;;
27-
28-
mysql|mysql-8)
29-
DB_IMAGE_NAME=mysql-8
30-
PROFILE_NAME=mysql
31-
;;
32-
33-
mysql-5)
34-
DB_IMAGE_NAME=mysql
35-
PROFILE_NAME=mysql
36-
;;
37-
38-
*)
39-
echo "ERROR: '$DB' is not a known database type. Supported types are: hsqldb, percona, postgresql, mysql"
40-
exit 1
41-
esac
42-
43-
if [[ -z "${DOCKER_IMAGE+x}" ]]; then
44-
DOCKER_IMAGE="cfidentity/uaa-${DB_IMAGE_NAME}"
45-
fi
46-
echo "Using docker image: ${DOCKER_IMAGE}"
47-
docker pull ${DOCKER_IMAGE}
48-
docker run --privileged -t -i --shm-size=1G \
49-
-v "${SCRIPT_DIR}":"${CONTAINER_SCRIPT_DIR}" \
50-
-v "${GRADLE_LOCK_DIR}" \
51-
--env DB="${DB}" \
52-
--env RUN_TESTS="${RUN_TESTS:-true}" \
53-
--publish 8081:8080 \
54-
"${DOCKER_IMAGE}" \
55-
/root/uaa/scripts/integration-tests.sh "${PROFILE_NAME}" "${CONTAINER_SCRIPT_DIR}" ${BOOT}
2+
set -eu -o pipefail
3+
4+
#######################################
5+
# main function to run the integration tests
6+
#######################################
7+
main() {
8+
local script_dir; script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9+
source "${script_dir}/scripts/lib_timer.sh"
10+
start_timer
11+
12+
local container_script_dir="/root/uaa"
13+
local gradle_lock_dir="/root/uaa/.gradle/"
14+
local run_as_boot="${2:-false}"
15+
source "${script_dir}/scripts/lib_database_variants.sh"
16+
parse_db_name "${1:-}"
17+
18+
echo "Using docker image: ${DOCKER_IMAGE}, DB=${DB}, PROFILE_NAME=${PROFILE_NAME}"
19+
echo
20+
21+
docker pull "${DOCKER_IMAGE}"
22+
docker run \
23+
--privileged \
24+
--tty \
25+
--interactive \
26+
--platform linux/amd64 \
27+
--shm-size=1G \
28+
--volume "${script_dir}":"${container_script_dir}" \
29+
--volume "${gradle_lock_dir}" \
30+
--env DB="${DB}" \
31+
--env RUN_TESTS="${RUN_TESTS:-true}" \
32+
--publish 8081:8080 \
33+
"${DOCKER_IMAGE}" \
34+
/root/uaa/scripts/integration_tests.sh "${PROFILE_NAME}" "${run_as_boot}"
35+
}
36+
37+
main "$@"

run-unit-tests.sh

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,34 @@
11
#!/bin/bash
2-
3-
set -xeu
4-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5-
6-
CONTAINER_SCRIPT_DIR='/root/uaa'
7-
GRADLE_LOCK_DIR='/root/uaa/.gradle/'
8-
9-
DB="${1:-hsqldb}"
10-
11-
case "${DB}" in
12-
hsqldb)
13-
DB_IMAGE_NAME=postgresql # we don't have a container image for hsqldb, and can use any image
14-
DB=hsqldb
15-
PROFILE_NAME=hsqldb
16-
;;
17-
18-
percona)
19-
DB_IMAGE_NAME=percona
20-
DB=percona
21-
PROFILE_NAME=mysql
22-
;;
23-
24-
postgresql|postgresql-17|postgresql-16|postgresql-15)
25-
DB_IMAGE_NAME=$1
26-
DB=postgresql
27-
PROFILE_NAME=postgresql
28-
;;
29-
30-
mysql|mysql-8)
31-
DB_IMAGE_NAME=mysql-8
32-
DB=mysql
33-
PROFILE_NAME=mysql
34-
;;
35-
36-
mysql-5)
37-
DB_IMAGE_NAME=mysql
38-
DB=mysql
39-
PROFILE_NAME=mysql
40-
;;
41-
42-
*)
43-
echo $"ERROR: $1 is not a known database type. Supported types are: hsqldb, percona, postgresql, mysql"
44-
exit 1
45-
esac
46-
47-
if [[ -z "${DOCKER_IMAGE+x}" ]]; then
48-
DOCKER_IMAGE="cfidentity/uaa-${DB_IMAGE_NAME}"
49-
fi
50-
51-
docker run \
52-
--privileged \
53-
--tty \
54-
--interactive \
55-
--shm-size=1G \
56-
--volume "${SCRIPT_DIR}":"${CONTAINER_SCRIPT_DIR}" \
57-
--volume "${GRADLE_LOCK_DIR}" \
58-
--env DB="${DB}" \
59-
"${DOCKER_IMAGE}" \
60-
/root/uaa/scripts/unit-tests.sh "${PROFILE_NAME}" "${CONTAINER_SCRIPT_DIR}"
2+
set -eu -o pipefail
3+
4+
#######################################
5+
# main function to run the unit tests
6+
#######################################
7+
main() {
8+
local script_dir; script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9+
source "${script_dir}/scripts/lib_timer.sh"
10+
start_timer
11+
12+
local container_script_dir="/root/uaa"
13+
local gradle_lock_dir="/root/uaa/.gradle/"
14+
source "${script_dir}/scripts/lib_database_variants.sh"
15+
parse_db_name "${1:-}"
16+
17+
echo "Using docker image: ${DOCKER_IMAGE}, DB=${DB}, PROFILE_NAME=${PROFILE_NAME}"
18+
echo
19+
20+
docker pull "${DOCKER_IMAGE}"
21+
docker run \
22+
--privileged \
23+
--tty \
24+
--interactive \
25+
--platform linux/amd64 \
26+
--shm-size=1G \
27+
--volume "${script_dir}":"${container_script_dir}" \
28+
--volume "${gradle_lock_dir}" \
29+
--env DB="${DB}" \
30+
"${DOCKER_IMAGE}" \
31+
/root/uaa/scripts/unit_tests.sh "${PROFILE_NAME}"
32+
}
33+
34+
main "$@"

scripts/integration-tests

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/integration-tests.sh

Lines changed: 0 additions & 109 deletions
This file was deleted.

scripts/integration_tests

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
UAA_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
5+
6+
if [ "$#" -eq 0 ]; then
7+
"${UAA_DIR}/scripts/gradle" integrationTest
8+
else
9+
"${UAA_DIR}/scripts/gradle" integrationTest "${@}"
10+
fi

0 commit comments

Comments
 (0)