mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-04-02 08:12:47 +01:00
* Ensure uuid of dismissed suggestion/issue matches an existing one * Fix lint, test and feedback issues * Adjust existing tests and remove new ones for not found errors * fix device access issue usage
54 lines
2.0 KiB
Python
54 lines
2.0 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_addon_configs(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_addon_configs(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(
|
|
coresys.resolution.get_issue_if_present(corrupt_repo)
|
|
)
|
|
err.errno = errno.EBADMSG
|
|
assert (await coresys.store.data._find_addon_configs(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
|