Files
supervisor/tests/store/test_reading_addons.py
Mike Degatano 3cc6bd19ad Mark system as unhealthy on OSError Bad message errors (#4750)
* Bad message error marks system as unhealthy

* Finish adding test cases for changes

* Rename test file for uniqueness

* bad_message to oserror_bad_message

* Omit some checks and check for network mounts
2023-12-21 18:05:29 +01:00

51 lines
1.9 KiB
Python

"""Test that we are reading add-on files correctly."""
import errno
from pathlib import Path
from unittest.mock import patch
from supervisor.coresys import CoreSys
from supervisor.resolution.const import ContextType, IssueType, SuggestionType
from supervisor.resolution.data import Issue, Suggestion
# pylint: disable=protected-access
async def test_read_addon_files(coresys: CoreSys):
"""Test that we are reading add-on files correctly."""
with patch(
"pathlib.Path.glob",
return_value=[
Path("addon/config.yml"),
Path(".git/config.yml"),
Path("somepath/.git/config.yml"),
Path("somepath/deeper_in_the_structure/.github/config.yml"),
Path(".github/config.yml"),
Path("some/rootfs/config.yml"),
Path(".circleci/config.yml"),
],
):
addon_list = await coresys.store.data._find_addons(Path("test"), {})
assert len(addon_list) == 1
assert str(addon_list[0]) == "addon/config.yml"
async def test_reading_addon_files_error(coresys: CoreSys):
"""Test error trying to read addon files."""
corrupt_repo = Issue(IssueType.CORRUPT_REPOSITORY, ContextType.STORE, "test")
reset_repo = Suggestion(SuggestionType.EXECUTE_RESET, ContextType.STORE, "test")
with patch("pathlib.Path.glob", side_effect=(err := OSError())):
err.errno = errno.EBUSY
assert (await coresys.store.data._find_addons(Path("test"), {})) is None
assert corrupt_repo in coresys.resolution.issues
assert reset_repo in coresys.resolution.suggestions
assert coresys.core.healthy is True
coresys.resolution.dismiss_issue(corrupt_repo)
err.errno = errno.EBADMSG
assert (await coresys.store.data._find_addons(Path("test"), {})) is None
assert corrupt_repo in coresys.resolution.issues
assert reset_repo not in coresys.resolution.suggestions
assert coresys.core.healthy is False