Skip to content

Commit 657576d

Browse files
authored
feat: support for Google AlloyDB Omni
feat: support for Google AlloyDB Omni
2 parents 6ff81e9 + 63a883d commit 657576d

File tree

5 files changed

+251
-7
lines changed

5 files changed

+251
-7
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Reusable test fixtures for any and all databases.
1717
| Project | | Status |
1818
|-----------|:----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1919
| CI/CD | | [![Latest Release](https://github.com/litestar-org/pytest-databases/actions/workflows/publish.yml/badge.svg)](https://github.com/litestar-org/pytest-databases/actions/workflows/publish.yml) [![ci](https://github.com/litestar-org/pytest-databases/actions/workflows/ci.yml/badge.svg)](https://github.com/litestar-org/pytest-databases/actions/workflows/ci.yml) [![Documentation Building](https://github.com/litestar-org/pytest-databases/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/litestar-org/pytest-databases/actions/workflows/docs.yml) |
20-
| Quality | | [![Coverage](https://codecov.io/github/litestar-org/pytest-databases/graph/badge.svg?token=vKez4Pycrc)](https://codecov.io/github/litestar-org/pytest-databases) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_litestar&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=litestar-org_litestar) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_litestar&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_litestar) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_litestar&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_litestar) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_litestar&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_litestar) |
21-
| Package | | [![PyPI - Version](https://img.shields.io/pypi/v/litestar?labelColor=202235&color=edb641&logo=python&logoColor=edb641)](https://badge.fury.io/py/litestar) ![PyPI - Support Python Versions](https://img.shields.io/pypi/pyversions/litestar?labelColor=202235&color=edb641&logo=python&logoColor=edb641) ![Starlite PyPI - Downloads](https://img.shields.io/pypi/dm/starlite?logo=python&label=starlite%20downloads&labelColor=202235&color=edb641&logoColor=edb641) ![Litestar PyPI - Downloads](https://img.shields.io/pypi/dm/litestar?logo=python&label=litestar%20downloads&labelColor=202235&color=edb641&logoColor=edb641) |
20+
| Quality | | [![Coverage](https://codecov.io/github/litestar-org/pytest-databases/graph/badge.svg?token=vKez4Pycrc)](https://codecov.io/github/litestar-org/pytest-databases) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_pytest_databases&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=litestar-org_pytest_databases) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_pytest_databases&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_pytest_databases) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_pytest_databases&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_pytest_databases) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_pytest_databases&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_pytest_databases) |
21+
| Package | | [![PyPI - Version](https://img.shields.io/pypi/v/pytest-databases?labelColor=202235&color=edb641&logo=python&logoColor=edb641)](https://badge.fury.io/py/pytest-databases) ![PyPI - Support Python Versions](https://img.shields.io/pypi/pyversions/pytest-databases?labelColor=202235&color=edb641&logo=python&logoColor=edb641) |
2222
| Community | | [![Reddit](https://img.shields.io/reddit/subreddit-subscribers/litestarapi?label=r%2FLitestar&logo=reddit&labelColor=202235&color=edb641&logoColor=edb641)](https://reddit.com/r/litestarapi) [![Discord](https://img.shields.io/discord/919193495116337154?labelColor=202235&color=edb641&label=chat%20on%20discord&logo=discord&logoColor=edb641)](https://discord.gg/litestar-919193495116337154) [![Matrix](https://img.shields.io/badge/chat%20on%20Matrix-bridged-202235?labelColor=202235&color=edb641&logo=matrix&logoColor=edb641)](https://matrix.to/#/#litestar:matrix.org) [![Medium](https://img.shields.io/badge/Medium-202235?labelColor=202235&color=edb641&logo=medium&logoColor=edb641)](https://blog.litestar.dev) [![Twitter](https://img.shields.io/twitter/follow/LitestarAPI?labelColor=202235&color=edb641&logo=twitter&logoColor=edb641&style=flat)](https://twitter.com/LitestarAPI) [![Blog](https://img.shields.io/badge/Blog-litestar.dev-202235?logo=blogger&labelColor=202235&color=edb641&logoColor=edb641)](https://blog.litestar.dev) |
2323
| Meta | | [![Litestar Project](https://img.shields.io/badge/Litestar%20Org-%E2%AD%90%20Litestar-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://github.com/litestar-org/pytest-databases) [![types - Mypy](https://img.shields.io/badge/types-Mypy-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://github.com/python/mypy) [![License - MIT](https://img.shields.io/badge/license-MIT-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://spdx.org/licenses/) [![Litestar Sponsors](https://img.shields.io/badge/Sponsor-%E2%9D%A4-%23edb641.svg?&logo=github&logoColor=edb641&labelColor=202235)](https://github.com/sponsors/litestar-org) [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json&labelColor=202235)](https://github.com/astral-sh/ruff) [![code style - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json&labelColor=202235)](https://github.com/psf/black)|
2424

@@ -44,7 +44,8 @@ It is designed to offer pre-configured testing setups for many different types a
4444
- **MySQL**: Version 5.6, 5.7 and 8 are available
4545
- **Oracle**: Version 18c XE and 23C Free are available
4646
- **SQL Server**: Version 2022 is available
47-
- **Spanner**: The latest cloud-emulator from Google is available
47+
- **Google AlloyDB Omni**: Simplified Omni installation for easy testing.
48+
- **Google Spanner**: The latest cloud-emulator from Google is available
4849
- **Cockroach**: Version 23.1-latest is available
4950
- **Redis**: Latest server
5051
- **Dragonfly**: Latest server

pyproject.toml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ keywords = [
2525
"duckdb",
2626
"bigquery",
2727
"spanner",
28+
"alloydb",
29+
"alloydbomni",
2830
"cockroachdb",
2931
"redis",
3032
"elasticsearch",
@@ -104,7 +106,18 @@ extra-dependencies = [
104106
"pytest-click",
105107
"pytest-xdist",
106108
]
107-
features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "spanner", "redis", "elasticsearch7", "elasticsearch8"]
109+
features = [
110+
"oracle",
111+
"mysql",
112+
"mssql",
113+
"postgres",
114+
"spanner",
115+
"cockroachdb",
116+
"spanner",
117+
"redis",
118+
"elasticsearch7",
119+
"elasticsearch8",
120+
]
108121
template = "default"
109122
type = "virtual"
110123

@@ -150,7 +163,18 @@ extra-dependencies = [
150163
"sphinxcontrib-mermaid>=0.9.2",
151164
"auto-pytabs[sphinx]>=0.4.0",
152165
]
153-
features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "spanner", "redis", "elasticsearch7", "elasticsearch8"]
166+
features = [
167+
"oracle",
168+
"mysql",
169+
"mssql",
170+
"postgres",
171+
"spanner",
172+
"cockroachdb",
173+
"spanner",
174+
"redis",
175+
"elasticsearch7",
176+
"elasticsearch8",
177+
]
154178
lock-filename = "requirements/requirements-docs.txt"
155179
pip-compile-constraint = "default"
156180
python = "3.11"
@@ -211,7 +235,17 @@ extra-dependencies = [
211235
"types-docutils",
212236
"types-redis",
213237
]
214-
features = ["oracle", "mysql", "mssql", "postgres", "cockroachdb", "spanner", "redis", "elasticsearch7", "elasticsearch8"]
238+
features = [
239+
"oracle",
240+
"mysql",
241+
"mssql",
242+
"postgres",
243+
"cockroachdb",
244+
"spanner",
245+
"redis",
246+
"elasticsearch7",
247+
"elasticsearch8",
248+
]
215249
lock-filename = "requirements/requirements-dev.txt"
216250
path = ".venv/"
217251
pip-compile-constraint = "docs"
@@ -239,7 +273,17 @@ extra-dependencies = [
239273
"types-docutils",
240274
"types-redis",
241275
]
242-
features = ["oracle", "mysql", "mssql", "postgres", "spanner", "cockroachdb", "redis", "elasticsearch7", "elasticsearch8"]
276+
features = [
277+
"oracle",
278+
"mysql",
279+
"mssql",
280+
"postgres",
281+
"spanner",
282+
"cockroachdb",
283+
"redis",
284+
"elasticsearch7",
285+
"elasticsearch8",
286+
]
243287
python = "3.11"
244288
template = "docs"
245289

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# MIT License
2+
3+
# Copyright (c) 2024 Litestar
4+
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
24+
from __future__ import annotations
25+
26+
import os
27+
from pathlib import Path
28+
from typing import TYPE_CHECKING
29+
30+
import asyncpg
31+
import pytest
32+
33+
if TYPE_CHECKING:
34+
from pytest_databases.docker import DockerServiceRegistry
35+
36+
37+
async def alloydb_omni_responsive(host: str, port: int, user: str, password: str, database: str) -> bool:
38+
try:
39+
conn = await asyncpg.connect(
40+
host=host,
41+
port=port,
42+
user=user,
43+
database=database,
44+
password=password,
45+
)
46+
except Exception: # noqa: BLE001
47+
return False
48+
49+
try:
50+
db_open = await conn.fetchrow("SELECT 1")
51+
return bool(db_open is not None and db_open[0] == 1)
52+
finally:
53+
await conn.close()
54+
55+
56+
@pytest.fixture()
57+
def postgres_user() -> str:
58+
return "postgres"
59+
60+
61+
@pytest.fixture()
62+
def postgres_password() -> str:
63+
return "super-secret"
64+
65+
66+
@pytest.fixture()
67+
def postgres_database() -> str:
68+
return "postgres"
69+
70+
71+
@pytest.fixture()
72+
def alloydb_omni_port() -> int:
73+
return 5420
74+
75+
76+
@pytest.fixture()
77+
def default_alloydb_omni_service_name() -> str:
78+
return "alloydb"
79+
80+
81+
@pytest.fixture(scope="session")
82+
def docker_compose_files() -> list[Path]:
83+
return [Path(Path(__file__).parent / "docker-compose.alloydb-omni.yml")]
84+
85+
86+
# alias to the latest
87+
@pytest.fixture(autouse=False)
88+
async def alloydb_omni_service(
89+
docker_services: DockerServiceRegistry,
90+
default_alloydb_omni_service_name: str,
91+
docker_compose_files: list[Path],
92+
postgres_port: int,
93+
postgres_database: str,
94+
postgres_user: str,
95+
postgres_password: str,
96+
) -> None:
97+
os.environ["POSTGRES_PASSWORD"] = postgres_password
98+
os.environ["POSTGRES_USER"] = postgres_user
99+
os.environ["POSTGRES_DATABASE"] = postgres_database
100+
os.environ[f"{default_alloydb_omni_service_name.upper()}_PORT"] = str(postgres_port)
101+
await docker_services.start(
102+
name=default_alloydb_omni_service_name,
103+
docker_compose_files=docker_compose_files,
104+
timeout=45,
105+
pause=1,
106+
check=alloydb_omni_responsive,
107+
port=postgres_port,
108+
database=postgres_database,
109+
user=postgres_user,
110+
password=postgres_password,
111+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
alloydb:
3+
networks:
4+
- default
5+
image: google/alloydbomni
6+
ulimits:
7+
memlock: -1
8+
ports:
9+
- "${ALLOYDB_PORT:-5420}:5432" # use a non-standard port here
10+
# For better performance, consider `host` mode instead `port` to avoid docker NAT.
11+
# `host` mode is NOT currently supported in Swarm Mode.
12+
# https://docs.docker.com/compose/compose-file/compose-file-v3/#network_mode
13+
# network_mode: "host"
14+
environment:
15+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret}
16+
networks:
17+
default:
18+
driver: bridge

tests/docker/test_alloydb_omni.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# MIT License
2+
3+
# Copyright (c) 2024 Litestar
4+
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from __future__ import annotations
24+
25+
from typing import TYPE_CHECKING
26+
27+
import pytest
28+
29+
from pytest_databases.docker.alloydb_omni import alloydb_omni_responsive
30+
31+
if TYPE_CHECKING:
32+
from pytest_databases.docker import DockerServiceRegistry
33+
34+
pytestmark = pytest.mark.anyio
35+
pytest_plugins = [
36+
"pytest_databases.docker.alloydb_omni",
37+
]
38+
39+
40+
async def test_alloydb_omni_default_config(
41+
default_alloydb_omni_service_name: str,
42+
alloydb_omni_port: int,
43+
postgres_database: str,
44+
postgres_user: str,
45+
postgres_password: str,
46+
) -> None:
47+
assert default_alloydb_omni_service_name == "alloydb"
48+
assert alloydb_omni_port == 5420
49+
assert postgres_database == "postgres"
50+
assert postgres_user == "postgres"
51+
assert postgres_password == "super-secret"
52+
53+
54+
@pytest.mark.xfail
55+
async def test_alloydb_omni_services(
56+
docker_ip: str,
57+
alloydb_omni_service: DockerServiceRegistry,
58+
alloydb_omni_port: int,
59+
postgres_database: str,
60+
postgres_user: str,
61+
postgres_password: str,
62+
) -> None:
63+
ping = await alloydb_omni_responsive(
64+
docker_ip,
65+
port=alloydb_omni_port,
66+
database=postgres_database,
67+
user=postgres_user,
68+
password=postgres_password,
69+
)
70+
assert ping

0 commit comments

Comments
 (0)