Skip to content

Commit

Permalink
Add a test case for a host.when conditional operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Jul 24, 2024
1 parent 3143695 commit d192194
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tests/test_cli/deploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ def my_deploy():
dest="/a_template",
is_template=True,
)

with host.when(lambda: host.name != "somehost"):
server.shell(
name="Second final limited operation",
commands="echo final_limited_op",
)
9 changes: 7 additions & 2 deletions tests/test_cli/test_cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ def _assert_op_data(self, correct_op_name_and_host_names):
assert list(op_meta.names)[0] == correct_op_name

for host in state.inventory:
executed = False
host_op = state.ops[host].get(op_hash)
if host_op:
executed = host_op.operation_meta.executed
if correct_host_names is True or host.name in correct_host_names:
self.assertIn(op_hash, host.op_hash_order)
assert executed is True
else:
self.assertNotIn(op_hash, host.op_hash_order)
assert executed is False

def test_deploy(self):
task_file_path = path.join("tasks", "a_task.py")
Expand Down Expand Up @@ -72,6 +76,7 @@ def test_deploy(self):
("Nested order loop 2/1", ("somehost", "anotherhost")),
("Nested order loop 2/2", ("somehost", "anotherhost")),
("Final limited operation", ("somehost",)),
("Second final limited operation", ("anotherhost", "someotherhost")),
]

# Run 3 iterations of the test - each time shuffling the order of the
Expand Down

0 comments on commit d192194

Please sign in to comment.