mirror of
https://github.com/mozilla-services/syncstorage-rs.git
synced 2026-05-04 19:56:11 +02:00
Some checks failed
Checks / python-checks (push) Has been cancelled
Checks / rust-checks (push) Has been cancelled
Glean probe-scraper / glean-probe-scraper (push) Has been cancelled
Build, Tag and Push Container Images to GAR Repository / check (push) Has been cancelled
Build, Tag and Push Container Images to GAR Repository / build-and-push-syncstorage-rs (push) Has been cancelled
Build, Tag and Push Container Images to GAR Repository / build-and-push-syncserver-postgres (push) Has been cancelled
Build, Tag and Push Container Images to GAR Repository / build-and-push-syncserver-postgres-enterprise-gar (push) Has been cancelled
Build, Tag and Push Container Images to GAR Repository / build-and-push-syncstorage-rs-spanner-python-utils (push) Has been cancelled
Build, Tag and Push Container Images to GAR Repository / build-and-push-syncserver-postgres-python-utils (push) Has been cancelled
Build, Tag and Push Container Images to GAR Repository / build-and-push-syncserver-postgres-python-utils-enterprise-gar (push) Has been cancelled
Build, Tag and Push Container Images to GAR Repository / build-and-push-syncserver-mysql (push) Has been cancelled
MySQL Build and Test / build-and-test-mysql (push) Has been cancelled
MySQL Build and Test / build-mysql-image (push) Has been cancelled
MySQL Build and Test / mysql-e2e-tests (push) Has been cancelled
Postgres Build and Test / build-and-test-postgres (push) Has been cancelled
Postgres Build and Test / build-postgres-image (push) Has been cancelled
Postgres Build and Test / postgres-e2e-tests (push) Has been cancelled
Publish Sync docs to pages / build-mdbook (push) Has been cancelled
Publish Sync docs to pages / build-openapi (push) Has been cancelled
Publish Sync docs to pages / combine-and-prepare (push) Has been cancelled
Publish Sync docs to pages / deploy (push) Has been cancelled
Spanner Build, Test, and Push / build-and-test-spanner (push) Has been cancelled
Spanner Build, Test, and Push / build-spanner-image (push) Has been cancelled
Spanner Build, Test, and Push / spanner-e2e-tests (push) Has been cancelled
chore: upgrade Python for all utils and refactor
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
import pytest
|
|
|
|
from tools.spanner.utils import ids_from_env
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def reset_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""Reset Spanner-related environment variables before each test."""
|
|
for var in [
|
|
"SYNC_SYNCSTORAGE__DATABASE_URL",
|
|
"INSTANCE_ID",
|
|
"DATABASE_ID",
|
|
"GOOGLE_CLOUD_PROJECT",
|
|
]:
|
|
monkeypatch.delenv(var, raising=False)
|
|
|
|
|
|
def test_ids_from_env_parses_url(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""Test with passed in DSN"""
|
|
monkeypatch.setenv(
|
|
"SYNC_SYNCSTORAGE__DATABASE_URL",
|
|
"spanner://projects/proj/instances/inst/databases/db",
|
|
)
|
|
dsn = "SYNC_SYNCSTORAGE__DATABASE_URL"
|
|
instance_id, database_id, project_id = ids_from_env(dsn)
|
|
assert project_id == "proj"
|
|
assert instance_id == "inst"
|
|
assert database_id == "db"
|
|
|
|
|
|
def test_ids_from_env_with_missing_url(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""Test ensures that default env vars set id values."""
|
|
monkeypatch.setenv("INSTANCE_ID", "foo")
|
|
monkeypatch.setenv("DATABASE_ID", "bar")
|
|
monkeypatch.setenv("GOOGLE_CLOUD_PROJECT", "baz")
|
|
instance_id, database_id, project_id = ids_from_env()
|
|
assert instance_id == "foo"
|
|
assert database_id == "bar"
|
|
assert project_id == "baz"
|
|
|
|
|
|
def test_from_env_with_invalid_url(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""A non-spanner URL scheme falls through to the env-var fallbacks."""
|
|
monkeypatch.setenv("SYNC_SYNCSTORAGE__DATABASE_URL", "notaspanner://foo")
|
|
monkeypatch.setenv("INSTANCE_ID", "default")
|
|
monkeypatch.setenv("DATABASE_ID", "default-db")
|
|
monkeypatch.setenv("GOOGLE_CLOUD_PROJECT", "default-proj")
|
|
|
|
instance_id, database_id, project_id = ids_from_env()
|
|
assert instance_id == "default"
|
|
assert database_id == "default-db"
|
|
assert project_id == "default-proj"
|