|
| 1 | +import unittest |
| 2 | +from unittest.mock import patch, MagicMock |
| 3 | + |
| 4 | +from skaraMirror import add_skara_upstream |
| 5 | +from tests.supress_print import SuppressPrint |
| 6 | + |
| 7 | + |
| 8 | +class TestAddSkaraUpstream(unittest.TestCase): |
| 9 | + @patch("skaraMirror.Repo") |
| 10 | + def test_add_skara_remote_not_exist(self, mock_repo): |
| 11 | + # Setup: Configure the mock repo object |
| 12 | + mock_repo.return_value.remotes = MagicMock() |
| 13 | + mock_repo.return_value.remotes.__iter__.return_value = [] |
| 14 | + |
| 15 | + # Define your function parameters |
| 16 | + workspace = "/tmp/workspace" |
| 17 | + jdk_version = "jdk11u" |
| 18 | + skara_repo = "https://github.com/openjdk/skara" |
| 19 | + branch = "master" |
| 20 | + |
| 21 | + # Execute the function |
| 22 | + with SuppressPrint(): |
| 23 | + add_skara_upstream(workspace, jdk_version, skara_repo, branch) |
| 24 | + |
| 25 | + # Assertions: Check if the remote was added |
| 26 | + mock_repo.return_value.create_remote.assert_called_once_with( |
| 27 | + "skara", skara_repo |
| 28 | + ) |
| 29 | + |
| 30 | + @patch("skaraMirror.Repo") |
| 31 | + def test_skara_remote_already_exists(self, mock_repo): |
| 32 | + # Setup: Simulate existing 'skara' remote |
| 33 | + mock_remote = MagicMock() |
| 34 | + mock_remote.name = "skara" |
| 35 | + mock_repo.return_value.remotes = MagicMock() |
| 36 | + mock_repo.return_value.remotes.__iter__.return_value = [mock_remote] |
| 37 | + |
| 38 | + # Execute the function with the same parameters as before |
| 39 | + with SuppressPrint(): |
| 40 | + add_skara_upstream( |
| 41 | + "/tmp/workspace", "jdk11u", "https://github.com/openjdk/skara", "master" |
| 42 | + ) |
| 43 | + |
| 44 | + # Assertions: Ensure create_remote was not called since 'skara' exists |
| 45 | + mock_repo.return_value.create_remote.assert_not_called() |
0 commit comments