Skip to content

Commit

Permalink
Merge pull request #82 from cisagov/lineage/skeleton
Browse files Browse the repository at this point in the history
⚠️ CONFLICT! Lineage pull request for: skeleton
  • Loading branch information
jsf9k authored Jul 31, 2023
2 parents 4980bb8 + a511e29 commit 5bf2f72
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--requirement requirements.txt
pre-commit
pytest
pytest-dockerc
python-on-whales
13 changes: 11 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@
"""
# Third-Party Libraries
import pytest
from python_on_whales import docker

MAIN_SERVICE_NAME = "scanner"


@pytest.fixture(scope="session")
def dockerc():
"""Start up the Docker composition."""
docker.compose.up(detach=True)
yield docker
docker.compose.down()


@pytest.fixture(scope="session")
def main_container(dockerc):
"""Return the main container from the Docker composition."""
# find the container by name even if it is stopped already
return dockerc.containers(service_names=[MAIN_SERVICE_NAME], stopped=True)[0]
return dockerc.compose.ps(services=[MAIN_SERVICE_NAME], all=True)[0]


# See #64
Expand All @@ -23,7 +32,7 @@ def main_container(dockerc):
# 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]
# return dockerc.compose.ps(services=[VERSION_SERVICE_NAME], all=True)[0]


def pytest_addoption(parser):
Expand Down
30 changes: 17 additions & 13 deletions tests/container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
def test_container_count(dockerc):
"""Verify the test composition and container."""
# stopped parameter allows non-running containers in results
print(dockerc.containers)
assert (
len(dockerc.containers(stopped=True)) == 2
len(dockerc.compose.ps(all=True)) == 2
), "Wrong number of containers were started."


Expand All @@ -18,7 +17,7 @@ def test_container_count(dockerc):
# """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,19 +28,22 @@ def test_container_count(dockerc):


# See #64
# 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 #64
# 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."


Expand All @@ -61,10 +63,11 @@ def test_container_count(dockerc):


# See #64
# 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 @@ -82,5 +85,6 @@ def test_container_count(dockerc):
# 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"

0 comments on commit 5bf2f72

Please sign in to comment.