Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cisagov/skeleton-docker
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: daeb027aa83e62f8723e974d459cd3ae528925ae
Choose a base ref
..
head repository: cisagov/skeleton-docker
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fd69f453785c6b660fd3c55b01112a9a7aa2a5b2
Choose a head ref
Showing with 15 additions and 17 deletions.
  1. +1 −1 bump-version
  2. +1 −1 src/version.txt
  3. +10 −0 tests/conftest.py
  4. +3 −15 tests/container_test.py
2 changes: 1 addition & 1 deletion bump-version
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ Options:
END_OF_LINE
)

old_version=$(sed -n "s/^__version__ = \"\(.*\)\"$/\1/p" $VERSION_FILE)
old_version=$(< "$VERSION_FILE")
# Comment out periods so they are interpreted as periods and don't
# just match any character
old_version_regex=${old_version//\./\\\.}
2 changes: 1 addition & 1 deletion src/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.0"
0.2.0
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
MAIN_SERVICE_NAME = "example"
VERSION_SERVICE_NAME = f"{MAIN_SERVICE_NAME}-version"

VERSION_FILE = "src/version.txt"


@pytest.fixture(scope="session")
def dockerc():
@@ -36,6 +38,14 @@ def version_container(dockerc):
return dockerc.compose.ps(services=[VERSION_SERVICE_NAME], all=True)[0]


@pytest.fixture(scope="session")
def project_version():
"""Return the version of the project."""
with open(VERSION_FILE) as f:
project_version = f.read().strip()
return project_version


def pytest_addoption(parser):
"""Add new commandline options to pytest."""
parser.addoption(
18 changes: 3 additions & 15 deletions tests/container_test.py
Original file line number Diff line number Diff line change
@@ -60,37 +60,25 @@ def test_output(dockerc, main_container):
@pytest.mark.skipif(
RELEASE_TAG in [None, ""], reason="this is not a release (RELEASE_TAG not set)"
)
def test_release_version():
def test_release_version(project_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(dockerc, version_container):
def test_log_version(dockerc, project_version, 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):
def test_container_version_label_matches(project_version, 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