mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-11-28 23:24:49 +08:00
Bootstrap integration tests
This is the first step to have some tests, that we could run against an MBS instance, to check that it's functionally correct. Ultimately, these will replace the test scripts (`contrib/test-*`). This doesn't really do anything yet, but I would like to make sure that everyone is on the same page regarding how this will be set up. Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -23,3 +23,4 @@ tests/test_module_build_service.db-journal
|
||||
requirements.txt.orig
|
||||
mbstest.db
|
||||
htmlcov/
|
||||
test.env.yaml
|
||||
|
||||
33
tests/integration/README.rst
Normal file
33
tests/integration/README.rst
Normal file
@@ -0,0 +1,33 @@
|
||||
==============================================
|
||||
Integration tests for the Module Build Service
|
||||
==============================================
|
||||
|
||||
This directory stores the integration tests for MBS.
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
The tests should be configured by a ``test.env.yaml`` file placed in the
|
||||
top-level directory of this repository. This can be changed to a different
|
||||
path by setting ``MBS_TEST_CONFIG``.
|
||||
|
||||
See `tests/integration/example.test.env.yaml`_ for the list of configuration
|
||||
options and examples.
|
||||
|
||||
Running the tests
|
||||
=================
|
||||
|
||||
Tests can be triggered from the top-level directory of this repository with::
|
||||
|
||||
tox -e integration
|
||||
|
||||
Note, that the ``integration`` environment is not part of the default ``tox``
|
||||
envlist.
|
||||
|
||||
``REQUESTS_CA_BUNDLE`` is passed in ``tox.ini`` for the ``integration``
|
||||
environment in order to enable running the tests against MBS instances which
|
||||
have self-signed certificates. Example usage::
|
||||
|
||||
REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt tox -e integration
|
||||
|
||||
.. _tests/integration/example.test.env.yaml: example.test.env.yaml
|
||||
39
tests/integration/conftest.py
Normal file
39
tests/integration/conftest.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import os
|
||||
|
||||
import yaml
|
||||
import pytest
|
||||
|
||||
from utils import MBS, Git, Koji
|
||||
|
||||
|
||||
def load_test_env():
|
||||
"""Load test environment configuration
|
||||
|
||||
:return: Test environment configuration.
|
||||
:rtype: dict
|
||||
"""
|
||||
config_file = os.getenv("MBS_TEST_CONFIG", "test.env.yaml")
|
||||
with open(config_file) as f:
|
||||
env = yaml.safe_load(f)
|
||||
return env
|
||||
|
||||
|
||||
test_env = load_test_env()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def mbs():
|
||||
return MBS(test_env["mbs_api"])
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def git():
|
||||
return Git(test_env["git_url"])
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def koji():
|
||||
return Koji(**test_env["koji"])
|
||||
9
tests/integration/example.test.env.yaml
Normal file
9
tests/integration/example.test.env.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
# API endpoint of the MBS instance under test.
|
||||
mbs_api: https://mbs.fedoraproject.org/module-build-service/2/module-builds/
|
||||
# Git instance used by the build system.
|
||||
git_url: https://src.fedoraproject.org/
|
||||
# Koji instance the MBS instance under test communicates with.
|
||||
koji:
|
||||
server: https://koji.fedoraproject.org/kojihub
|
||||
topurl: https://kojipkgs.fedoraproject.org/
|
||||
8
tests/integration/test_normal_build.py
Normal file
8
tests/integration/test_normal_build.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
def test_normal_build():
|
||||
""" TODO(csomh): implement this test
|
||||
"""
|
||||
assert True
|
||||
21
tests/integration/utils.py
Normal file
21
tests/integration/utils.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
class MBS:
|
||||
|
||||
def __init__(self, api):
|
||||
self._api = api
|
||||
|
||||
|
||||
class Git:
|
||||
|
||||
def __init__(self, url):
|
||||
self._url = url
|
||||
|
||||
|
||||
class Koji:
|
||||
|
||||
def __init__(self, server, topurl):
|
||||
self._server = server
|
||||
self._topurl = topurl
|
||||
21
tox.ini
21
tox.ini
@@ -27,6 +27,10 @@ whitelist_externals =
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
commands =
|
||||
py.test -v \
|
||||
--ignore tests/integration \
|
||||
--cov module_build_service \
|
||||
--cov-report html \
|
||||
--cov-report term \
|
||||
-W "ignore:Use .persist_selectable:DeprecationWarning" \
|
||||
-W "ignore:The ConnectionEvents.dbapi_error() event is deprecated and will be removed in a future release. Please refer to the ConnectionEvents.handle_error() event.:DeprecationWarning" \
|
||||
{posargs}
|
||||
@@ -55,5 +59,18 @@ commands =
|
||||
/bin/bash -c "bandit -r -ll $(find . -mindepth 1 -maxdepth 1 ! -name tests ! -name \.\* -type d -o -name \*.py)"
|
||||
ignore_outcome = True
|
||||
|
||||
[pytest]
|
||||
addopts = --cov module_build_service --cov-report html --cov-report term
|
||||
[testenv:integration]
|
||||
basepython = python3
|
||||
skipsdist = true
|
||||
skip_install = true
|
||||
sitepackages = false
|
||||
# let's handle integration test deps separately
|
||||
deps =
|
||||
pytest
|
||||
requests
|
||||
PyYAML
|
||||
# Set this to /etc/pki/tls/certs/ca-bundle.crt, for example,
|
||||
# if the instance tested has a self-signed certificate.
|
||||
passenv = REQUESTS_CA_BUNDLE MBS_TEST_CONFIG
|
||||
commands =
|
||||
pytest -vv --confcutdir=tests/integration {posargs:tests/integration}
|
||||
|
||||
Reference in New Issue
Block a user