Skip to content

Commit

Permalink
fix: convert listValues to lists
Browse files Browse the repository at this point in the history
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
  • Loading branch information
fernandezcuesta committed Oct 17, 2024
1 parent fde5b7e commit 1d2dcb3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crossplane/function/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def struct_to_dict(s: structpb.Struct) -> dict:
dictionary.
"""
return {
k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else v)
k: (struct_to_dict(v) if isinstance(v, structpb.Struct) else (
list(v) if isinstance(v, structpb.ListValue) else v
))
for k, v in s.items()
}

Expand Down
22 changes: 22 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,28 @@ class TestCase:
),
want={"foo": {"bar": "baz"}},
),
TestCase(
reason="Convert a nested struct containing ListValues to a dictionary.",
s=structpb.Struct(
fields={
"foo": structpb.Value(
struct_value=structpb.Struct(
fields={
"bar": structpb.Value(
list_value=structpb.ListValue(
values=[
structpb.Value(string_value="baz"),
structpb.Value(string_value="qux"),
]
)
)
}
)
)
}
),
want={"foo": {"bar": ["baz", "qux"]}},
),
]

for case in cases:
Expand Down

0 comments on commit 1d2dcb3

Please sign in to comment.