Skip to content

Commit

Permalink
Correctly merge in upstream testing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsf9k committed Jul 28, 2023
1 parent ab98639 commit e336abd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 79 deletions.
9 changes: 1 addition & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,10 @@ def main_container(dockerc):
# def version_container(dockerc):
# """Return the version container from the Docker composition.

<<<<<<< HEAD
# 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]
=======
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.compose.ps(services=[VERSION_SERVICE_NAME], all=True)[0]
>>>>>>> a9d6c92ea3ca2760e4a18276d06c668058dd3670
# return dockerc.compose.ps(services=[VERSION_SERVICE_NAME], all=True)[0]


def pytest_addoption(parser):
Expand Down
87 changes: 16 additions & 71 deletions tests/container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ def test_container_count(dockerc):
), "Wrong number of containers were started."


<<<<<<< HEAD
# See #60
# 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"):
# if READY_MESSAGE in main_container.logs():
# break
# time.sleep(1)
# else:
Expand All @@ -29,52 +28,23 @@ def test_container_count(dockerc):


# See #60
# def test_wait_for_exits(main_container, version_container):
# def test_wait_for_exits(dockerc, 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
# dockerc.wait(main_container.id) == 0
# ), "Container service (main) did not exit cleanly"
# assert (
# dockerc.wait(version_container.id) == 0
# ), "Container service (version) did not exit cleanly"


# See #60
# def test_output(main_container):
# def test_output(dockerc, 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")
# # make sure container exited if running test isolated
# dockerc.wait(main_container.id)
# log_output = main_container.logs()
# assert SECRET_QUOTE in log_output, "Secret not found in log output."
=======
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():
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(dockerc, main_container, version_container):
"""Wait for containers to exit."""
assert (
dockerc.wait(main_container.id) == 0
), "Container service (main) did not exit cleanly"
assert (
dockerc.wait(version_container.id) == 0
), "Container service (version) did not exit cleanly"


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


# See #60
Expand All @@ -92,12 +62,12 @@ def test_output(dockerc, main_container):
# ), "RELEASE_TAG does not match the project version"


<<<<<<< HEAD
# See #60
# def test_log_version(version_container):
# def test_log_version(dockerc, 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()
# # make sure container exited if running test isolated
# dockerc.wait(version_container.id)
# log_output = version_container.logs().strip()
# pkg_vars = {}
# with open(VERSION_FILE) as f:
# exec(f.read(), pkg_vars) # nosec
Expand All @@ -115,31 +85,6 @@ def test_output(dockerc, main_container):
# exec(f.read(), pkg_vars) # nosec
# project_version = pkg_vars["__version__"]
# assert (
# version_container.labels["org.opencontainers.image.version"] == project_version
# version_container.config.labels["org.opencontainers.image.version"]
# == project_version
# ), "Dockerfile version label does not match project version"
=======
def test_log_version(dockerc, version_container):
"""Verify the container outputs the correct version to the logs."""
# make sure container exited if running test isolated
dockerc.wait(version_container.id)
log_output = version_container.logs().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.config.labels["org.opencontainers.image.version"]
== project_version
), "Dockerfile version label does not match project version"
>>>>>>> a9d6c92ea3ca2760e4a18276d06c668058dd3670

0 comments on commit e336abd

Please sign in to comment.