Skip to content

Commit

Permalink
add tests for file.serialize check_cmd usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasmhughes authored and dwoz committed Dec 16, 2023
1 parent a66c4fc commit 2cff8b3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/pytests/functional/states/file/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2cff8b3

Please sign in to comment.