add tests for file.serialize check_cmd usage

This commit is contained in:
nicholasmhughes 2023-09-25 17:12:27 -04:00 committed by Daniel Wozniak
parent a66c4fc174
commit 2cff8b35fa

View file

@ -147,3 +147,37 @@ def test_serializer_plist_file_open(file, tmp_path):
serialized_data = salt.serializers.plist.deserialize(name.read_bytes())
# make sure our serialized data matches what we expect
assert serialized_data["foo"] == merged["foo"]
def test_serialize_check_cmd(file, tmp_path):
# pass
path_test = tmp_path / "test_serialize_check_cmd"
dataset_one = {
"name": "naive",
"description": "A basic test",
"a_list": ["first_element", "second_element"],
}
ret = file.serialize(
name=str(path_test),
dataset=dataset_one,
serializer="json",
check_cmd="grep 'first_element'",
)
assert ret.result is True
# fail
dataset_two = {
"name": "naive",
"description": "A basic test",
"a_list": ["first_element", "second_element"],
"finally": "the last item",
}
ret = file.serialize(
name=str(path_test),
dataset=dataset_two,
serializer="json",
check_cmd="grep 'fifth_element'",
)
assert ret.result is False
assert json.loads(path_test.read_text()) == dataset_one