1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

feat: compute load balancer targets status using a filter (#550)

##### SUMMARY

Allow to compute the status of a load balancer using a filter.

Closes #467 

##### ISSUE TYPE

- Feature Pull Request


##### COMPONENT NAME

hetzner.hcloud.loab_balancer_status
This commit is contained in:
Jonas L. 2024-08-14 14:18:39 +02:00 committed by GitHub
parent a85bd39738
commit fce8bc9bb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 199 additions and 10 deletions

View file

@ -0,0 +1,45 @@
from __future__ import annotations
import pytest
from plugins.filter.all import load_balancer_status
LOAD_BALANCER_STATUS_TEST_CASES = (
({"targets": [{"health_status": []}]}, "unknown"),
({"targets": [{"health_status": [{}]}]}, "unknown"),
({"targets": [{"health_status": [{"status": "unknown"}]}]}, "unknown"),
({"targets": [{"health_status": [{"status": "unhealthy"}]}]}, "unhealthy"),
({"targets": [{"health_status": [{"status": "healthy"}]}]}, "healthy"),
(
{
"targets": [
{"health_status": [{"status": "healthy"}]},
{"health_status": [{"status": "healthy"}]},
]
},
"healthy",
),
(
{
"targets": [
{"health_status": [{"status": "healthy"}, {"status": "unhealthy"}]},
{"health_status": [{"status": "healthy"}, {"status": "unknown"}]},
]
},
"unhealthy",
),
(
{
"targets": [
{"health_status": [{"status": "healthy"}]},
{"health_status": [{"status": "unhealthy"}]},
]
},
"unhealthy",
),
)
@pytest.mark.parametrize(("value", "expected"), LOAD_BALANCER_STATUS_TEST_CASES)
def test_load_balancer_status(value, expected):
assert expected == load_balancer_status(value)