Files
tracer-cloud--opensre/tests/tools/test_eks_list_clusters_tool.py
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

87 lines
3.4 KiB
Python

"""Tests for EKSListClustersTool (function-based, @tool decorated)."""
from __future__ import annotations
from unittest.mock import MagicMock, patch
from botocore.exceptions import ClientError
from integrations.eks.tools import list_eks_clusters
from tests.tools.conftest import BaseToolContract, mock_agent_state
class TestEKSListClustersToolContract(BaseToolContract):
def get_tool_under_test(self):
return list_eks_clusters.__opensre_registered_tool__
def test_is_available_requires_connection_verified() -> None:
rt = list_eks_clusters.__opensre_registered_tool__
assert rt.is_available({"eks": {"connection_verified": True}}) is True
assert rt.is_available({"eks": {}}) is False
assert rt.is_available({}) is False
def test_extract_params_maps_fields() -> None:
rt = list_eks_clusters.__opensre_registered_tool__
sources = mock_agent_state()
params = rt.extract_params(sources)
assert params["role_arn"] == "arn:aws:iam::123456789012:role/eks-role"
def test_run_happy_path() -> None:
mock_client = MagicMock()
mock_client.list_clusters.return_value = ["cluster-1", "cluster-2"]
with patch("integrations.eks.tools.EKSClient", return_value=mock_client):
result = list_eks_clusters(role_arn="arn:aws:iam::123:role/r")
assert result["available"] is True
assert result["clusters"] == ["cluster-1", "cluster-2"]
def test_run_with_cluster_filter() -> None:
mock_client = MagicMock()
mock_client.list_clusters.return_value = ["cluster-1", "cluster-2", "cluster-3"]
with patch("integrations.eks.tools.EKSClient", return_value=mock_client):
result = list_eks_clusters(role_arn="arn:aws:iam::123:role/r", cluster_names=["cluster-1"])
assert result["clusters"] == ["cluster-1"]
def test_run_handles_client_error() -> None:
mock_client = MagicMock()
error = ClientError({"Error": {"Code": "AccessDenied", "Message": "Denied"}}, "ListClusters")
mock_client.list_clusters.side_effect = error
with patch("integrations.eks.tools.EKSClient", return_value=mock_client):
result = list_eks_clusters(role_arn="arn:aws:iam::123:role/r")
assert result["available"] is False
assert result["clusters"] == []
def test_run_forwards_credentials_to_eks_client() -> None:
"""Stored AWS-integration credentials must thread through into ``EKSClient``.
Without this the `list_eks_clusters` path (the cluster-discovery /
connection-verification step) would still hit ``sts.assume_role(RoleArn="", ...)``
for IAM-user-only integrations and raise ``ParamValidationError``.
"""
mock_client = MagicMock()
mock_client.list_clusters.return_value = ["cluster-1"]
creds = {
"access_key_id": "AKIA_TEST",
"secret_access_key": "SECRET",
"session_token": "",
}
with patch("integrations.eks.tools.EKSClient", return_value=mock_client) as cls:
list_eks_clusters(role_arn="", credentials=creds)
cls.assert_called_once()
assert cls.call_args.kwargs["credentials"] == creds
assert cls.call_args.kwargs["role_arn"] == ""
def test_run_credentials_none_by_default() -> None:
"""Existing role-based callers must keep working — credentials defaults to None."""
mock_client = MagicMock()
mock_client.list_clusters.return_value = []
with patch("integrations.eks.tools.EKSClient", return_value=mock_client) as cls:
list_eks_clusters(role_arn="arn:aws:iam::123:role/r")
assert cls.call_args.kwargs["credentials"] is None