Skip to content

Commit c4d94fa

Browse files
committed
WIP: Run CI tests against multiple versions
1 parent dbbe385 commit c4d94fa

File tree

5 files changed

+54
-12
lines changed

5 files changed

+54
-12
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ jobs:
183183
runs-on:
184184
group: "huge-runners"
185185
timeout-minutes: 30
186+
strategy:
187+
matrix:
188+
version: ["1.0.0", "1.1.0"]
186189
steps:
187190
- name: "Check out repository code"
188191
uses: "actions/checkout@v4"
@@ -201,8 +204,13 @@ jobs:
201204
pip install invoke toml codecov
202205
- name: "Install Package"
203206
run: "poetry install --all-extras"
207+
- name: "Set environment variables for python_testcontainers"
208+
run: |
209+
echo INFRAHUB_TESTING_IMAGE_VER=${{ matrix.version }} >> $GITHUB_ENV
204210
- name: "Integration Tests"
205-
run: "poetry run pytest --cov infrahub_sdk tests/integration/"
211+
run: |
212+
echo "Running tests for version: ${{ matrix.version }}"
213+
poetry run pytest --cov infrahub_sdk tests/integration/
206214
- name: "Upload coverage to Codecov"
207215
run: |
208216
codecov --flags integration-tests

infrahub_sdk/testing/docker.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
1+
import os
2+
from typing import Optional
3+
14
import pytest
5+
from packaging.version import Version, InvalidVersion
6+
27
from infrahub_testcontainers.helpers import TestInfrahubDocker
38

49
from .. import Config, InfrahubClient, InfrahubClientSync
510

11+
DEFAULT_INFRAHUB_VERSION = "todo"
12+
INFRAHUB_VERSION = os.getenv("INFRAHUB_TESTING_IMAGE_TAG", DEFAULT_INFRAHUB_VERSION)
13+
14+
15+
def check_skip_version(min_infrahub_version: str | None = None, max_infrahub_version: str | None = None) -> bool:
16+
"""
17+
Check if a test should be skipped depending on infrahub version.
18+
"""
19+
try:
20+
version = Version(INFRAHUB_VERSION)
21+
except InvalidVersion:
22+
# We would typically end up here for development purpose while running a CI test against
23+
# unreleased versions of infrahub, like `stable` or `develop` branch.
24+
# For now, we consider this means we are testing against the most recent version of infrahub,
25+
# so we skip if the test should not be ran against a maximum version.
26+
if max_infrahub_version is None:
27+
return True
28+
29+
if min_infrahub_version is not None and version <= Version(min_infrahub_version):
30+
return True
31+
32+
if max_infrahub_version is not None and version <= Version(max_infrahub_version):
33+
return True
34+
35+
return False
36+
637

738
class TestInfrahubDockerClient(TestInfrahubDocker):
39+
40+
@staticmethod
41+
def _infrahub_version() -> str:
42+
raise INFRAHUB_VERSION
43+
844
@pytest.fixture(scope="class")
945
def client(self, infrahub_port: int) -> InfrahubClient:
1046
return InfrahubClient(

tests/integration/test_infrahub_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717

1818
class TestInfrahubNode(TestInfrahubDockerClient, SchemaAnimal):
19-
@pytest.fixture(scope="class")
20-
def infrahub_version(self) -> str:
21-
return "1.1.0"
19+
<<<<<<< Updated upstream
20+
=======
2221

22+
>>>>>>> Stashed changes
2323
@pytest.fixture(scope="class")
2424
async def base_dataset(
2525
self,

tests/integration/test_node.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212

1313
class TestInfrahubNode(TestInfrahubDockerClient, SchemaCarPerson):
14-
@pytest.fixture(scope="class")
15-
def infrahub_version(self) -> str:
16-
return "1.1.0"
14+
<<<<<<< Updated upstream
15+
=======
1716

17+
>>>>>>> Stashed changes
1818
@pytest.fixture(scope="class")
1919
async def initial_schema(self, default_branch: str, client: InfrahubClient, schema_base: SchemaRoot) -> None:
2020
await client.schema.wait_until_converged(branch=default_branch)

tests/integration/test_repository.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import TYPE_CHECKING
44

5-
import pytest
6-
75
from infrahub_sdk.testing.docker import TestInfrahubDockerClient
86
from infrahub_sdk.testing.repository import GitRepo
97
from infrahub_sdk.utils import get_fixtures_dir
@@ -13,10 +11,10 @@
1311

1412

1513
class TestInfrahubRepository(TestInfrahubDockerClient):
16-
@pytest.fixture(scope="class")
17-
def infrahub_version(self) -> str:
18-
return "1.1.0"
14+
<<<<<<< Updated upstream
15+
=======
1916

17+
>>>>>>> Stashed changes
2018
async def test_add_repository(self, client: InfrahubClient, remote_repos_dir):
2119
src_directory = get_fixtures_dir() / "integration/mock_repo"
2220
repo = GitRepo(name="mock_repo", src_directory=src_directory, dst_directory=remote_repos_dir)

0 commit comments

Comments
 (0)