diff --git a/.github/skills/testing.md b/.github/skills/testing.md index 1460799..c1869f9 100644 --- a/.github/skills/testing.md +++ b/.github/skills/testing.md @@ -30,6 +30,30 @@ Key pabot flags: --- +## Running Tests in Docker Container + +Tests can also be executed within an isolated docker container instead. This limts the dependencies +in your local setup (like fontweights). A prerequisite is to have a running docker installation. + +Running the script `scripts/create-test-image.sh` will create a new docker image with the tag `test-dashboard`. The inline Dockerfile is based on the setup in the `.github/workflows/tests.yml`. +Running the script again can be used to update amd replace the image based on the latest patches. + +The script `scripts/run-in-test-container.sh` can be used to start a new container based on the created image in one of two ways: + +```bash +cd .../robotframework-dashboard + +# Running as an interactive shell +bash scripts/run-in-test-container.sh + +# Running in batch mode to execute some connands +bash scripts/run-in-test-container.sh "bash scripts/tests.sh" + +bash scripts/run-in-test-container.sh "robot -t *version* atest/testsuites/00_cli.robot" +``` + +The script has to be started from the top level git working directory as it mounts it into the container. + ## Test Dependencies (`requirements-test.txt`) | Library | Role | diff --git a/scripts/create-test-image.sh b/scripts/create-test-image.sh new file mode 100644 index 0000000..71e8b24 --- /dev/null +++ b/scripts/create-test-image.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# Creates a docker image to used to run tests locally, without +# installing all the required tool into your system + +die() { echo "FATAL: $*"; exit 1; } + +docker -v || die "docker seems not being installed" + +docker build --tag test-dashboard -f - . < /dev/null || + die "docker seems not being installed" +[ -n "$(docker images -q "$IMAGE" 2> /dev/null)" ] || + die "image $IMAGE not found, please run scripts/create-test-image.sh" +[ -d .git ] || + die "you need to start this script from the toplevel directory of the robotframework-dashboard repository" + +my_uid=$(id -u) +my_gid=$(id -g) + +if [ $# = 0 ]; then + echo "No arguments given, starting container with interactive terminal" + echo "Hint: don't forget to install the dashboard from the git repository in the container:" + echo " pip install . && export PATH=\$PATH:~/.local/bin" + echo "" + docker run -it --rm --ipc=host -v.:/robotframework-dashboard --user ${my_uid}:${my_gid} test-dashboard +else + echo "Deploying current workingdirectory into the container and running" + echo " $*" + echo "" + docker run -it --rm --ipc=host -v.:/robotframework-dashboard --user ${my_uid}:${my_gid} test-dashboard \ + /bin/bash -c \ + "pip install .; export PATH=\$PATH:~/.local/bin; ${*}" +fi