Skip to content

Commit

Permalink
test/helper: add a helper for status JSON data
Browse files Browse the repository at this point in the history
The JSON output from "rauc status" is a bit difficult to interpret since
it always requires iterating over the array elements to search for the
slot.
To simplify future test assertions, use a helper here that returns the
slot data for a given slot name.

Signed-off-by: Enrico Joerns <[email protected]>
  • Loading branch information
ejoerns committed Nov 29, 2024
1 parent 752bc4b commit 7b9d823
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,18 @@ def run(command, *, timeout=30):

def run_tree(path):
subprocess.check_call(["tree", "--metafirst", "-ax", "-pugs", "--inodes", path])


def slot_data_from_json(status_data, slotname):
"""
Helper to return the slot data from 'rauc status' JSON output.
:param status_data: JSON data obtained from 'rauc status'.
:param slotname: The name of the slot to find in the data.
:return: Slot data as a dictionary.
"""
for slot in status_data["slots"]:
if slotname in slot:
return slot[slotname]
else:
raise ValueError(f"Slot '{slotname}' not found")

0 comments on commit 7b9d823

Please sign in to comment.