Skip to content

Commit

Permalink
make test
Browse files Browse the repository at this point in the history
Signed-off-by: ShotaAshida <[email protected]>
  • Loading branch information
ShotaAshida committed Oct 30, 2019
1 parent b6134ba commit 2196943
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions chaosazure/aks/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

25 changes: 18 additions & 7 deletions tests/aks/test_aks_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -19,15 +19,15 @@ 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)
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)

Expand All @@ -38,15 +38,15 @@ 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)
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)

Expand All @@ -57,14 +57,25 @@ 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)
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'"

0 comments on commit 2196943

Please sign in to comment.