Skip to content

Commit

Permalink
[IMP] tests: add a test to verify the git version
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-wtioit committed Feb 15, 2023
1 parent 4b5414c commit c3eea7e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from itertools import product
from os import environ
from os.path import dirname, join
from subprocess import Popen
from subprocess import Popen, check_output

logging.basicConfig(level=logging.DEBUG)

Expand Down Expand Up @@ -728,6 +728,40 @@ def test_aggregate_permissions(self):
("autoaggregate",),
)

def test_git_version(self):
smallest_dir = join(SCAFFOLDINGS_DIR, "smallest")
# make sure image is built before getting expected git version from image layers (history)
for sub_env in matrix():
self.compose_test(smallest_dir, sub_env, ("id",))

# detect expected git version from image layers
if "COMPOSE_PROJECT_NAME" in os.environ:
image_name = f'{os.environ["COMPOSE_PROJECT_NAME"]}_odoo:latest'
else:
image_name = "smallest_odoo:latest"
image_layers = check_output(["docker", "image", "history", image_name]).split(
b"\n"
)
git_version_layer = [
layer for layer in image_layers if b"ARG GIT_VERSION=" in layer
][0]
git_version = [
c for c in git_version_layer.split(b" ") if c.startswith(b"GIT_VERSION=")
][0].split(b"=")[1]
expected_git_version = f"git version {git_version.decode('utf-8')}"

# verify that the git used inside the container matches the expected version
for sub_env in matrix():
self.compose_test(
smallest_dir,
sub_env,
(
"bash",
"-c",
f'set -x; test "$(git --version)" == "{expected_git_version}"',
),
)


if __name__ == "__main__":
unittest.main()

0 comments on commit c3eea7e

Please sign in to comment.