Skip to content

Commit 3d44b08

Browse files
committed
[IMP] tests: add a test to verify the git version
1 parent 5972a77 commit 3d44b08

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

tests/__init__.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from itertools import product
1111
from os import environ
1212
from os.path import dirname, join
13-
from subprocess import Popen
13+
from subprocess import Popen, check_output
1414

1515
logging.basicConfig(level=logging.DEBUG)
1616

@@ -728,6 +728,40 @@ def test_aggregate_permissions(self):
728728
("autoaggregate",),
729729
)
730730

731+
def test_git_version(self):
732+
smallest_dir = join(SCAFFOLDINGS_DIR, "smallest")
733+
# make sure image is built before getting expected git version from image layers (history)
734+
for sub_env in matrix():
735+
self.compose_test(smallest_dir, sub_env, ("id",))
736+
737+
# detect expected git version from image layers
738+
if "COMPOSE_PROJECT_NAME" in os.environ:
739+
image_name = f'{os.environ["COMPOSE_PROJECT_NAME"]}_odoo:latest'
740+
else:
741+
image_name = "smallest_odoo:latest"
742+
image_layers = check_output(["docker", "image", "history", image_name]).split(
743+
b"\n"
744+
)
745+
git_version_layer = [
746+
layer for layer in image_layers if b"ARG GIT_VERSION=" in layer
747+
][0]
748+
git_version = [
749+
c for c in git_version_layer.split(b" ") if c.startswith(b"GIT_VERSION=")
750+
][0].split(b"=")[1]
751+
expected_git_version = f"git version {git_version.decode('utf-8')}"
752+
753+
# verify that the git used inside the container matches the expected version
754+
for sub_env in matrix():
755+
self.compose_test(
756+
smallest_dir,
757+
sub_env,
758+
(
759+
"bash",
760+
"-c",
761+
f'set -x; test "$(git --version)" == "{expected_git_version}"',
762+
),
763+
)
764+
731765

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

0 commit comments

Comments
 (0)