Skip to content

Commit

Permalink
Add itde package and tool for starting test db
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti committed Apr 22, 2024
1 parent bb23ca6 commit 51f06a9
Show file tree
Hide file tree
Showing 4 changed files with 1,360 additions and 236 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ build/
.vscode

.DS_Store

.build_output/
51 changes: 46 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from pathlib import Path
from typing import Iterable
from contextlib import contextmanager
import nox
from nox import Session

Expand All @@ -9,7 +10,7 @@
"integration_tests",
]

_ROOT : Path = Path(__file__).parent
_ROOT: Path = Path(__file__).parent


def _test_command(path: Path) -> Iterable[str]:
Expand All @@ -28,6 +29,41 @@ def _integration_tests(session: Session) -> None:
session.run(*command)


@contextmanager
def test_db(session: Session, db_version: str, port: int):
with_db = db_version not in ["", None]

def nop():
pass

def start_db():
session.run(
"itde",
"spawn-test-environment",
"--environment-name",
"test",
"--database-port-forward",
f"{port}",
"--bucketfs-port-forward",
"2580",
"--docker-db-image-version",
db_version,
"--db-mem-size",
"4GB",
external=True,
)

def stop_db():
session.run("docker", "kill", "db_container_test", external=True)

start = start_db if with_db else nop
stop = stop_db if with_db else nop

start()
yield
stop()


@nox.session(name="unit-tests", python=False)
def unit_tests(session: Session) -> None:
"""Runs all unit tests"""
Expand All @@ -36,12 +72,17 @@ def unit_tests(session: Session) -> None:

@nox.session(name="integration-tests", python=False)
def integration_tests(session: Session) -> None:
"""Runs the all integration tests"""
_integration_tests(session)
"""Runs the all integration tests
Args:
db_version: version to start, if none no db will be started.
"""
with test_db(session, db_version="7.1.17", port=8263):
_integration_tests(session)


@nox.session(name="all-tests", python=False)
@ nox.session(name="all-tests", python=False)
def all_tests(session: Session) -> None:
"""Runs all tests (Unit and Integration)"""
command = _test_command(_ROOT / "test")
command=_test_command(_ROOT / "test")
session.run(*command)
Loading

0 comments on commit 51f06a9

Please sign in to comment.