Add unit tests for the autorestart
@@ -146,3 +146,33 @@ def test_action_execute_called_correctly(node_scenario):
args, kwargs = call
assert args[0] == "echo lol"
assert kwargs["nodes"] == [items[i]]
+
+def test_action_stop_creates_cleanup_action(node_scenario):
+ node_scenario.schema["actions"] = [
+ dict(
+ stop=dict(
+ autoRestart=True
+ )
+ )
+ ]
+ mock_item = MagicMock()
+ node_scenario.act([mock_item])
+ cleanup = node_scenario.get_cleanup_actions()
+ assert len(cleanup) == 1
+ assert cleanup[0] is not node_scenario
+ assert cleanup[0].schema is not node_scenario.schema
+ assert cleanup[0].schema != node_scenario.schema
+ assert "start" in cleanup[0].schema["actions"][0]["action"]
+
+
+def test_action_stop_doesnt_create_cleanup_action(node_scenario):
+ node_scenario.schema["actions"] = [
+ dict(
+ stop=dict(
+ autoRestart=False
+ )
+ )
+ ]
+ mock_item = MagicMock()
+ node_scenario.act([mock_item])
+ assert node_scenario.get_cleanup_actions() == []
