Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions .github/workflows/workflow-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,45 @@ jobs:
sync: ${{ steps.changes.outputs.sync_all }}
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
uses: "actions/checkout@v5"
- name: Check for file changes
uses: dorny/paths-filter@v3
id: changes
with:
token: ${{ github.token }}
filters: .github/file-filters.yml

# TODO: Create the unit tests...
# unit-tests:
# name: Unit Tests (py${{ matrix.python-version }})
# strategy:
# matrix:
# python-version:
# - "3.9"
# - "3.10"
# - "3.11"
# - "3.12"
# if: needs.files-changed.outputs.sync == 'true'
# runs-on: ubuntu-latest
# timeout-minutes: 30
# defaults:
# run:
# working-directory: sync/
# steps:
# - name: "Check out repository code"
# uses: "actions/checkout@v4"
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}
# - name: "Setup environment"
# run: |
# pipx install poetry
# poetry config virtualenvs.prefer-active-python true
# pip install toml invoke
# - name: "Install Package"
# run: "poetry install"
# - name: "markdownlint-cli2, ruff, and pylint Tests"
# run: "poetry run invoke tests.tests-unit"
unit-tests:
name: "Unit Tests (py${{ matrix.python-version }})"
needs: ["files-changed"]
if: needs.files-changed.outputs.sync == 'true'
runs-on: "ubuntu-22.04"
timeout-minutes: 15
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v5"

- name: "Install uv"
uses: "astral-sh/setup-uv@v4"
with:
version: "latest"

- name: "Set up Python ${{ matrix.python-version }}"
run: uv python install ${{ matrix.python-version }}

- name: "Install dependencies"
run: uv sync --frozen --extra dev

# Runs only `-m "not integration"`. Integration tests need a live
# Infrahub instance and are opted into via `invoke tests-integration`
# (run locally; not gated here yet — TODO: add Infrahub service
# container or compose stack and a separate integration-tests job).
- name: "pytest: unit tests"
run: uv run invoke tests.tests-unit
10 changes: 8 additions & 2 deletions infrahub_sync/adapters/infrahub.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,17 @@ def infrahub_node_to_diffsync(self, node: InfrahubNodeSync) -> dict[str, Any]:
if has_field(config=self.config, name=node._schema.kind, field=attr_name):
attr = getattr(node, attr_name)
val = attr.value
# Convert IP types and other non-string values to strings for DiffSync models
# IP types come back from the Infrahub SDK as ipaddress
# objects; DiffSync models store them as their string form
# (e.g. "10.0.0.1/32"), so normalise here. Other non-string
# kinds — List, Number, Boolean, DateTime — pass through
# unchanged: stringifying them turns a real list `[]` into
# the four-character literal `"[]"`, which then fails
# Pydantic validation on `list[str]`-typed fields.
if isinstance(
val,
(ipaddress.IPv4Interface, ipaddress.IPv6Interface, ipaddress.IPv4Network, ipaddress.IPv6Network),
) or (val is not None and not isinstance(val, str)):
):
data[attr_name] = str(val)
else:
data[attr_name] = val
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ asyncio_mode = "auto"
testpaths = [
"tests"
]
markers = [
"integration: tests that require a running Infrahub instance. Skipped by default; opt in with -m integration and INFRAHUB_ADDRESS + INFRAHUB_API_TOKEN set.",
]
filterwarnings = [
"ignore:Module already imported so cannot be rewritten",
"ignore:the imp module is deprecated",
Expand Down
12 changes: 10 additions & 2 deletions tasks/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@

@task
def tests_unit(context: Context) -> None:
pass
"""Run unit tests — everything under tests/ except integration-marked tests."""
with context.cd(MAIN_DIRECTORY):
context.run('pytest -m "not integration"', pty=True)


@task
def tests_integration(context: Context) -> None:
pass
"""Run integration tests against a live Infrahub.

Requires INFRAHUB_ADDRESS and INFRAHUB_API_TOKEN in the environment;
tests skip themselves when those aren't set.
"""
with context.cd(MAIN_DIRECTORY):
context.run("pytest -m integration", pty=True)
Loading
Loading