|
10 | 10 | from itertools import product |
11 | 11 | from os import environ |
12 | 12 | from os.path import dirname, join |
13 | | -from subprocess import Popen |
| 13 | +from subprocess import Popen, check_output |
14 | 14 |
|
15 | 15 | logging.basicConfig(level=logging.DEBUG) |
16 | 16 |
|
@@ -728,6 +728,40 @@ def test_aggregate_permissions(self): |
728 | 728 | ("autoaggregate",), |
729 | 729 | ) |
730 | 730 |
|
| 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 | + |
731 | 765 |
|
732 | 766 | if __name__ == "__main__": |
733 | 767 | unittest.main() |
0 commit comments