Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative to hardcoding image names in tests #375

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conu/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ def parse_reference(reference):
"""
parse provided image reference into <image_repository>:<tag>

:param reference: str, e.g. (registry.fedoraproject.org/fedora:27)
:return: collection (tuple or list), ("registry.fedoraproject.org/fedora", "27")
:param reference: str, e.g. (registry.fedoraproject.org/fedora:31)
:return: collection (tuple or list), ("registry.fedoraproject.org/fedora", "31")
"""
if ":" in reference:
im, tag = reference.rsplit(":", 1)
Expand Down
5 changes: 4 additions & 1 deletion tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

FEDORA_REPOSITORY = "registry.fedoraproject.org/fedora"
FEDORA_MINIMAL_REPOSITORY = "registry.fedoraproject.org/fedora-minimal"
FEDORA_MINIMAL_REPOSITORY_TAG = "26"
FEDORA_MINIMAL_REPOSITORY_TAG = "31"
FEDORA_MINIMAL_REPOSITORY_DIGEST = "registry.fedoraproject.org/fedora-minimal@" \
"sha256:3b5147b65bf7d124b9ded3959b5e44bf392b405be219853dbcc346f8b9c06e88"
FEDORA_MINIMAL_IMAGE = "{}:{}".format(FEDORA_MINIMAL_REPOSITORY, FEDORA_MINIMAL_REPOSITORY_TAG)
Expand All @@ -34,3 +34,6 @@
CENTOS_POSTGRES_9_6_TAG = "9.6"
DJANGO_POSTGRES_TEMPLATE = "django-psql-example"
INTERNAL_REGISTRY_URL = "172.30.1.1:5000"

FEDORA_MINIMAL_IMAGE_REGEX = r"registry\.fedoraproject\.org\/fedora-minimal\:+([0-9])+"
FEDORA_MINIMAL_NAME_REGEX = "fedora-minimal:([0-9])+"
16 changes: 9 additions & 7 deletions tests/integration/test_buildah.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from conu.backend.buildah.image import BuildahImage, BuildahImagePullPolicy
from conu.utils import check_buildah_command_works
from tests.constants import FEDORA_MINIMAL_IMAGE
from ..constants import FEDORA_MINIMAL_REPOSITORY, FEDORA_MINIMAL_REPOSITORY_TAG
from ..constants import FEDORA_MINIMAL_REPOSITORY, FEDORA_MINIMAL_REPOSITORY_TAG, \
FEDORA_MINIMAL_IMAGE_REGEX

import re

def test_buildah_command():
assert check_buildah_command_works()
Expand All @@ -28,7 +30,7 @@ def test_buildah_image(buildah_backend):
insp = image.inspect()
assert "Config" in insp
assert isinstance(insp["Config"], str)
assert "registry.fedoraproject.org/fedora-minimal:26" == str(image)
assert re.match(FEDORA_MINIMAL_IMAGE_REGEX, str(image))
assert "BuildahImage(repository=%s, tag=%s)" % (FEDORA_MINIMAL_REPOSITORY,
FEDORA_MINIMAL_REPOSITORY_TAG) == repr(image)
assert isinstance(image.get_id(), string_types)
Expand Down Expand Up @@ -137,7 +139,7 @@ def test_list_containers(buildah_backend):
def test_list_images(buildah_backend):
image_list = buildah_backend.list_images()
assert len(image_list) > 0
# id of registry.fedoraproject.org/fedora-minimal:26
# id of registry.fedoraproject.org/fedora-minimal:31
assert isinstance(image_list[0], BuildahImage)
assert image_list[0].get_id()
assert image_list[0].get_full_name()
Expand All @@ -150,8 +152,8 @@ def test_image_metadata(buildah_backend):

assert im_metadata.command == ["/bin/bash"]
assert im_metadata.name == FEDORA_MINIMAL_IMAGE
assert im_metadata.env_variables["FGC"] == "f26"
assert im_metadata.env_variables["DISTTAG"] == "f26container"
assert im_metadata.env_variables["FGC"] == "f31"
assert im_metadata.env_variables["DISTTAG"] == "f31container"
assert im_metadata.labels == {}


