From 21969439bee2cd9d64206698fb7e8ceb1c956545 Mon Sep 17 00:00:00 2001 From: ShotaAshida Date: Wed, 30 Oct 2019 16:24:09 +0900 Subject: [PATCH] make test Signed-off-by: ShotaAshida --- chaosazure/aks/actions.py | 5 +++++ tests/aks/test_aks_actions.py | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/chaosazure/aks/actions.py b/chaosazure/aks/actions.py index aae3d58..4efb95b 100644 --- a/chaosazure/aks/actions.py +++ b/chaosazure/aks/actions.py @@ -99,8 +99,13 @@ def node_resource_group_query(query, sample, configuration, secrets): choice = random.choice(aks) node_resource_group = choice['properties']['nodeResourceGroup'] + return format_query(sample, node_resource_group) + + +def format_query(sample, node_resource_group): if sample is None: return "where resourceGroup =~ '{}'".format(node_resource_group) else: return "where resourceGroup =~ '{}' | sample {}".format( node_resource_group, sample) + diff --git a/tests/aks/test_aks_actions.py b/tests/aks/test_aks_actions.py index e93d05e..fbd95db 100644 --- a/tests/aks/test_aks_actions.py +++ b/tests/aks/test_aks_actions.py @@ -3,7 +3,7 @@ import pytest from chaoslib.exceptions import FailedActivity -from chaosazure.aks.actions import restart_node, stop_node, delete_node +from chaosazure.aks.actions import restart_node, stop_node, delete_node, format_query resource = { 'name': 'chaos-aks', @@ -19,7 +19,7 @@ def test_delete_node(delete, fetch): resource_list = [resource] fetch.return_value = resource_list - delete_node(None, None, None) + delete_node(None, None, None, None) @patch('chaosazure.aks.actions.fetch_resources', autospec=True) @@ -27,7 +27,7 @@ def test_restart_node_with_no_nodes(fetch): with pytest.raises(FailedActivity) as x: resource_list = [] fetch.return_value = resource_list - delete_node(None, None, None) + delete_node(None, None, None, None) assert "No AKS clusters found" in str(x.value) @@ -38,7 +38,7 @@ def test_stop_node(stop, fetch): resource_list = [resource] fetch.return_value = resource_list - stop_node(None, None, None) + stop_node(None, None, None, None) @patch('chaosazure.aks.actions.fetch_resources', autospec=True) @@ -46,7 +46,7 @@ def test_restart_node_with_no_nodes(fetch): with pytest.raises(FailedActivity) as x: resource_list = [] fetch.return_value = resource_list - stop_node(None, None, None) + stop_node(None, None, None, None) assert "No AKS clusters found" in str(x.value) @@ -57,7 +57,7 @@ def test_restart_node(restart, fetch): resource_list = [resource] fetch.return_value = resource_list - restart_node(None, None, None) + restart_node(None, None, None, None) @patch('chaosazure.aks.actions.fetch_resources', autospec=True) @@ -65,6 +65,17 @@ def test_restart_node_with_no_nodes(fetch): with pytest.raises(FailedActivity) as x: resource_list = [] fetch.return_value = resource_list - restart_node(None, None, None) + restart_node(None, None, None, None) assert "No AKS clusters found" in str(x.value) + + +def test_format_query(): + query = format_query(1, resource['properties']['nodeResourceGroup']) + assert query == "where resourceGroup =~ 'nrg' | sample 1" + + +def test_no_sample_format_query(): + query = format_query(None, resource['properties']['nodeResourceGroup']) + assert query == "where resourceGroup =~ 'nrg'" +