mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-06 09:29:31 +00:00
* Use add-on config timestamp to determine add-on update age Instead of using the current timestamp when loading the add-on config, simply use the add-on config modification timestamp. This way, we can get a timetsamp even when Supervisor got restarted. It also simplifies the code a bit. * Fix pytest * Patch stat() instead of modifing fixture files
52 lines
2.0 KiB
Python
52 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(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
|