Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/43364.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed thorium reg.list to accept a non-string, non-list add value (such as an integer) instead of raising AttributeError.
4 changes: 3 additions & 1 deletion salt/thorium/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ def list_(name, add, match, stamp=False, prune=0):
- stamp: True
"""
ret = {"name": name, "changes": {}, "comment": "", "result": True}
if not isinstance(add, list):
if isinstance(add, str):
add = add.split(",")
elif not isinstance(add, list):
add = [add]
if name not in __reg__:
__reg__[name] = {}
__reg__[name]["val"] = []
Expand Down
Empty file.
49 changes: 49 additions & 0 deletions tests/pytests/unit/thorium/test_reg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
tests.pytests.unit.thorium.test_reg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Unit tests for the thorium reg module
"""

import pytest

import salt.thorium.reg as reg


@pytest.fixture
def setup_reg_dunders():
# The thorium loader injects ``__reg__`` and ``__events__`` as module
# globals. Set them directly since they are not standard salt dunders
# handled by the loader mock fixture.
reg.__dict__["__reg__"] = {}
reg.__dict__["__events__"] = [
{
"tag": "phil/was/here",
"data": {"data": {42: "the answer"}, "_stamp": "2017-09-06"},
}
]
try:
yield
finally:
reg.__dict__.pop("__reg__", None)
reg.__dict__.pop("__events__", None)


def test_list_integer_add(setup_reg_dunders):
"""
An integer ``add`` value must not raise AttributeError (no .split on int)
and the integer key should be looked up in the event data.
"""
ret = reg.list_("myregister", add=42, match="phil/was/here")
assert ret["result"] is True
assert reg.__dict__["__reg__"]["myregister"]["val"] == [{42: "the answer"}]


def test_list_string_add_still_splits(setup_reg_dunders):
"""
A comma separated string ``add`` value must still be split into keys.
"""
reg.__dict__["__events__"][0]["data"]["data"] = {"a": 1, "b": 2}
ret = reg.list_("myregister", add="a,b", match="phil/was/here")
assert ret["result"] is True
assert reg.__dict__["__reg__"]["myregister"]["val"] == [{"a": 1, "b": 2}]
Loading