From 2cff8b35faeb31f4f8d9b0ed60dea3b4a45eb8ed Mon Sep 17 00:00:00 2001 From: nicholasmhughes Date: Mon, 25 Sep 2023 17:12:27 -0400 Subject: [PATCH] add tests for file.serialize check_cmd usage --- .../functional/states/file/test_serialize.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/pytests/functional/states/file/test_serialize.py b/tests/pytests/functional/states/file/test_serialize.py index 26d35cd23244..02f72fd237e9 100644 --- a/tests/pytests/functional/states/file/test_serialize.py +++ b/tests/pytests/functional/states/file/test_serialize.py @@ -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