mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Updated test_cache.py test_unicode_error, since should no longer be thrown due to an empty file
This commit is contained in:
parent
b0d78400a6
commit
ca67812d96
2 changed files with 13 additions and 4 deletions
|
@ -144,7 +144,7 @@ def test_pillar_get_cache_disk(temp_salt_minion, caplog):
|
|||
opts["pillar_cache"] = True
|
||||
opts["cachedir"] = str(temp_path)
|
||||
|
||||
caplog.at_level(logging.ERROR)
|
||||
caplog.at_level(logging.DEBUG)
|
||||
pillar = salt.pillar.PillarCache(
|
||||
opts=opts,
|
||||
grains=salt.loader.grains(opts),
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
Test the salt cache objects
|
||||
"""
|
||||
|
||||
import logging
|
||||
import pathlib
|
||||
import time
|
||||
|
||||
|
@ -221,7 +222,7 @@ def test_everything(cache_dir):
|
|||
b"\xc3\x83\xc2\xa6\xc3\x83\xc2\xb8\xc3\x83\xc2\xa5",
|
||||
],
|
||||
)
|
||||
def test_unicode_error(cache_dir, data):
|
||||
def test_unicode_error(cache_dir, data, caplog):
|
||||
"""
|
||||
Test when the data in the cache raises a UnicodeDecodeError
|
||||
we do not raise an error.
|
||||
|
@ -240,9 +241,17 @@ def test_unicode_error(cache_dir, data):
|
|||
}
|
||||
}
|
||||
}
|
||||
with patch.object(salt.utils.msgpack, "load", return_value=cache_data):
|
||||
with patch.object(
|
||||
salt.utils.msgpack, "load", return_value=cache_data
|
||||
), caplog.at_level(logging.DEBUG):
|
||||
cd = cache.CacheDisk(0.3, str(path))
|
||||
assert cd._dict == cache_data
|
||||
# this test used to rely on msgpack throwing errors if attempt to read an empty file
|
||||
# code now checks if file empty and returns, so we should never attempt msgpack load
|
||||
assert cd._dict == {}
|
||||
assert not (
|
||||
f"Error reading cache file at '{path}': Unpack failed: incomplete input"
|
||||
in caplog.messages
|
||||
)
|
||||
|
||||
|
||||
def test_cache_corruption(cache_dir):
|
||||
|
|
Loading…
Add table
Reference in a new issue