Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislavploaia committed Apr 15, 2024
2 parents 01a4a5f + de10667 commit 9e7b1c5
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore everything
*

# Allow files and directories
!/tests
!/scripts
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Use the desired base image
FROM python:3.11.3
FROM python:3.11.9-slim-bullseye

# Set the working directory
WORKDIR /integration-tests

# Copy the requirements.txt file to the working directory
COPY tests/requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# copy support scripts
COPY --chmod=755 ./scripts/collectRebotResults.sh /bin/collectRebotResults
COPY --chmod=755 ./scripts/runRobotTest.sh /bin/runRobotTest

# Copy the rest of the project files to the working directory
COPY . .
COPY ./tests ./tests

# Install dependencies
RUN mv ./tests/requirements.txt ./requirements.txt && \
pip install --no-cache-dir -r requirements.txt
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Please refer to https://docs.ehrbase.org/en/latest/03_development/02_testing/index.html

## Running the tests
## Running the tests locally

This command will run all tests from `tests/robot` folder.
DB and server have to be started prior to running the tests.
Expand All @@ -12,4 +12,20 @@ DB and server have to be started prior to running the tests.
```bash
cd tests
./run_local_tests.sh
```
```

## Running the test using docker

Execute a single test suite and store results in `./results`:
```bash
docker run -ti -v ./results:/integration-tests/results ehrbase/integration-tests:build runRobotTest \
--serverBase http://ehrbase:8080 \
--name SANITY \
--path SANITY_TESTS \
--tags Sanity
```

Collect results of multiple tests into a single report
```bash
docker run -ti -v ./results:/integration-tests/results -v ./report:/integration-tests/report ehrbase/integration-tests:build collectRebotResults
```
38 changes: 38 additions & 0 deletions scripts/collectRebotResults.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#set -u

base=$(pwd)
dirResults="$base/results"
dirReport="$base/report"


############################################################
# Ensures we have a clean report directory #
############################################################

mkdir -p ${dirReport}
rm -Rf ${dirReport}/*


############################################################
# Run rebot #
############################################################

echo "------------------------------------------------------"
echo "Collecting Robot Test-Results:"
echo " - $(ls -m ${dirResults} | sed -e $'s/, /\\\n - /g')"
echo "------------------------------------------------------"

# run rebot
rebot \
--name EHRbase \
--outputdir ${dirReport} \
--log Final_Log.html \
--report Final_Report.html \
--output output.xml \
${dirResults}/*/output.xml

# allow to read/write the result for everyone
chmod -R ugo+rw ${dirReport}

exit 0
145 changes: 145 additions & 0 deletions scripts/runRobotTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/bash
set -u

base=$(pwd)
dirResults="$base/results"


############################################################
# Help #
############################################################
showHelp()
{
# Display Help
echo "Run a given robot integration tests suite."
echo
echo "Syntax: runRobotTests [h|-n|-p|-t|-s]"
echo
echo "Example: runRobotTests --name SANITY --path SANITY_TESTS --tags Sanity -t TEST"
echo
echo "options:"
echo "n|name Name of the suite also used as result sub directory."
echo "p|path Path of the suite to run."
echo "t|tags Include tags."
echo "s|suite SUT param defaults to 'TEST'."
echo "serverBase Ehrbase server base, defaults to env var EHRBASE_BASE_URL or fallback to http://ehrbase:8080"
echo "serverNodeName Ehrbase server node name, defaults to env var SERVER_NODENAME or fallback to local.ehrbase.org"
echo
}

name=0
path=0
tags=0
suite='TEST'
serverBase=${EHRBASE_BASE_URL:-http://ehrbase:8080}
serverNodeName=${SERVER_NODENAME:-local.ehrbase.org}
POSITIONAL_ARGS=()

############################################################
# parse command line args #
############################################################

while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
showHelp
exit
;;
-n|--name)
name="$2"
shift # past argument
shift # past value
;;
-p|--path)
path="$2"
shift # past argument
shift # past value
;;
-t|--tags)
tags="$2"
shift # past argument
shift # past value
;;
-s|--suite)
suite="$2"
shift # past argument
shift # past value
;;
--serverBase)
serverBase="$2"
shift # past argument
shift # past value
;;
--serverNodeName)
serverNodeName="$2"
shift # past argument
shift # past value
;;
*)
echo "Error: Invalid option [$1]"
exit -1;;
esac
done


############################################################
# Checks given parameters #
############################################################

if [ $name == 0 ]; then
echo "Option [name] not specified"
exit -1
fi
if [ $path == 0 ]; then
echo "Option [path] not specified"
exit -1
fi
if [ $path == 0 ]; then
echo "Option [path] not specified"
exit -1
fi


############################################################
# Ensures we are in a clean result directory #
############################################################

rm -Rf ${dirResults}/${name}


############################################################
# Run tests #
############################################################

echo "---------------------------------------------------------------------------------------"
echo "Running Robot Test-Suite [name: ${name}, path: ${path}, tags: ${tags}, suite: ${suite}]"
echo "---------------------------------------------------------------------------------------"

cd tests
robot --include ${tags} \
--skip TODO \
--skip future \
--loglevel INFO \
-e ADMIN \
-e SECURITY \
--dotted \
--console quiet \
--skiponfailure not-ready -L TRACE \
--flattenkeywords for \
--flattenkeywords foritem \
--flattenkeywords name:_resources.* \
--flattenkeywords "name:composition_keywords.Load Json File With Composition" \
--flattenkeywords "name:template_opt1.4_keywords.upload OPT file" \
--removekeywords "name:JSONLibrary.Load Json From File" \
--removekeywords "name:Change Json KeyValue and Save Back To File" \
--removekeywords "name:JSONLibrary.Update Value To Json" \
--removekeywords "name:JSONLibrary.Convert JSON To String" \
--removekeywords "name:JSONLibrary.Get Value From Json" \
--report NONE \
--name ${name} \
--outputdir ${dirResults}/${name} \
-v SUT:${suite} \
-v nodocker \
-v NODENAME:${serverNodeName} \
-v BASEURL:${serverBase}/ehrbase/rest/openehr/v1 \
robot/${path}
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RESTinstance == 1.1.0

docker == 4.0.2
deepdiff == 4.3.2
psycopg2-binary == 2.8.6
psycopg2-binary == 2.9.9
python-benedict == 0.24.2

pyjwt == 2.4.0
Expand Down

0 comments on commit 9e7b1c5

Please sign in to comment.