mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
tests: Improve succinct download test
* move to the test file that contains all the other download tests * don't write 1000 files: it can be slow in CI * Compare file content to what was originally written (also read the whole file content) * Remove try-except that seems unused Signed-off-by: Jussi Kukkonen <jku@goto.fi>
This commit is contained in:
parent
7d389f3fcd
commit
01b30ccd2d
2 changed files with 30 additions and 39 deletions
|
|
@ -510,45 +510,6 @@ def test_succinct_roles_graph_traversal(
|
|||
finally:
|
||||
self.teardown_subtest()
|
||||
|
||||
def test_download_targets_with_succinct_roles(self) -> None:
|
||||
try:
|
||||
self.setup_subtest()
|
||||
self.sim = RepositorySimulator()
|
||||
self.sim.add_succinct_roles("targets", 8, "bin")
|
||||
self.sim.update_snapshot()
|
||||
|
||||
assert self.sim.targets.delegations is not None
|
||||
assert self.sim.targets.delegations.succinct_roles is not None
|
||||
succinct_roles = self.sim.targets.delegations.succinct_roles
|
||||
|
||||
# Add lots of targets with unique data to imitate a real repository.
|
||||
for i in range(1000):
|
||||
target_name = f"target-{i}"
|
||||
target_bin = succinct_roles.get_role_for_target(target_name)
|
||||
self.sim.add_target(
|
||||
target_bin, bytes(target_name, "utf-8"), target_name
|
||||
)
|
||||
|
||||
updater = self._init_updater()
|
||||
# Call explicitly refresh to simplify the expected_calls list.
|
||||
updater.refresh()
|
||||
|
||||
for i in range(1000):
|
||||
# Verify that the target info was successfully found.
|
||||
target_info = updater.get_targetinfo(f"target-{i}")
|
||||
assert target_info is not None
|
||||
target_full_path = updater.download_target(target_info)
|
||||
|
||||
# Verify that the target content is the same as the target name.
|
||||
with open(target_full_path, encoding="utf-8") as target:
|
||||
target_content = target.readline()
|
||||
self.assertEqual(
|
||||
target_content, os.path.basename(target_full_path)
|
||||
)
|
||||
|
||||
finally:
|
||||
self.teardown_subtest()
|
||||
|
||||
|
||||
class TestTargetFileSearch(TestDelegations):
|
||||
r"""
|
||||
|
|
|
|||
|
|
@ -121,6 +121,36 @@ def test_fetch_target(self, target: TestTarget) -> None:
|
|||
self.assertEqual(path, updater.find_cached_target(info))
|
||||
self.assertEqual(path, updater.find_cached_target(info, path))
|
||||
|
||||
def test_download_targets_with_succinct_roles(self) -> None:
|
||||
self.sim.add_succinct_roles("targets", 8, "bin")
|
||||
self.sim.update_snapshot()
|
||||
|
||||
assert self.sim.targets.delegations is not None
|
||||
assert self.sim.targets.delegations.succinct_roles is not None
|
||||
succinct_roles = self.sim.targets.delegations.succinct_roles
|
||||
|
||||
# Add lots of targets with unique data to imitate a real repository.
|
||||
for i in range(20):
|
||||
target_name = f"target-{i}"
|
||||
target_bin = succinct_roles.get_role_for_target(target_name)
|
||||
self.sim.add_target(
|
||||
target_bin, bytes(target_name, "utf-8"), target_name
|
||||
)
|
||||
|
||||
# download each target
|
||||
updater = self._init_updater()
|
||||
for i in range(20):
|
||||
target_name = f"target-{i}"
|
||||
|
||||
# Verify that the target info was successfully found.
|
||||
target_info = updater.get_targetinfo(target_name)
|
||||
assert target_info is not None
|
||||
target_full_path = updater.download_target(target_info)
|
||||
|
||||
# Verify that the target content is the same as the target name.
|
||||
with open(target_full_path, encoding="utf-8") as target:
|
||||
self.assertEqual(target.read(), target_name)
|
||||
|
||||
def test_invalid_target_download(self) -> None:
|
||||
target = TestTarget("targetpath", b"content", "targetpath")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue