mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-21 04:10:37 +02:00
fix(deploy): add test cases for local copy mode and fix issues
This commit is contained in:
parent
160c23a547
commit
5e3b474a1c
@ -29,6 +29,7 @@
|
|||||||
# libraries here as they will become a requirement for all commands.
|
# libraries here as they will become a requirement for all commands.
|
||||||
|
|
||||||
import difflib
|
import difflib
|
||||||
|
from typing import List
|
||||||
import git
|
import git
|
||||||
import glob
|
import glob
|
||||||
import io
|
import io
|
||||||
@ -4300,7 +4301,7 @@ def get_app_display_name(app):
|
|||||||
return app.get('AutoName') or app['id']
|
return app.get('AutoName') or app['id']
|
||||||
|
|
||||||
|
|
||||||
def local_rsync(options, fromdir, todir):
|
def local_rsync(options, fromdir, todir, args: List[str] = []):
|
||||||
"""Rsync method for local to local copying of things.
|
"""Rsync method for local to local copying of things.
|
||||||
|
|
||||||
This is an rsync wrapper with all the settings for safe use within
|
This is an rsync wrapper with all the settings for safe use within
|
||||||
@ -4317,6 +4318,7 @@ def local_rsync(options, fromdir, todir):
|
|||||||
rsyncargs += ['--verbose']
|
rsyncargs += ['--verbose']
|
||||||
if options.quiet:
|
if options.quiet:
|
||||||
rsyncargs += ['--quiet']
|
rsyncargs += ['--quiet']
|
||||||
|
rsyncargs += args
|
||||||
logging.debug(' '.join(rsyncargs + [fromdir, todir]))
|
logging.debug(' '.join(rsyncargs + [fromdir, todir]))
|
||||||
if subprocess.call(rsyncargs + [fromdir, todir]) != 0:
|
if subprocess.call(rsyncargs + [fromdir, todir]) != 0:
|
||||||
raise FDroidException()
|
raise FDroidException()
|
||||||
|
@ -561,9 +561,11 @@ def sync_from_localcopy(repo_section, local_copy_dir):
|
|||||||
"""
|
"""
|
||||||
logging.info('Syncing from local_copy_dir to this repo.')
|
logging.info('Syncing from local_copy_dir to this repo.')
|
||||||
if options.index_only:
|
if options.index_only:
|
||||||
|
rsyncargs = ['--include', "*/"] + _get_index_includes(repo_section) + ['--exclude', '*']
|
||||||
common.local_rsync(common.get_options(),
|
common.local_rsync(common.get_options(),
|
||||||
_get_index_includes(local_copy_dir),
|
_get_index_includes(local_copy_dir),
|
||||||
repo_section.rstrip('/') + '/')
|
repo_section.rstrip('/') + '/',
|
||||||
|
args=rsyncargs)
|
||||||
else:
|
else:
|
||||||
# trailing slashes have a meaning in rsync which is not needed here, so
|
# trailing slashes have a meaning in rsync which is not needed here, so
|
||||||
# make sure both paths have exactly one trailing slash
|
# make sure both paths have exactly one trailing slash
|
||||||
@ -588,9 +590,11 @@ def update_localcopy(repo_section, local_copy_dir):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if options.index_only:
|
if options.index_only:
|
||||||
|
rsyncargs = ['--include', "*/"] + _get_index_includes(repo_section) + ['--exclude', '*']
|
||||||
common.local_rsync(common.get_options(),
|
common.local_rsync(common.get_options(),
|
||||||
_get_index_includes(repo_section),
|
_get_index_includes(repo_section),
|
||||||
repo_section.rstrip('/') + '/')
|
local_copy_dir,
|
||||||
|
args=rsyncargs)
|
||||||
else:
|
else:
|
||||||
# local_copy_dir is guaranteed to have a trailing slash in main() below
|
# local_copy_dir is guaranteed to have a trailing slash in main() below
|
||||||
common.local_rsync(common.get_options(), repo_section, local_copy_dir)
|
common.local_rsync(common.get_options(), repo_section, local_copy_dir)
|
||||||
|
@ -555,6 +555,66 @@ class DeployTest(unittest.TestCase):
|
|||||||
fdroidserver.deploy.update_serverwebroot(serverwebroot, repo_section)
|
fdroidserver.deploy.update_serverwebroot(serverwebroot, repo_section)
|
||||||
self.assertEqual(call_iteration, 1, 'expected 1 invocations of subprocess.call')
|
self.assertEqual(call_iteration, 1, 'expected 1 invocations of subprocess.call')
|
||||||
|
|
||||||
|
def test_update_localcopy_in_index_only_mode(self):
|
||||||
|
# setup parameters for this test run
|
||||||
|
fdroidserver.deploy.options.no_chcksum = False
|
||||||
|
fdroidserver.deploy.options.verbose = True
|
||||||
|
fdroidserver.deploy.options.quiet = False
|
||||||
|
fdroidserver.deploy.options.identity_file = None
|
||||||
|
fdroidserver.deploy.options.index_only = True
|
||||||
|
repo_section = 'repo'
|
||||||
|
|
||||||
|
# setup function for asserting subprocess.call invocations
|
||||||
|
call_iteration = 0
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as local_copy_dir:
|
||||||
|
def update_localcopy_call(cmd):
|
||||||
|
nonlocal call_iteration
|
||||||
|
if call_iteration == 0:
|
||||||
|
self.assertListEqual(
|
||||||
|
cmd,
|
||||||
|
[
|
||||||
|
'rsync',
|
||||||
|
'--recursive', '--safe-links', '--times', '--perms',
|
||||||
|
'--one-file-system', '--delete', '--chmod=Da+rx,Fa-x,a+r,u+w',
|
||||||
|
'--verbose',
|
||||||
|
'--include',
|
||||||
|
"*/",
|
||||||
|
'--include',
|
||||||
|
'repo/entry.jar',
|
||||||
|
'--include',
|
||||||
|
'repo/entry.json',
|
||||||
|
'--include',
|
||||||
|
'repo/entry.json.asc',
|
||||||
|
'--include',
|
||||||
|
'repo/index-v1.jar',
|
||||||
|
'--include',
|
||||||
|
'repo/index-v1.json',
|
||||||
|
'--include',
|
||||||
|
'repo/index-v1.json.asc',
|
||||||
|
'--include',
|
||||||
|
'repo/index-v2.json',
|
||||||
|
'--include',
|
||||||
|
'repo/index-v2.json.asc',
|
||||||
|
'--include',
|
||||||
|
'repo/index.jar',
|
||||||
|
'--include',
|
||||||
|
'repo/index.xml',
|
||||||
|
'--exclude',
|
||||||
|
"*",
|
||||||
|
'repo',
|
||||||
|
local_copy_dir,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.fail('unexpected subprocess.call invocation')
|
||||||
|
call_iteration += 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
with mock.patch('subprocess.call', side_effect=update_localcopy_call):
|
||||||
|
fdroidserver.deploy.update_localcopy(repo_section, local_copy_dir)
|
||||||
|
self.assertEqual(call_iteration, 1, 'expected 1 invocations of subprocess.call')
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
not os.getenv('VIRUSTOTAL_API_KEY'), 'VIRUSTOTAL_API_KEY is not set'
|
not os.getenv('VIRUSTOTAL_API_KEY'), 'VIRUSTOTAL_API_KEY is not set'
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user