Skip to content

Commit

Permalink
Comment out some tests
Browse files Browse the repository at this point in the history
The container doesn't currently support the functionality being
checked by the tests.  See #57 for more details.
  • Loading branch information
jsf9k committed May 18, 2021
1 parent ea50e66 commit d0342b2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 76 deletions.
17 changes: 9 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ def main_container(dockerc):
return dockerc.containers(service_names=[MAIN_SERVICE_NAME], stopped=True)[0]


@pytest.fixture(scope="session")
def version_container(dockerc):
"""Return the version container from the docker composition.
The version container should just output the version of its underlying contents.
"""
# find the container by name even if it is stopped already
return dockerc.containers(service_names=[VERSION_SERVICE_NAME], stopped=True)[0]
# See #57
# @pytest.fixture(scope="session")
# def version_container(dockerc):
# """Return the version container from the docker composition.

# The version container should just output the version of its underlying contents.
# """
# # find the container by name even if it is stopped already
# return dockerc.containers(service_names=[VERSION_SERVICE_NAME], stopped=True)[0]


def pytest_addoption(parser):
Expand Down
142 changes: 74 additions & 68 deletions tests/container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

# Standard Python Libraries
import os
import time

# Third-Party Libraries
import pytest
# import time

# import pytest

ENV_VAR = "ECHO_MESSAGE"
ENV_VAR_VAL = "Hello World from docker-compose!"
Expand All @@ -26,68 +26,74 @@ def test_container_count(dockerc):
), "Wrong number of containers were started."


def test_wait_for_ready(main_container):
"""Wait for container to be ready."""
TIMEOUT = 10
for i in range(TIMEOUT):
if READY_MESSAGE in main_container.logs().decode("utf-8"):
break
time.sleep(1)
else:
raise Exception(
f"Container does not seem ready. "
f'Expected "{READY_MESSAGE}" in the log within {TIMEOUT} seconds.'
)


def test_wait_for_exits(main_container, version_container):
"""Wait for containers to exit."""
assert main_container.wait() == 0, "Container service (main) did not exit cleanly"
assert (
version_container.wait() == 0
), "Container service (version) did not exit cleanly"


def test_output(main_container):
"""Verify the container had the correct output."""
main_container.wait() # make sure container exited if running test isolated
log_output = main_container.logs().decode("utf-8")
assert SECRET_QUOTE in log_output, "Secret not found in log output."


@pytest.mark.skipif(
RELEASE_TAG in [None, ""], reason="this is not a release (RELEASE_TAG not set)"
)
def test_release_version():
"""Verify that release tag version agrees with the module version."""
pkg_vars = {}
with open(VERSION_FILE) as f:
exec(f.read(), pkg_vars) # nosec
project_version = pkg_vars["__version__"]
assert (
RELEASE_TAG == f"v{project_version}"
), "RELEASE_TAG does not match the project version"


def test_log_version(version_container):
"""Verify the container outputs the correct version to the logs."""
version_container.wait() # make sure container exited if running test isolated
log_output = version_container.logs().decode("utf-8").strip()
pkg_vars = {}
with open(VERSION_FILE) as f:
exec(f.read(), pkg_vars) # nosec
project_version = pkg_vars["__version__"]
assert (
log_output == project_version
), f"Container version output to log does not match project version file {VERSION_FILE}"


def test_container_version_label_matches(version_container):
"""Verify the container version label is the correct version."""
pkg_vars = {}
with open(VERSION_FILE) as f:
exec(f.read(), pkg_vars) # nosec
project_version = pkg_vars["__version__"]
assert (
version_container.labels["org.opencontainers.image.version"] == project_version
), "Dockerfile version label does not match project version"
# See #57
# def test_wait_for_ready(main_container):
# """Wait for container to be ready."""
# TIMEOUT = 10
# for i in range(TIMEOUT):
# if READY_MESSAGE in main_container.logs().decode("utf-8"):
# break
# time.sleep(1)
# else:
# raise Exception(
# f"Container does not seem ready. "
# f'Expected "{READY_MESSAGE}" in the log within {TIMEOUT} seconds.'
# )


# See #57
# def test_wait_for_exits(main_container, version_container):
# """Wait for containers to exit."""
# assert main_container.wait() == 0, "Container service (main) did not exit cleanly"
# assert (
# version_container.wait() == 0
# ), "Container service (version) did not exit cleanly"


# See #57
# def test_output(main_container):
# """Verify the container had the correct output."""
# main_container.wait() # make sure container exited if running test isolated
# log_output = main_container.logs().decode("utf-8")
# assert SECRET_QUOTE in log_output, "Secret not found in log output."


# See #57
# @pytest.mark.skipif(
# RELEASE_TAG in [None, ""], reason="this is not a release (RELEASE_TAG not set)"
# )
# def test_release_version():
# """Verify that release tag version agrees with the module version."""
# pkg_vars = {}
# with open(VERSION_FILE) as f:
# exec(f.read(), pkg_vars) # nosec
# project_version = pkg_vars["__version__"]
# assert (
# RELEASE_TAG == f"v{project_version}"
# ), "RELEASE_TAG does not match the project version"


# See #57
# def test_log_version(version_container):
# """Verify the container outputs the correct version to the logs."""
# version_container.wait() # make sure container exited if running test isolated
# log_output = version_container.logs().decode("utf-8").strip()
# pkg_vars = {}
# with open(VERSION_FILE) as f:
# exec(f.read(), pkg_vars) # nosec
# project_version = pkg_vars["__version__"]
# assert (
# log_output == project_version
# ), f"Container version output to log does not match project version file {VERSION_FILE}"


# See #57
# def test_container_version_label_matches(version_container):
# """Verify the container version label is the correct version."""
# pkg_vars = {}
# with open(VERSION_FILE) as f:
# exec(f.read(), pkg_vars) # nosec
# project_version = pkg_vars["__version__"]
# assert (
# version_container.labels["org.opencontainers.image.version"] == project_version
# ), "Dockerfile version label does not match project version"

0 comments on commit d0342b2

Please sign in to comment.