Skip to content

Commit 01b30cc

Browse files
committed
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 <[email protected]>
1 parent 7d389f3 commit 01b30cc

File tree

2 files changed

+30
-39
lines changed

2 files changed

+30
-39
lines changed

tests/test_updater_delegation_graphs.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -510,45 +510,6 @@ def test_succinct_roles_graph_traversal(
510510
finally:
511511
self.teardown_subtest()
512512

513-
def test_download_targets_with_succinct_roles(self) -> None:
514-
try:
515-
self.setup_subtest()
516-
self.sim = RepositorySimulator()
517-
self.sim.add_succinct_roles("targets", 8, "bin")
518-
self.sim.update_snapshot()
519-
520-
assert self.sim.targets.delegations is not None
521-
assert self.sim.targets.delegations.succinct_roles is not None
522-
succinct_roles = self.sim.targets.delegations.succinct_roles
523-
524-
# Add lots of targets with unique data to imitate a real repository.
525-
for i in range(1000):
526-
target_name = f"target-{i}"
527-
target_bin = succinct_roles.get_role_for_target(target_name)
528-
self.sim.add_target(
529-
target_bin, bytes(target_name, "utf-8"), target_name
530-
)
531-
532-
updater = self._init_updater()
533-
# Call explicitly refresh to simplify the expected_calls list.
534-
updater.refresh()
535-
536-
for i in range(1000):
537-
# Verify that the target info was successfully found.
538-
target_info = updater.get_targetinfo(f"target-{i}")
539-
assert target_info is not None
540-
target_full_path = updater.download_target(target_info)
541-
542-
# Verify that the target content is the same as the target name.
543-
with open(target_full_path, encoding="utf-8") as target:
544-
target_content = target.readline()
545-
self.assertEqual(
546-
target_content, os.path.basename(target_full_path)
547-
)
548-
549-
finally:
550-
self.teardown_subtest()
551-
552513

553514
class TestTargetFileSearch(TestDelegations):
554515
r"""

tests/test_updater_fetch_target.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,36 @@ def test_fetch_target(self, target: TestTarget) -> None:
121121
self.assertEqual(path, updater.find_cached_target(info))
122122
self.assertEqual(path, updater.find_cached_target(info, path))
123123

124+
def test_download_targets_with_succinct_roles(self) -> None:
125+
self.sim.add_succinct_roles("targets", 8, "bin")
126+
self.sim.update_snapshot()
127+
128+
assert self.sim.targets.delegations is not None
129+
assert self.sim.targets.delegations.succinct_roles is not None
130+
succinct_roles = self.sim.targets.delegations.succinct_roles
131+
132+
# Add lots of targets with unique data to imitate a real repository.
133+
for i in range(20):
134+
target_name = f"target-{i}"
135+
target_bin = succinct_roles.get_role_for_target(target_name)
136+
self.sim.add_target(
137+
target_bin, bytes(target_name, "utf-8"), target_name
138+
)
139+
140+
# download each target
141+
updater = self._init_updater()
142+
for i in range(20):
143+
target_name = f"target-{i}"
144+
145+
# Verify that the target info was successfully found.
146+
target_info = updater.get_targetinfo(target_name)
147+
assert target_info is not None
148+
target_full_path = updater.download_target(target_info)
149+
150+
# Verify that the target content is the same as the target name.
151+
with open(target_full_path, encoding="utf-8") as target:
152+
self.assertEqual(target.read(), target_name)
153+
124154
def test_invalid_target_download(self) -> None:
125155
target = TestTarget("targetpath", b"content", "targetpath")
126156

0 commit comments

Comments
 (0)