Skip to content

Commit

Permalink
Merge pull request #203 from cisagov/improvement/change_version_file_…
Browse files Browse the repository at this point in the history
…format

Change the format of the version tracking file
  • Loading branch information
mcdonnnj authored Dec 6, 2024
2 parents 71198d3 + 414efb4 commit 7d4071d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bump-version
Original file line number Diff line number Diff line change
Expand Up @@ -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//\./\\\.}
Expand Down
2 changes: 1 addition & 1 deletion src/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.1"
0.0.1
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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(
Expand Down
18 changes: 3 additions & 15 deletions tests/container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d4071d

Please sign in to comment.