#1 Adding tests for CI
Closed 5 years ago by cverna. Opened 5 years ago by cverna.
container/ cverna/fedora-container-image adding_tests  into  master

@@ -0,0 +1,3 @@ 

+ #!/bin/bash

+ 

+ pytest-3 -vv ./test_container.py

@@ -0,0 +1,52 @@ 

+ #!/usr/bin/python3

+ 

+ import logging

+ import os

+ 

+ import conu

+ 

+ import pytest

+ 

+ 

+ IMAGE = os.environ.get("IMAGE_NAME", "registry.fedoraproject.org/fedora")

+ TAG = os.environ.get("IMAGE_TAG", "latest")

+ 

+ 

+ @pytest.fixture(scope="module")

+ def container(request):

+     with conu.DockerBackend(logging_level=logging.DEBUG) as backend:

+         im = backend.ImageClass(IMAGE, tag=TAG)

+         b = conu.DockerRunBuilder(command=["sleep", "infinity"])

+         b.options += [

+             "--net", "host",

+             "--pid=host",

+             "--ipc", "host",

+             "-it",

+             "--privileged",

+             "-v", "/run:/run",

+             "-v", "/:/host",

+             "-v", "/var/log:/var/log",

+         ]

+         machine_id_path = "/etc/machine-id"

+         if os.path.exists(machine_id_path):

+             b.options += [

+                 "-v", "%s:%s" % (machine_id_path, machine_id_path)

+             ]

+         localtime_path = "/etc/localtime"

+         if os.path.exists(localtime_path):

+             b.options += [

+                 "-v", "%s:%s" % (localtime_path, localtime_path)

+             ]

+         container = im.run_via_binary(b)

+     yield container

+     container.stop()

+     container.delete()

+ 

+ 

+ class TestContainer:

+     def test_python3(self, container):

+         container.execute(["python3", "-V"])

+ 

+ 

+ if __name__ == '__main__':

+     pytest.main()

file added
+2
@@ -0,0 +1,2 @@ 

+ [all]

+ localhost ansible_connection=local

file added
+13
@@ -0,0 +1,13 @@ 

+ - hosts: localhost

+   roles:

+   - role: standard-test-basic

+     tags:

+     - container

+     tests:

+     - integration

+     required_packages:

+     - python3-conu

+     - python3-pytest

+     - docker

+     required_services:

+     - docker