Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

115 lines
3.8 KiB
Python

"""Tests for integrations/selectors.py."""
from __future__ import annotations
from integrations.selectors import (
get_default_instance,
get_instance_by_name,
get_instances,
get_instances_by_tag,
select_instance,
)
def _resolved_single() -> dict:
return {
"grafana": {"endpoint": "https://x", "api_key": "k", "integration_id": "g1"},
}
def _resolved_multi() -> dict:
return {
"grafana": {"endpoint": "https://prod", "api_key": "kp", "integration_id": "env-grafana"},
"_all_grafana_instances": [
{
"name": "prod",
"tags": {"env": "prod", "region": "us-east-1"},
"config": {"endpoint": "https://prod", "api_key": "kp"},
"integration_id": "env-grafana",
},
{
"name": "staging",
"tags": {"env": "staging", "region": "us-west-2"},
"config": {"endpoint": "https://staging", "api_key": "ks"},
"integration_id": "env-grafana",
},
],
}
def test_get_instances_returns_empty_when_service_absent() -> None:
assert get_instances({}, "grafana") == []
assert get_instances(None, "grafana") == []
def test_get_instances_returns_list_when_present() -> None:
instances = get_instances(_resolved_multi(), "grafana")
assert [i["name"] for i in instances] == ["prod", "staging"]
def test_get_instances_synthesizes_single_entry_when_only_flat_shape() -> None:
instances = get_instances(_resolved_single(), "grafana")
assert len(instances) == 1
assert instances[0]["name"] == "default"
assert instances[0]["config"]["api_key"] == "k"
def test_get_default_instance_returns_flat_shape() -> None:
assert get_default_instance(_resolved_multi(), "grafana") == {
"endpoint": "https://prod",
"api_key": "kp",
"integration_id": "env-grafana",
}
def test_get_default_instance_none_when_service_absent() -> None:
assert get_default_instance({}, "grafana") is None
def test_get_instance_by_name_returns_matching_config() -> None:
config = get_instance_by_name(_resolved_multi(), "grafana", "staging")
assert config is not None
assert config["endpoint"] == "https://staging"
def test_get_instance_by_name_returns_none_when_unknown() -> None:
assert get_instance_by_name(_resolved_multi(), "grafana", "unknown") is None
def test_get_instance_by_name_empty_name_returns_none() -> None:
assert get_instance_by_name(_resolved_multi(), "grafana", "") is None
def test_get_instances_by_tag_matches_single_kv() -> None:
results = get_instances_by_tag(_resolved_multi(), "grafana", "env", "staging")
assert len(results) == 1
assert results[0]["endpoint"] == "https://staging"
def test_get_instances_by_tag_returns_empty_when_no_match() -> None:
assert get_instances_by_tag(_resolved_multi(), "grafana", "env", "qa") == []
def test_select_instance_prefers_name_over_tags_when_both_given() -> None:
# name="prod" matches; tags={"env":"staging"} would not — name wins
config = select_instance(_resolved_multi(), "grafana", name="prod", tags={"env": "staging"})
assert config is not None
assert config["endpoint"] == "https://prod"
def test_select_instance_with_no_filters_returns_default() -> None:
config = select_instance(_resolved_multi(), "grafana")
assert config is not None
assert config["endpoint"] == "https://prod" # first/default
def test_select_instance_by_tags_only() -> None:
config = select_instance(_resolved_multi(), "grafana", tags={"env": "staging"})
assert config is not None
assert config["endpoint"] == "https://staging"
def test_select_instance_by_name_no_match_returns_none() -> None:
# Per docstring: name-based lookup doesn't silently fall back
assert select_instance(_resolved_multi(), "grafana", name="nope") is None