Skip to content

Commit

Permalink
WIP: Run CI tests against multiple versions
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasG0 committed Jan 23, 2025
1 parent dbbe385 commit c4d94fa
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ jobs:
runs-on:
group: "huge-runners"
timeout-minutes: 30
strategy:
matrix:
version: ["1.0.0", "1.1.0"]
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
Expand All @@ -201,8 +204,13 @@ jobs:
pip install invoke toml codecov
- name: "Install Package"
run: "poetry install --all-extras"
- name: "Set environment variables for python_testcontainers"
run: |
echo INFRAHUB_TESTING_IMAGE_VER=${{ matrix.version }} >> $GITHUB_ENV
- name: "Integration Tests"
run: "poetry run pytest --cov infrahub_sdk tests/integration/"
run: |
echo "Running tests for version: ${{ matrix.version }}"
poetry run pytest --cov infrahub_sdk tests/integration/
- name: "Upload coverage to Codecov"
run: |
codecov --flags integration-tests
Expand Down
36 changes: 36 additions & 0 deletions infrahub_sdk/testing/docker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
import os
from typing import Optional

import pytest
from packaging.version import Version, InvalidVersion

from infrahub_testcontainers.helpers import TestInfrahubDocker

from .. import Config, InfrahubClient, InfrahubClientSync

DEFAULT_INFRAHUB_VERSION = "todo"
INFRAHUB_VERSION = os.getenv("INFRAHUB_TESTING_IMAGE_TAG", DEFAULT_INFRAHUB_VERSION)


def check_skip_version(min_infrahub_version: str | None = None, max_infrahub_version: str | None = None) -> bool:
"""
Check if a test should be skipped depending on infrahub version.
"""
try:
version = Version(INFRAHUB_VERSION)
except InvalidVersion:
# We would typically end up here for development purpose while running a CI test against
# unreleased versions of infrahub, like `stable` or `develop` branch.
# For now, we consider this means we are testing against the most recent version of infrahub,
# so we skip if the test should not be ran against a maximum version.
if max_infrahub_version is None:
return True

if min_infrahub_version is not None and version <= Version(min_infrahub_version):
return True

if max_infrahub_version is not None and version <= Version(max_infrahub_version):
return True

return False


class TestInfrahubDockerClient(TestInfrahubDocker):

@staticmethod
def _infrahub_version() -> str:
raise INFRAHUB_VERSION

@pytest.fixture(scope="class")
def client(self, infrahub_port: int) -> InfrahubClient:
return InfrahubClient(
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_infrahub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@


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

>>>>>>> Stashed changes
@pytest.fixture(scope="class")
async def base_dataset(
self,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@


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

>>>>>>> Stashed changes
@pytest.fixture(scope="class")
async def initial_schema(self, default_branch: str, client: InfrahubClient, schema_base: SchemaRoot) -> None:
await client.schema.wait_until_converged(branch=default_branch)
Expand Down
8 changes: 3 additions & 5 deletions tests/integration/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from typing import TYPE_CHECKING

import pytest

from infrahub_sdk.testing.docker import TestInfrahubDockerClient
from infrahub_sdk.testing.repository import GitRepo
from infrahub_sdk.utils import get_fixtures_dir
Expand All @@ -13,10 +11,10 @@


class TestInfrahubRepository(TestInfrahubDockerClient):
@pytest.fixture(scope="class")
def infrahub_version(self) -> str:
return "1.1.0"
<<<<<<< Updated upstream
=======

>>>>>>> Stashed changes
async def test_add_repository(self, client: InfrahubClient, remote_repos_dir):
src_directory = get_fixtures_dir() / "integration/mock_repo"
repo = GitRepo(name="mock_repo", src_directory=src_directory, dst_directory=remote_repos_dir)
Expand Down

0 comments on commit c4d94fa

Please sign in to comment.