|
3 | 3 | import pytest
|
4 | 4 | from chaoslib.exceptions import FailedActivity
|
5 | 5 |
|
6 |
| -from chaosaws.fis.actions import start_experiment |
| 6 | +from chaosaws.fis.actions import start_experiment, stop_experiment |
7 | 7 |
|
8 | 8 |
|
9 | 9 | def test_that_fis_modules___all___attribute_exposed_correctly():
|
10 | 10 | import chaosaws.fis.actions as actions
|
11 | 11 |
|
12 | 12 | all = actions.__all__
|
13 | 13 | assert "start_experiment" in all
|
| 14 | + assert "stop_experiment" in all |
14 | 15 |
|
15 | 16 |
|
16 | 17 | @patch("chaosaws.fis.actions.aws_client", autospec=True)
|
@@ -77,3 +78,52 @@ def test_that_start_experiment_returns_client_response(aws_client):
|
77 | 78 |
|
78 | 79 | actual_resp = start_experiment(experiment_template_id="an-id")
|
79 | 80 | assert actual_resp == resp
|
| 81 | + |
| 82 | + |
| 83 | +@patch("chaosaws.fis.actions.aws_client", autospec=True) |
| 84 | +def test_that_stop_experiment_invoked_correctly_when_given_experiment_id(aws_client): |
| 85 | + client = MagicMock() |
| 86 | + aws_client.return_value = client |
| 87 | + |
| 88 | + stop_experiment(experiment_id="an-id") |
| 89 | + client.stop_experiment.assert_called_once_with(id="an-id") |
| 90 | + |
| 91 | + |
| 92 | +@patch("chaosaws.fis.actions.aws_client", autospec=True) |
| 93 | +def test_that_stop_experiment_fails_if_experiment_id_empty_or_none(aws_client): |
| 94 | + client = MagicMock() |
| 95 | + aws_client.return_value = client |
| 96 | + |
| 97 | + with pytest.raises(FailedActivity) as ex: |
| 98 | + stop_experiment(experiment_id="") |
| 99 | + assert str(ex.value) == ( |
| 100 | + "You must pass a valid experiment id, id provided was empty" |
| 101 | + ) |
| 102 | + |
| 103 | + with pytest.raises(FailedActivity) as ex: |
| 104 | + stop_experiment(experiment_id=None) |
| 105 | + assert str(ex.value) == ( |
| 106 | + "You must pass a valid experiment id, id provided was empty" |
| 107 | + ) |
| 108 | + |
| 109 | + |
| 110 | +@patch("chaosaws.fis.actions.aws_client", autospec=True) |
| 111 | +def test_that_stop_experiment_fails_if_exception_raised(aws_client): |
| 112 | + client = MagicMock() |
| 113 | + aws_client.return_value = client |
| 114 | + client.stop_experiment.side_effect = Exception("Something went wrong") |
| 115 | + |
| 116 | + with pytest.raises(FailedActivity) as ex: |
| 117 | + stop_experiment(experiment_id="an-id") |
| 118 | + assert str(ex.value) == "Stop Experiment failed, reason was: Something went wrong" |
| 119 | + |
| 120 | + |
| 121 | +@patch("chaosaws.fis.actions.aws_client", autospec=True) |
| 122 | +def test_that_stop_experiment_returns_client_response(aws_client): |
| 123 | + client = MagicMock() |
| 124 | + aws_client.return_value = client |
| 125 | + resp = {"a-key": "a-value"} |
| 126 | + client.stop_experiment.return_value = resp |
| 127 | + |
| 128 | + actual_resp = stop_experiment(experiment_id="an-id") |
| 129 | + assert actual_resp == resp |
0 commit comments