Skip to content

Commit

Permalink
mqtt: fix unexpected behaviour
Browse files Browse the repository at this point in the history
Currently mqtt_response with the unexpected key set to true fails if no
message is received. This is strange, was we don't expect a message, and
should only fail if a message is received.

Formatted stage:
  mqtt_publish:
    payload: 10.10.10.10
    topic: inet6/add
  mqtt_response:
    payload: !anything ''
    timeout: 5
    topic: vallumd/will
    unexpected: true

Errors:
E   tavern.util.exceptions.TestFailError: Test 'add IPv4 IP to IPv6 ipset' failed:
    - Expected '<Tavern YAML sentinel for anything>' on topic 'vallumd/will' but no such message received

Fix this by adding an extra check for the expected key when we received
no message.

Signed-off-by: Stijn Tintel <[email protected]>
  • Loading branch information
stintel committed Dec 9, 2022
1 parent 6f37548 commit 3c6d68f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tavern/_plugins/mqtt/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ def addwarning(w, *args, **kwargs):

self._maybe_run_validate_functions(msg)
else:
self._adderr(
"Expected '%s' on topic '%s' but no such message received",
expected_payload,
topic,
)
if not self.expected.get("unexpected"):
self._adderr(
"Expected '%s' on topic '%s' but no such message received",
expected_payload,
topic,
)

if self.errors:
if warnings:
Expand All @@ -198,6 +199,9 @@ def addwarning(w, *args, **kwargs):

saved = {}

if not msg:
return saved

saved.update(self.maybe_get_save_values_from_save_block("json", msg.payload))

saved.update(self.maybe_get_save_values_from_ext(msg, self.expected))
Expand Down

0 comments on commit 3c6d68f

Please sign in to comment.