Skip to content

Commit

Permalink
Allow for empty payloads in generic source for testing purposes (#371)
Browse files Browse the repository at this point in the history
If the payload is empty then skip over it, in some special cases the
ruleset might not need any direct events but would be using set_facts to
generate the data.
This came about in PR
#349 Where there is no
payload.

https://github.com/ansible/ansible-rulebook/blob/3f9793c702401590807b027133c4ca70ec672884/tests/e2e/files/rulebooks/actions/test_run_playbook.yml#L48
This leads to an error in the source
```
2023-02-14 16:38:53,582 - ansible_rulebook.engine - ERROR - Source error
Traceback (most recent call last):
  File "/Users/madhukanoor/devsrc/ansible-rulebook/ansible_rulebook/engine.py", line 154, in start_source
    await entrypoint(fqueue, args)
  File "/Users/madhukanoor/devsrc/ansible-rulebook/tests/e2e/../sources/generic.py", line 97, in main
    data.update(event)
```
  • Loading branch information
mkanoor authored Feb 15, 2023
2 parents 6ae4688 + f377971 commit df2dd66
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/sources/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ async def main(queue: asyncio.Queue, args: Dict[str, Any]):
if randomize:
random.shuffle(payload)
for event in payload:
if not event:
continue
for _ in range(repeat_count):
data = {}
if create_index:
Expand Down

0 comments on commit df2dd66

Please sign in to comment.