diff --git a/README.rst b/README.rst index ebe1d4c..b8a6e01 100644 --- a/README.rst +++ b/README.rst @@ -133,33 +133,38 @@ Running the unit-tests To run the unit-tests, there is container available with all the dependencies needed. +First you will need to have podman installed on your workstation. :: + + $ sudo dnf install podman + + Use the following command to run the tests :: - $ ./dev/run-tests-docker.py + $ ./dev/run-tests-container.py This command will build a fedora based container and execute the test suite. If you wish to execute the test suite on a centos based container run the following command :: - $ ./dev/run-tests-docker.py --centos + $ ./dev/run-tests-container.py --centos When the test container image has been built you can skip the building step to save time and run directly the test suite. :: - $ ./dev/run-tests-docker.py --skip-build - $ ./dev/run-tests-docker.py --centos --skip-build + $ ./dev/run-tests-container.py --skip-build + $ ./dev/run-tests-container.py --centos --skip-build You can also run a single test case :: - $ ./dev/run-tests-docker.py tests/test_pagure_flask_ui_priorities.py + $ ./dev/run-tests-container.py tests/test_pagure_flask_ui_priorities.py Or a single test :: - $ ./dev/run-tests-docker.py tests/test_pagure_flask_ui_priorities.py:PagureFlaskPrioritiestests.test_ticket_with_no_priority + $ ./dev/run-tests-container.py tests/test_pagure_flask_ui_priorities.py:PagureFlaskPrioritiestests.test_ticket_with_no_priority -You can also get `run-tests-docker` help :: +You can also get `run-tests-container` help :: - $ ./dev/run-tests-docker.py --help + $ ./dev/run-tests-container.py --help Manually ^^^^^^^^ diff --git a/dev/docker/test_env_template b/dev/docker/test_env_template index e2f5dde..81a528b 100644 --- a/dev/docker/test_env_template +++ b/dev/docker/test_env_template @@ -6,7 +6,6 @@ $infra_repo RUN $pkg_mgr install -y $pkg_list \ && $pkg_mgr clean all -ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 -WORKDIR /code -ENTRYPOINT [ "/code/runtests.py", "run" ] +WORKDIR /pagure +ENTRYPOINT [ "/pagure/runtests.py", "run" ] CMD [] diff --git a/dev/run-tests-container.py b/dev/run-tests-container.py new file mode 100755 index 0000000..3e66e2e --- /dev/null +++ b/dev/run-tests-container.py @@ -0,0 +1,109 @@ +#! /usr/bin/python3 +import argparse +import os +import subprocess as sp +from string import Template + +TEMPLATE = "dev/docker/test_env_template" + +PKG_LIST = "python-alembic python-arrow python-binaryornot \ + python-bleach python-blinker python-chardet python-cryptography \ + python-docutils python-enum34 python-flask python2-fedora-flask \ + python-flask-wtf python2-bcrypt python-jinja2 \ + python-markdown python-munch python-openid-cla \ + python-openid-teams python-psutil python-pygit2 python2-pillow \ + python-sqlalchemy python-straight-plugin python-wtforms \ + python-nose python3-coverage python-mock python-mock \ + python-eventlet python2-flask-oidc python-flake8 python-celery \ + python-redis python-trololio python-beautifulsoup4 redis vim git" + + +def setup_parser(): + """ Setup the cli arguments """ + parser = argparse.ArgumentParser(prog="pagure-test") + parser.add_argument( + "test_case", nargs="?", default="", help="Run the given test case" + ) + parser.add_argument( + "--fedora", + action="store_true", + help="Run the tests in fedora environment (DEFAULT)", + ) + parser.add_argument( + "--centos", + action="store_true", + help="Run the tests in centos environment", + ) + parser.add_argument( + "--skip-build", + dest="skip_build", + action="store_false", + help="Skip building the container image", + ) + + return parser + + +if __name__ == "__main__": + parser = setup_parser() + args = parser.parse_args() + + if args.centos is True: + base_image = "centos:7" + pkg_mgr = "yum" + epel_pkg = "RUN yum -y install epel-release" + infra_repo = ( + "ADD ./fedora-infra-tags.repo /etc/yum.repos.d/infra-tags.repo" + ) + container_name = "pagure-test-centos" + PKG_LIST += "python34 python34-coverage" + else: + base_image = "registry.fedoraproject.org/fedora:28" + pkg_mgr = "dnf" + container_name = "pagure-test-fedora" + epel_pkg = "" + infra_repo = "" + + with open(TEMPLATE, "r") as fp: + t = Template(fp.read()) + with open("dev/docker/test_env", "w") as fp: + fp.write( + t.substitute( + base_image=base_image, + pkg_list=PKG_LIST, + pkg_mgr=pkg_mgr, + epel_pkg=epel_pkg, + infra_repo=infra_repo, + ) + ) + + if args.skip_build is not False: + print("------ Building Docker Image -----") + sp.run( + [ + "podman", + "build", + "--rm", + "-t", + container_name, + "-f", + "dev/docker/test_env", + "dev/docker", + ] + ) + + print("--------- Running Test --------------") + sp.run( + [ + "podman", + "run", + "-it", + "--rm", + "--name", + container_name, + "-v", + "{}:/pagure".format(os.getcwd()), + container_name, + args.test_case, + ] + ) diff --git a/dev/run-tests-docker.py b/dev/run-tests-docker.py deleted file mode 100755 index 8f1a34a..0000000 --- a/dev/run-tests-docker.py +++ /dev/null @@ -1,67 +0,0 @@ -#! /usr/bin/python3 -import argparse -import os -import subprocess as sp -from string import Template - -TEMPLATE = 'dev/docker/test_env_template' - -PKG_LIST = 'python-alembic python-arrow python-binaryornot \ - python-bleach python-blinker python-chardet python-cryptography \ - python-docutils python-enum34 python-flask python2-fedora-flask \ - python-flask-wtf python2-bcrypt python-jinja2 \ - python-markdown python-munch python-openid-cla \ - python-openid-teams python-psutil python-pygit2 python2-pillow \ - python-sqlalchemy python-straight-plugin python-wtforms \ - python-nose python3-coverage python-mock python-mock \ - python-eventlet python2-flask-oidc python-flake8 python-celery \ - python-redis python-trololio python-beautifulsoup4 redis vim git' - - -def setup_parser(): - """ Setup the cli arguments """ - parser = argparse.ArgumentParser(prog='pagure-test') - parser.add_argument('test_case', nargs='?', default='', - help='Run the given test case') - parser.add_argument('--fedora', action='store_true', - help='Run the tests in fedora environment (DEFAULT)') - parser.add_argument('--centos', action='store_true', - help='Run the tests in centos environment') - parser.add_argument('--skip-build', dest='skip_build', action='store_false', - help='Skip building the container image') - - return parser - - -if __name__ == '__main__': - parser = setup_parser() - args = parser.parse_args() - - if args.centos is True: - base_image = 'centos:7' - pkg_mgr = 'yum' - epel_pkg = 'RUN yum -y install epel-release' - infra_repo = 'ADD ./fedora-infra-tags.repo /etc/yum.repos.d/infra-tags.repo' - container_name = 'pagure-test-centos' - else: - base_image = 'registry.fedoraproject.org/fedora:28' - pkg_mgr = 'dnf' - container_name = 'pagure-test-fedora' - epel_pkg = '' - infra_repo = '' - - with open(TEMPLATE, 'r') as fp: - t = Template(fp.read()) - with open('dev/docker/test_env', 'w') as fp: - fp.write(t.substitute(base_image=base_image, pkg_list=PKG_LIST, - pkg_mgr=pkg_mgr, epel_pkg=epel_pkg, - infra_repo=infra_repo)) - - if args.skip_build is not False: - print('------ Building Docker Image -----') - sp.run(['docker', 'build', '--rm', '-t', container_name, '-f', - 'dev/docker/test_env', 'dev/docker']) - - print('--------- Running Test --------------') - sp.run(['docker', 'run', '-it', '--rm', '--name', container_name, '-v', - '{}:/code:z'.format(os.getcwd()), container_name, args.test_case])