|
| 1 | +"""Tests for eks workload helpers""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from app.tools.utils.eks_workload_helper import extract_workload_params |
| 6 | + |
| 7 | + |
| 8 | +def test_extract_basic_params(): |
| 9 | + """Test basic parameter extraction with minimal config""" |
| 10 | + sources = {"eks": {"cluster_name": "test-cluster", "namespace": "default"}} |
| 11 | + |
| 12 | + result = extract_workload_params(sources) |
| 13 | + |
| 14 | + assert result["cluster_name"] == "test-cluster" |
| 15 | + assert result["namespace"] == "default" |
| 16 | + assert result["region"] == "us-east-1" |
| 17 | + assert result["role_arn"] == "" |
| 18 | + assert result["external_id"] == "" |
| 19 | + assert result["credentials"] is None |
| 20 | + |
| 21 | + |
| 22 | +def test_namespace_defaults_to_all(): |
| 23 | + """Test namespace defaults to 'all' when not provided""" |
| 24 | + sources = {"eks": {"cluster_name": "test-cluster"}} |
| 25 | + |
| 26 | + result = extract_workload_params(sources) |
| 27 | + |
| 28 | + assert result["namespace"] == "all" |
| 29 | + |
| 30 | + |
| 31 | +def test_handles_all_optional_fields(): |
| 32 | + """Test extraction includes all optional AWS fields""" |
| 33 | + sources = { |
| 34 | + "eks": { |
| 35 | + "cluster_name": "prod-cluster", |
| 36 | + "role_arn": "arn:aws:iam::123:role/test", |
| 37 | + "external_id": "external-123", |
| 38 | + "region": "us-west-2", |
| 39 | + "credentials": {"access_key": "key123"}, |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + result = extract_workload_params(sources) |
| 44 | + |
| 45 | + assert result["cluster_name"] == "prod-cluster" |
| 46 | + assert result["role_arn"] == "arn:aws:iam::123:role/test" |
| 47 | + assert result["external_id"] == "external-123" |
| 48 | + assert result["region"] == "us-west-2" |
| 49 | + assert result["credentials"] == {"access_key": "key123"} |
| 50 | + |
| 51 | + |
| 52 | +def test_missing_eks_raises_error(): |
| 53 | + """Test ValueError when 'eks' key is missing""" |
| 54 | + sources = {"other": {}} |
| 55 | + |
| 56 | + try: |
| 57 | + extract_workload_params(sources) |
| 58 | + raise AssertionError("Should have raised ValueError") |
| 59 | + except ValueError as e: |
| 60 | + assert "must contain an 'eks' key" in str(e) |
0 commit comments