mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-04 06:21:15 +02:00
Add tests for install_busybox()
This commit is contained in:
1 parent
f3b6825e40
commit
1fd8444d22
2 files changed
+61
-2
No files matched your search
@@ -15,6 +15,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import asyncio
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from unittest.mock import MagicMock, patch
|
||||
@@ -209,3 +210,49 @@ async def test_docker_check_connection_docker_preferred_version_against_older(vm
|
||||
vm._connected = False
|
||||
await vm._check_connection()
|
||||
assert vm._api_version == DOCKER_MINIMUM_API_VERSION
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_install_busybox():
|
||||
|
||||
mock_process = MagicMock(spec=asyncio.subprocess.Process)
|
||||
mock_process.communicate.return_value = (b"", b"not a dynamic executable")
|
||||
mock_process.returncode = 1 # means that busybox is not dynamically linked
|
||||
|
||||
with patch("os.path.isfile", return_value=False):
|
||||
with patch("shutil.which", return_value="/usr/bin/busybox"):
|
||||
with patch("asyncio.create_subprocess_exec", return_value=mock_process) as create_subprocess_mock:
|
||||
with patch("shutil.copy2") as copy2_mock:
|
||||
await Docker.install_busybox()
|
||||
create_subprocess_mock.assert_called_with(
|
||||
"ldd",
|
||||
"/usr/bin/busybox",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.DEVNULL,
|
||||
)
|
||||
assert copy2_mock.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_install_busybox_dynamic_linked():
|
||||
|
||||
mock_process = MagicMock(spec=asyncio.subprocess.Process)
|
||||
mock_process.communicate.return_value = (b"Dynamically linked library", b"")
|
||||
mock_process.returncode = 0 # means that busybox is dynamically linked
|
||||
|
||||
with patch("os.path.isfile", return_value=False):
|
||||
with patch("shutil.which", return_value="/usr/bin/busybox"):
|
||||
with patch("asyncio.create_subprocess_exec", return_value=mock_process):
|
||||
with pytest.raises(DockerError) as e:
|
||||
await Docker.install_busybox()
|
||||
assert str(e.value) == "No busybox executable could be found"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_install_busybox_no_executables():
|
||||
|
||||
with patch("os.path.isfile", return_value=False):
|
||||
with patch("shutil.which", return_value=None):
|
||||
with pytest.raises(DockerError) as e:
|
||||
await Docker.install_busybox()
|
||||
assert str(e.value) == "No busybox executable could be found"
|
||||
Reference in new issue
Block a user