4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
105 lines
3.7 KiB
Python
105 lines
3.7 KiB
Python
"""Tests for PostgreSQLReplicationStatusTool (function-based, @tool decorated)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
from integrations.postgresql.tools.postgresql_replication_status_tool import (
|
|
get_postgresql_replication_status,
|
|
)
|
|
from tests.tools.conftest import BaseToolContract
|
|
|
|
|
|
class TestPostgreSQLReplicationStatusToolContract(BaseToolContract):
|
|
def get_tool_under_test(self):
|
|
return get_postgresql_replication_status.__opensre_registered_tool__
|
|
|
|
|
|
def test_metadata() -> None:
|
|
rt = get_postgresql_replication_status.__opensre_registered_tool__
|
|
assert rt.name == "get_postgresql_replication_status"
|
|
assert rt.source == "postgresql"
|
|
|
|
|
|
def test_run_happy_path_with_replicas() -> None:
|
|
fake_result = {
|
|
"source": "postgresql",
|
|
"available": True,
|
|
"is_primary": True,
|
|
"current_wal_lsn": "1/A2B3C4D5",
|
|
"replica_count": 2,
|
|
"replicas": [
|
|
{
|
|
"pid": 23456,
|
|
"username": "replica_user",
|
|
"application_name": "replica_1",
|
|
"client_addr": "10.0.1.100",
|
|
"client_hostname": "replica-1.internal",
|
|
"state": "streaming",
|
|
"sent_lsn": "1/A2B3C4D5",
|
|
"write_lsn": "1/A2B3C4D4",
|
|
"flush_lsn": "1/A2B3C4D3",
|
|
"replay_lsn": "1/A2B3C4D3",
|
|
"write_lag": "00:00:00.001",
|
|
"flush_lag": "00:00:00.002",
|
|
"replay_lag": "00:00:00.003",
|
|
"sync_state": "async",
|
|
},
|
|
{
|
|
"pid": 23457,
|
|
"username": "replica_user",
|
|
"application_name": "replica_2",
|
|
"client_addr": "10.0.1.101",
|
|
"client_hostname": "replica-2.internal",
|
|
"state": "streaming",
|
|
"sent_lsn": "1/A2B3C4D5",
|
|
"write_lsn": "1/A2B3C4D5",
|
|
"flush_lsn": "1/A2B3C4D5",
|
|
"replay_lsn": "1/A2B3C4D5",
|
|
"write_lag": "",
|
|
"flush_lag": "",
|
|
"replay_lag": "",
|
|
"sync_state": "sync",
|
|
},
|
|
],
|
|
}
|
|
with patch(
|
|
"integrations.postgresql.tools.postgresql_replication_status_tool.get_replication_status",
|
|
return_value=fake_result,
|
|
):
|
|
result = get_postgresql_replication_status(host="localhost", database="testdb")
|
|
assert result["is_primary"] is True
|
|
assert result["replica_count"] == 2
|
|
assert result["current_wal_lsn"] == "1/A2B3C4D5"
|
|
assert len(result["replicas"]) == 2
|
|
assert result["replicas"][1]["sync_state"] == "sync"
|
|
|
|
|
|
def test_run_happy_path_no_replicas() -> None:
|
|
fake_result = {
|
|
"source": "postgresql",
|
|
"available": True,
|
|
"is_primary": True,
|
|
"current_wal_lsn": "1/A2B3C4D5",
|
|
"replicas": [],
|
|
"note": "Server is a primary but has no active replicas.",
|
|
}
|
|
with patch(
|
|
"integrations.postgresql.tools.postgresql_replication_status_tool.get_replication_status",
|
|
return_value=fake_result,
|
|
):
|
|
result = get_postgresql_replication_status(host="localhost", database="testdb")
|
|
assert result["is_primary"] is True
|
|
assert len(result["replicas"]) == 0
|
|
assert "note" in result
|
|
|
|
|
|
def test_run_error_propagated() -> None:
|
|
with patch(
|
|
"integrations.postgresql.tools.postgresql_replication_status_tool.get_replication_status",
|
|
return_value={"source": "postgresql", "available": False, "error": "access denied"},
|
|
):
|
|
result = get_postgresql_replication_status(host="invalid", database="testdb")
|
|
assert "error" in result
|
|
assert result["available"] is False
|