/
/
/
1"""Tests for the NFS filesystem provider mount error handling."""
2
3from __future__ import annotations
4
5from unittest.mock import AsyncMock, MagicMock, patch
6
7import pytest
8from music_assistant_models.errors import SetupFailedError, UnsupportedSystemError
9
10from music_assistant.providers.filesystem_nfs.provider import NFSFileSystemProvider
11
12INSTANCE_ID = "filesystem_nfs--test"
13SETUP_VALUES = {
14 "host": "nas.local",
15 "export_path": "/volume1/music",
16 "subfolder": "",
17 "nfs_version": "",
18}
19
20
21def _make_provider() -> NFSFileSystemProvider:
22 provider = NFSFileSystemProvider.__new__(NFSFileSystemProvider)
23 provider.base_path = f"/tmp/{INSTANCE_ID}" # noqa: S108
24 # no subfolder configured, so the scan root is the mountpoint itself
25 provider.mount_path = provider.base_path
26 provider._subfolder = ""
27 provider.logger = MagicMock()
28 provider.config = MagicMock()
29 provider.config.instance_id = INSTANCE_ID
30 provider.get_setup_value = MagicMock( # type: ignore[method-assign]
31 side_effect=lambda key, default=None: SETUP_VALUES.get(key, default)
32 )
33 return provider
34
35
36async def test_mount_failure_shows_the_summary_line() -> None:
37 """A failed mount shows the summary line but keeps the full output for support."""
38 summary = "mount.nfs: access denied by server while mounting nas.local:/volume1/music"
39 pointer = "Refer to the nfs(5) manual page"
40 provider = _make_provider()
41 with (
42 patch(
43 "music_assistant.providers.filesystem_nfs.provider.check_output",
44 AsyncMock(return_value=(32, f"{summary}\n{pointer}".encode())),
45 ),
46 patch(
47 "music_assistant.providers.filesystem_nfs.provider.platform.system",
48 return_value="Linux",
49 ),
50 pytest.raises(SetupFailedError) as exc_info,
51 ):
52 await provider.mount()
53 assert exc_info.value.translation_key == "mount_failed"
54 assert exc_info.value.translation_args == [summary]
55 assert pointer in str(exc_info.value)
56
57
58async def test_unsupported_platform() -> None:
59 """A platform without NFS mount support is reported as permanently incompatible."""
60 provider = _make_provider()
61 with (
62 patch(
63 "music_assistant.providers.filesystem_nfs.provider.platform.system",
64 return_value="Windows",
65 ),
66 pytest.raises(UnsupportedSystemError),
67 ):
68 await provider.mount()
69