-
Notifications
You must be signed in to change notification settings - Fork 4
Add podman support #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,99 @@ | ||
| name: Run tests | ||
| name: Run parallel tests | ||
|
|
||
| on: ["push", "pull_request"] | ||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| docker-tests: | ||
| name: Docker Tests / Python ${{ matrix.python-version }} | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| test: | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install hatch | ||
| - name: Install Docker CE | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y \ | ||
| ca-certificates \ | ||
| curl \ | ||
| gnupg \ | ||
| lsb-release | ||
| sudo mkdir -p /etc/apt/keyrings | ||
| curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | ||
| echo \ | ||
| "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | ||
| $(lsb_release -cs) stable" | \ | ||
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | ||
| sudo apt-get update | ||
| sudo apt-get install -y docker-ce docker-ce-cli containerd.io | ||
| sudo systemctl start docker | ||
| docker --version | ||
| - name: Run Docker scenario tests | ||
| run: | | ||
| hatch run ci -- dbtesttools.tests.test_pgfixture_docker dbtesttools.tests.test_isolation | ||
| podman-tests: | ||
| name: Podman Tests / Python ${{ matrix.python-version }} | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
| python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install hatch | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install hatch | ||
| - name: Install Podman | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y podman | ||
| podman --version | ||
| - name: Run tests | ||
| run: | | ||
| hatch run ci | ||
| - name: Start Podman API (rootless) | ||
| run: | | ||
| export XDG_RUNTIME_DIR="/run/user/$(id -u)" | ||
| sudo mkdir -p "$XDG_RUNTIME_DIR" | ||
| sudo chown $(id -u):$(id -g) "$XDG_RUNTIME_DIR" | ||
| mkdir -p "$XDG_RUNTIME_DIR" | ||
| nohup podman system service --time=0 unix://$XDG_RUNTIME_DIR/podman/podman.sock > podman-api.log 2>&1 & | ||
| echo "Waiting for podman.sock..." | ||
| for i in {1..10}; do | ||
| if podman info > /dev/null 2>&1; then | ||
| echo "Podman is up" | ||
| break | ||
| fi | ||
| sleep 2 | ||
| done | ||
| cat podman-api.log | ||
| if ! podman info > /dev/null 2>&1; then | ||
| echo "::error ::Podman API service failed to start" | ||
| cat podman-api.log | ||
| exit 1 | ||
| fi | ||
| - name: Run Podman scenario tests | ||
| run: | | ||
| hatch run ci -- dbtesttools.tests.test_pgfixture_podman dbtesttools.tests.test_isolation | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import os | ||
| import unittest | ||
| import warnings | ||
|
|
||
| import testscenarios | ||
| import testtools | ||
| from sqlalchemy import text | ||
|
|
||
| from dbtesttools.engines.postgres import PostgresContainerFixture | ||
|
|
||
| warnings.filterwarnings("ignore", category=UserWarning, module="urllib3") | ||
|
|
||
|
|
||
| class TestPostgresContainer( | ||
| testscenarios.TestWithScenarios, testtools.TestCase | ||
| ): | ||
| """Test that we can bring up a Postgres container.""" | ||
|
|
||
| scenarios = [ | ||
| ("docker", {"podman": False}), | ||
| ("podman", {"podman": True}), | ||
| ] | ||
|
|
||
| def setUp(self): | ||
depatl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.pg_fixture = None | ||
| super().setUp() | ||
| if self.podman: | ||
| os.environ["DBTESTTOOLS_USE_PODMAN"] = "1" | ||
| else: | ||
| os.environ.pop("DBTESTTOOLS_USE_PODMAN", None) | ||
| try: | ||
| fixture = PostgresContainerFixture(future=True) | ||
| fixture.setUp() | ||
| self.pg_fixture = fixture | ||
| except Exception as e: | ||
| print(f'[ERROR] Failed to start Postgres fixture: {e}') | ||
|
|
||
| def tearDown(self): | ||
| if self.pg_fixture is not None: | ||
| if hasattr(self.pg_fixture, "engine"): | ||
| try: | ||
| self.pg_fixture.engine.dispose() | ||
| except Exception as e: | ||
| print(f"Warning: failed to dispose engine: {e}") | ||
depatl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if hasattr(self.pg_fixture, "container"): | ||
| try: | ||
| self.pg_fixture.container.kill() | ||
| except Exception as e: | ||
| print(f"Warning: failed to kill container: {e}") | ||
| super().tearDown() | ||
|
|
||
| def test_connection(self): | ||
| if self.pg_fixture is None: | ||
| self.fail("Postgres fixture was not initialized") | ||
| # Actually test that the database is reachable | ||
| conn = self.pg_fixture.connect() | ||
| try: | ||
| result = conn.execute(text("SELECT 1;")) | ||
| value = result.scalar() | ||
| self.assertEqual(value, 1) | ||
| finally: | ||
| conn.close() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from .test_pgfixture import TestPostgresContainer | ||
|
|
||
| # Override the scenarios to only run Docker | ||
| TestPostgresContainer.scenarios = [ | ||
| ("docker", {"podman": False}), | ||
| ] | ||
|
|
||
| # Optional: re-export the test class to make unittest discovery happy | ||
| __all__ = ["TestPostgresContainer"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from .test_pgfixture import TestPostgresContainer | ||
|
|
||
| # Override the scenarios to only run Podman | ||
| TestPostgresContainer.scenarios = [ | ||
| ("podman", {"podman": True}), | ||
| ] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why you're doing this, and the previous change. The scenarios declaration will run both of these automatically. This change means that the last file to to get imported overrides the scenarios as well, so for example on my machine the only scenario that gets run now is podman. When running In other words, we should not depend on GH Actions to run all of our tests to completion. Let's go back to basics with this change and simply run up a worker with podman installed. See here https://github.com/marketplace/actions/install-podman for one in the marketplace. I don't think you need all that docker-ce stuff as well, was there a reason to do it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah apparently that podman action is deprecated, crap. Back to manual installation. |
||
|
|
||
| # Optional: re-export the test class to make unittest discovery happy | ||
| __all__ = ["TestPostgresContainer"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on curl here is very bad, it means the tests won't pass if that site is down or something similar is broken.