aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gmail.com>2019-02-11 17:41:13 -0600
committerTim Harder <radhermit@gmail.com>2019-02-11 17:41:13 -0600
commit839c3ac056e9f085623124d1fa001d787d46c78f (patch)
tree635f023be79d54623f2750161f2eab88ca56eebb /tests/sync
parenttests/rsync/test_rsync: add explicit rsync timestamp syncer tests (diff)
downloadpkgcore-839c3ac056e9f085623124d1fa001d787d46c78f.tar.gz
pkgcore-839c3ac056e9f085623124d1fa001d787d46c78f.tar.bz2
pkgcore-839c3ac056e9f085623124d1fa001d787d46c78f.zip
tests/rsync/test_rsync: merge uri parse tests with syncer test class
Diffstat (limited to 'tests/sync')
-rw-r--r--tests/sync/test_rsync.py57
1 files changed, 29 insertions, 28 deletions
diff --git a/tests/sync/test_rsync.py b/tests/sync/test_rsync.py
index 36ecf724..35840bd1 100644
--- a/tests/sync/test_rsync.py
+++ b/tests/sync/test_rsync.py
@@ -6,26 +6,10 @@ import os
from unittest import mock
import pytest
+from snakeoil.process import CommandNotFound
from pkgcore.sync import base, rsync
from pkgcore.sync.tar import tar_syncer
-from tests.sync.syncer import make_bogus_syncer, make_valid_syncer
-
-bogus = make_bogus_syncer(rsync.rsync_syncer)
-valid = make_valid_syncer(rsync.rsync_syncer)
-
-
-def test_uri_parse():
- with pytest.raises(base.SyncError):
- bogus("/tmp/foon", "rsync+hopefully_nonexistent_binary://foon.com/dar")
-
- o = valid("/tmp/foon", "rsync://dar/module")
- assert o.rsh == None
- assert o.uri == "rsync://dar/module/"
-
- o = valid("/tmp/foon", "rsync+/bin/sh://dar/module")
- assert o.uri == "rsync://dar/module/"
- assert o.rsh == "/bin/sh"
def fake_ips(num):
@@ -36,7 +20,6 @@ def fake_ips(num):
]
-@mock.patch('snakeoil.process.find_binary', return_value='rsync')
@mock.patch('socket.getaddrinfo', return_value=fake_ips(3))
@mock.patch('snakeoil.process.spawn.spawn')
class TestRsyncSyncer(object):
@@ -45,30 +28,48 @@ class TestRsyncSyncer(object):
@pytest.fixture(autouse=True)
def _setup(self, tmp_path):
- path = tmp_path / 'repo'
- self.syncer = self._syncer_class(
- str(path), "rsync://rsync.gentoo.org/gentoo-portage")
-
- def test_successful_sync(self, spawn, getaddrinfo, find_binary):
+ self.repo_path = str(tmp_path / 'repo')
+ with mock.patch('snakeoil.process.find_binary', return_value='rsync'):
+ self.syncer = self._syncer_class(
+ self.repo_path, "rsync://rsync.gentoo.org/gentoo-portage")
+
+ @mock.patch('snakeoil.process.find_binary')
+ def test_uri_parse_rsync_missing(self, find_binary, spawn, getaddrinfo):
+ find_binary.side_effect = CommandNotFound('rsync')
+ with pytest.raises(base.SyncError):
+ self._syncer_class(self.repo_path, 'rsync://foon.com/dar')
+
+ @mock.patch('snakeoil.process.find_binary')
+ def test_uri_parse(self, find_binary, spawn, getaddrinfo):
+ find_binary.side_effect = lambda x: x
+ o = self._syncer_class(self.repo_path, 'rsync://dar/module')
+ assert o.uri == 'rsync://dar/module/'
+ assert o.rsh == None
+
+ o = self._syncer_class(self.repo_path, 'rsync+/bin/sh://dar/module')
+ assert o.uri == 'rsync://dar/module/'
+ assert o.rsh == '/bin/sh'
+
+ def test_successful_sync(self, spawn, getaddrinfo):
spawn.return_value = 0
assert self.syncer.sync()
spawn.assert_called_once()
- def test_bad_syntax_sync(self, spawn, getaddrinfo, find_binary):
+ def test_bad_syntax_sync(self, spawn, getaddrinfo):
spawn.return_value = 1
with pytest.raises(base.SyncError) as excinfo:
assert self.syncer.sync()
assert str(excinfo.value).startswith('rsync command syntax error:')
spawn.assert_called_once()
- def test_failed_disk_space_sync(self, spawn, getaddrinfo, find_binary):
+ def test_failed_disk_space_sync(self, spawn, getaddrinfo):
spawn.return_value = 11
with pytest.raises(base.SyncError) as excinfo:
assert self.syncer.sync()
assert str(excinfo.value) == 'rsync ran out of disk space'
spawn.assert_called_once()
- def test_retried_sync(self, spawn, getaddrinfo, find_binary):
+ def test_retried_sync(self, spawn, getaddrinfo):
spawn.return_value = 99
with pytest.raises(base.SyncError) as excinfo:
assert self.syncer.sync()
@@ -76,7 +77,7 @@ class TestRsyncSyncer(object):
# rsync should retry every resolved IP related to the sync URI
assert len(spawn.mock_calls) == 3
- def test_retried_sync_max_retries(self, spawn, getaddrinfo, find_binary):
+ def test_retried_sync_max_retries(self, spawn, getaddrinfo):
spawn.return_value = 99
# generate more IPs than retries
getaddrinfo.return_value = fake_ips(self.syncer.retries + 1)
@@ -85,7 +86,7 @@ class TestRsyncSyncer(object):
assert str(excinfo.value) == 'all attempts failed'
assert len(spawn.mock_calls) == self.syncer.retries
- def test_failed_dns_sync(self, spawn, getaddrinfo, find_binary):
+ def test_failed_dns_sync(self, spawn, getaddrinfo):
getaddrinfo.side_effect = OSError()
with pytest.raises(base.SyncError) as excinfo:
assert self.syncer.sync()