|
9 | 9 | from subvortex.auto_upgrader.src.github import Github |
10 | 10 |
|
11 | 11 |
|
12 | | -@patch("subvortex.auto_upgrader.src.constants.SV_EXECUTION_METHOD", "service") |
13 | | -@patch("subvortex.auto_upgrader.src.github.os.path.islink") |
14 | | -@patch("subvortex.auto_upgrader.src.github.os.listdir") |
15 | | -@patch("subvortex.auto_upgrader.src.github.os.path.isdir") |
16 | | -@patch("subvortex.auto_upgrader.src.github.os.path.isfile") |
17 | | -def test_get_local_version_service_returns_version( |
18 | | - mock_isfile, |
19 | | - mock_isdir, |
20 | | - mock_listdir, |
21 | | - mock_islink, |
22 | | -): |
| 12 | +@patch("subvortex.auto_upgrader.src.github.os.readlink") |
| 13 | +@patch("subvortex.auto_upgrader.src.github.os.path.islink", return_value=True) |
| 14 | +@patch("subvortex.auto_upgrader.src.github.os.path.isfile", return_value=False) |
| 15 | +def test_get_local_version_symlink_returns_version(mock_isfile, mock_islink, mock_readlink): |
23 | 16 | # Arrange |
24 | 17 | github = Github() |
25 | | - |
26 | | - # Simulate /var/tmp/subvortex directory listing |
27 | | - mock_listdir.return_value = [ |
28 | | - "subvortex-1.2.3", # Valid version folder |
29 | | - "subvortex-1.1.0", # Older valid version |
30 | | - "random-folder", # Should be ignored |
31 | | - ] |
32 | | - |
33 | | - # Simulate os.path.isdir always returning True |
34 | | - mock_islink.side_effect = [False, False, False] |
35 | | - mock_isdir.side_effect = [True, True, True, True] |
36 | | - mock_isfile.side_effect = [False, False, False] |
| 18 | + mock_readlink.return_value = "/var/tmp/subvortex/subvortex-1.2.3" |
37 | 19 |
|
38 | 20 | # Act |
39 | 21 | version = github.get_local_version() |
40 | 22 |
|
41 | 23 | # Assert |
42 | 24 | assert version == "1.2.3" |
43 | | - mock_listdir.assert_called_once_with("/var/tmp/subvortex") |
44 | | - assert mock_isdir.call_count == 4 |
| 25 | + mock_readlink.assert_called_once() |
45 | 26 |
|
46 | 27 |
|
47 | | -@patch("subvortex.auto_upgrader.src.constants.SV_EXECUTION_METHOD", "service") |
48 | | -@patch("subvortex.auto_upgrader.src.github.os.listdir") |
49 | | -@patch("subvortex.auto_upgrader.src.github.os.path.isdir") |
50 | | -def test_get_local_version_service_returns_none_when_no_valid_versions( |
51 | | - mock_isdir, mock_listdir |
52 | | -): |
| 28 | +@patch("subvortex.auto_upgrader.src.github.os.readlink") |
| 29 | +@patch("subvortex.auto_upgrader.src.github.os.path.islink", return_value=True) |
| 30 | +def test_get_local_version_symlink_invalid_path(mock_islink, mock_readlink): |
53 | 31 | # Arrange |
54 | 32 | github = Github() |
55 | | - |
56 | | - # Simulate /var/tmp/subvortex directory listing with no valid versions |
57 | | - mock_listdir.return_value = [ |
58 | | - "random-folder", |
59 | | - "another-folder", |
60 | | - "not-a-version", |
61 | | - ] |
62 | | - |
63 | | - # Simulate os.path.isdir always returning True |
64 | | - mock_isdir.return_value = True |
| 33 | + mock_readlink.return_value = "/some/unknown/path/no-version-here" |
65 | 34 |
|
66 | 35 | # Act |
67 | 36 | version = github.get_local_version() |
68 | 37 |
|
69 | 38 | # Assert |
70 | 39 | assert version is None |
71 | | - mock_listdir.assert_called_once_with("/var/tmp/subvortex") |
72 | | - assert mock_isdir.call_count == 4 # 1 check for base dir + 3 entries |
73 | 40 |
|
74 | 41 |
|
75 | | -@patch("subvortex.auto_upgrader.src.constants.SV_EXECUTION_METHOD", "service") |
76 | | -@patch("subvortex.auto_upgrader.src.github.os.path.isdir") |
77 | | -def test_get_local_version_service_returns_none_when_asset_dir_does_not_exist( |
78 | | - mock_isdir, |
79 | | -): |
| 42 | +@patch("subvortex.auto_upgrader.src.github.os.readlink") |
| 43 | +@patch("subvortex.auto_upgrader.src.github.os.path.islink", return_value=True) |
| 44 | +@patch("subvortex.auto_upgrader.src.github.os.path.isfile", return_value=True) |
| 45 | +@patch("subvortex.auto_upgrader.src.github.os.remove") |
| 46 | +def test_get_local_version_symlink_force_marker(mock_remove, mock_isfile, mock_islink, mock_readlink): |
80 | 47 | # Arrange |
81 | 48 | github = Github() |
82 | | - |
83 | | - # Simulate os.path.isdir always returning True |
84 | | - mock_isdir.return_value = False |
| 49 | + mock_readlink.return_value = "/var/tmp/subvortex/subvortex-3.0.0a40" |
85 | 50 |
|
86 | 51 | # Act |
87 | 52 | version = github.get_local_version() |
88 | 53 |
|
89 | 54 | # Assert |
90 | 55 | assert version is None |
91 | | - assert mock_isdir.call_count == 1 |
| 56 | + mock_remove.assert_called_once() |
92 | 57 |
|
93 | 58 |
|
94 | 59 | @patch("subvortex.auto_upgrader.src.github.requests.get") |
|
0 commit comments