Allow to run tests with PostgreSQL inside container

This patch introduces a new environment variable in order to allow running
tests with different database backend. This is useful particularly for running
tests inside container. With this change, it is possible run tests in following
combinations:

* Python 2 and SQLite
* Python 3 and SQLite
* Python 2 and PostgreSQL
* Python 3 and PostgreSQL

Package python-psycopg2 is installed in both Dockerfile-tests and
Dockerfile-tests-py3 in case of running tests with PostgreSQL.

A new script contrib/run-unittests.sh is added to make it easy to run tests. An
example:

    contrib/run-unittests.sh --py3 --with-pgsql

that runs tests with Python 3 and PostgreSQL.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
Chenxiong Qi
2019-06-11 15:27:06 +08:00
parent 5794c4375d
commit 630f7b4e18
8 changed files with 111 additions and 18 deletions

View File

@@ -1,28 +1,33 @@
Running Tests
=============
Since MBS requires Python dependencies that aren't available using PyPi (e.g. libsolv bindings),
there are container images (based on CentOS and Fedora) that can be used to run the code analysis and unit tests.
Since MBS requires Python dependencies that aren't available using PyPi (e.g.
libsolv bindings), there are container images (based on CentOS and Fedora) that
can be used to run the code analysis and unit tests.
To run the tests, you must first install `podman` with::
* ``docker/Dockerfile-tests`` is based on ``centos:7``, inside which tests run
with Python 2.
$ sudo dnf install podman
* ``docker/Dockerfile-tests-py3`` is based on ``fedora:29``, inside which tests
run with Python 3.
From the repo root, run the tests with::
Both of these images are available from Quay.io under `factory2 organization`_
and named ``mbs-test-centos`` and ``mbs-test-fedora`` individually. Refer to
section "Updating test images in Quay" to learn how to manage these images.
$ podman run -t --rm -v $PWD:/src:Z quay.io/factory2/mbs-test-centos
.. _factory2: https://quay.io/organization/factory2
To run the tests with Python 3 use the image based on Fedora::
To run the tests, just simply run: ``contrib/run-unittests.sh``
$ podman run -t --rm -v $PWD:/src:Z quay.io/factory2/mbs-test-fedora
By default, this script runs tests inside container ``mbs-test-centos``
with Python 2 and SQLite database.
If you need to build the container image locally use::
There are options to change the tests enviornment:
$ podman build -t mbs-test-centos -f docker/Dockerfile-tests .
* ``--py3``: run tests with Python 3.
* ``--with-pgsql``: run tests with PostgreSQL database.
or::
$ podman build -t mbs-test-fedora -f docker/Dockerfile-tests-py3 .
For example, ``contrib/run-unittests.sh --py3 --with-pgsql``.
Style Guide
===========
@@ -184,7 +189,19 @@ Historical Names of Module Build Service
Updating test images in Quay
============================
The Quay web UI can be used to update the images used for testing:
The docker images inside which to run tests could be built locally or via Quay
web UI.
For building locally, use ``podman build`` or ``docker build``. For example
with ``podman``::
$ podman build -t quay.io/factory2/mbs-test-centos -f docker/Dockerfile-tests .
or::
$ podman build -t quay.io/factory2/mbs-test-fedora -f docker/Dockerfile-tests-py3 .
To update the images used for testing via Quay web UI:
* https://quay.io/repository/factory2/mbs-test-centos
* https://quay.io/repository/factory2/mbs-test-fedora