Expand All @@ -169,8 +171,8 @@ def test_container_metadata(buildah_backend):

assert container_metadata.command == ["/bin/bash"]
assert container_metadata.name == "mycontainer"
assert container_metadata.env_variables["FGC"] == "f26"
assert container_metadata.env_variables["DISTTAG"] == "f26container"
assert container_metadata.env_variables["FGC"] == "f31"
assert container_metadata.env_variables["DISTTAG"] == "f31container"
assert container_metadata.labels == {}
finally:
c.delete(force=True)
11 changes: 6 additions & 5 deletions tests/integration/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from conu.utils import parse_reference
from ..constants import FEDORA_MINIMAL_REPOSITORY, FEDORA_MINIMAL_REPOSITORY_TAG, \
FEDORA_REPOSITORY
FEDORA_REPOSITORY, FEDORA_MINIMAL_IMAGE_REGEX, FEDORA_MINIMAL_NAME_REGEX

from conu.apidefs.metadata import ContainerStatus
from conu.backend.docker.client import get_client
Expand All @@ -42,9 +42,10 @@
from conu.backend.docker.skopeo import SkopeoTransport
from six import string_types

import re

@pytest.mark.parametrize("reference,result", [
("registry.fedoraproject.org/fedora:27", ("registry.fedoraproject.org/fedora", "27")),
("registry.fedoraproject.org/fedora:31", ("registry.fedoraproject.org/fedora", "31")),
("registry.fedoraproject.org/fedora", ("registry.fedoraproject.org/fedora", "latest")),
("registry.fedoraproject.org:7890/fedora",
("registry.fedoraproject.org:7890/fedora", "latest")),
Expand Down Expand Up @@ -135,8 +136,8 @@ def test_image():
image = backend.ImageClass(FEDORA_MINIMAL_REPOSITORY, tag=FEDORA_MINIMAL_REPOSITORY_TAG)
assert "Config" in image.inspect()
assert "Config" in image.inspect()
assert "fedora-minimal:26" in image.get_full_name()
assert "registry.fedoraproject.org/fedora-minimal:26" == str(image)
assert re.match(FEDORA_MINIMAL_IMAGE_REGEX, image.get_full_name())
assert re.match(FEDORA_MINIMAL_IMAGE_REGEX, str(image))
assert "DockerImage(repository=%s, tag=%s)" % (FEDORA_MINIMAL_REPOSITORY,
FEDORA_MINIMAL_REPOSITORY_TAG) == repr(image)
assert isinstance(image.get_id(), string_types)
Expand Down Expand Up @@ -196,7 +197,7 @@ def test_copy_from(tmpdir):
try:
c.copy_from("/etc/fedora-release", str(tmpdir))
with open(os.path.join(str(tmpdir), "fedora-release")) as fd:
assert fd.read() == "Fedora release 26 (Twenty Six)\n"
assert fd.read() == "Fedora release 31 (Thirty One)\n"

c.copy_from("/etc", str(tmpdir))
os.path.exists(os.path.join(str(tmpdir), "passwd"))
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def test_container_read_file(docker_container):
with pytest.raises(ConuException):
fs.read_file("/i/lost/my/banana")
content = fs.read_file("/etc/system-release")
assert content == "Fedora release 26 (Twenty Six)\n"
assert content == "Fedora release 31 (Thirty One)\n"


def test_container_copy_from(docker_container, tmpdir):
with docker_container.mount() as fs:
fs.copy_from("/etc/system-release", str(tmpdir))
with open(os.path.join(str(tmpdir), "system-release")) as fd:
assert fd.read() == "Fedora release 26 (Twenty Six)\n"
assert fd.read() == "Fedora release 31 (Thirty One)\n"

tmpdir.mkdir("etc")
if six.PY2:
Expand All @@ -76,7 +76,7 @@ def test_container_get_file(docker_container):
f = fs.get_file("/etc/system-release")
assert f.fileno()
assert "/etc/system-release" in f.name
assert f.read() == "Fedora release 26 (Twenty Six)\n"
assert f.read() == "Fedora release 31 (Thirty One)\n"
f.close()


Expand Down Expand Up @@ -119,14 +119,14 @@ def test_image_read_file(docker_image):
with pytest.raises(ConuException):
fs.read_file("/i/lost/my/banana")
content = fs.read_file("/etc/system-release")
assert content == "Fedora release 26 (Twenty Six)\n"
assert content == "Fedora release 31 (Thirty One)\n"


def test_image_copy_from(docker_image, tmpdir):
with docker_image.mount() as fs:
fs.copy_from("/etc/system-release", str(tmpdir))
with open(os.path.join(str(tmpdir), "system-release")) as fd:
assert fd.read() == "Fedora release 26 (Twenty Six)\n"
assert fd.read() == "Fedora release 31 (Thirty One)\n"

tmpdir.mkdir("etc")
if six.PY2:
Expand All @@ -142,7 +142,7 @@ def test_image_get_file(docker_image):
f = fs.get_file("/etc/system-release")
assert f.fileno()
assert "/etc/system-release" in f.name
assert f.read() == "Fedora release 26 (Twenty Six)\n"
assert f.read() == "Fedora release 31 (Thirty One)\n"
f.close()


Expand Down
9 changes: 5 additions & 4 deletions tests/integration/test_podman.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function, unicode_literals

from ..constants import FEDORA_MINIMAL_REPOSITORY, FEDORA_MINIMAL_REPOSITORY_TAG, \
FEDORA_REPOSITORY
FEDORA_REPOSITORY, FEDORA_MINIMAL_IMAGE_REGEX, FEDORA_MINIMAL_NAME_REGEX

import subprocess
import time
Expand All @@ -18,6 +18,7 @@
from six import string_types

import pytest
import re


@pytest.fixture()
Expand Down Expand Up @@ -51,8 +52,8 @@ def test_podman_image(podman_backend):
assert "%s:%s" % (FEDORA_MINIMAL_REPOSITORY, FEDORA_MINIMAL_REPOSITORY_TAG) == image.get_full_name()
assert "%s:%s" % (FEDORA_MINIMAL_REPOSITORY, FEDORA_MINIMAL_REPOSITORY_TAG) in image.inspect()['RepoTags']
assert "Config" in image.inspect()
assert "fedora-minimal:26" in image.get_full_name()
assert "registry.fedoraproject.org/fedora-minimal:26" == str(image)
assert re.match(FEDORA_MINIMAL_IMAGE_REGEX, image.get_full_name())
assert re.match(FEDORA_MINIMAL_IMAGE_REGEX, str(image))
assert "PodmanImage(repository=%s, tag=%s)" % (FEDORA_MINIMAL_REPOSITORY,
FEDORA_MINIMAL_REPOSITORY_TAG) == repr(image)
assert isinstance(image.get_id(), string_types)
Expand Down Expand Up @@ -321,7 +322,7 @@ def test_list_containers(podman_backend):
def test_list_images(podman_backend):
image_list = podman_backend.list_images()
assert len(image_list) > 0
# id of registry.fedoraproject.org/fedora-minimal:26
# id of registry.fedoraproject.org/fedora-minimal:31
the_id = subprocess.check_output(["podman", "inspect", "-f", "{{.Id}}",
FEDORA_MINIMAL_REPOSITORY + ":" +
FEDORA_MINIMAL_REPOSITORY_TAG]).decode("utf-8").strip()
Expand Down
2 changes: 1 addition & 1 deletion tests/release/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_pypi(c):
},
{
"container_image": "registry.fedoraproject.org/fedora",
"container_image_tag": "26",
"container_image_tag": "31",
"script": [
["dnf", "install", "-y", "dnf-plugins-core"],
["dnf", "copr", "enable", "-y", "ttomecek/conu"],
Expand Down