Skip to content

Commit 56b14f0

Browse files
author
Martin Vrachev
committed
Downloading from a repository with many targets
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent e94dca6 commit 56b14f0

1 file changed

Lines changed: 25 additions & 46 deletions

File tree

tests/test_updater_delegation_graphs.py

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -510,62 +510,41 @@ def test_succinct_roles_graph_traversal(
510510
finally:
511511
self.teardown_subtest()
512512

513-
succinct_roles_targets_test_cases: utils.DataSet = {
514-
"bin amount = 2, taget bin index 0": SuccinctRolesTestCase(
515-
bit_length=1,
516-
target_path="boo",
517-
expected_target_bin="bin-0",
518-
),
519-
"bin amount = 4, taget bin index 0": SuccinctRolesTestCase(
520-
bit_length=2,
521-
target_path="foo",
522-
expected_target_bin="bin-0",
523-
),
524-
"bin amount = 256, taget bin index fc": SuccinctRolesTestCase(
525-
bit_length=8,
526-
target_path="bar",
527-
expected_target_bin="bin-fc",
528-
),
529-
}
530-
531-
@utils.run_sub_tests_with_dataset(succinct_roles_targets_test_cases)
532-
def test_download_targets_with_succinct_roles(
533-
self, test_data: SuccinctRolesTestCase
534-
) -> None:
535-
513+
def test_download_targets_with_succinct_roles(self) -> None:
536514
try:
537515
self.setup_subtest()
538-
exp_files = [*TOP_LEVEL_ROLE_NAMES, test_data.expected_target_bin]
539-
exp_calls = [(test_data.expected_target_bin, 1)]
540-
exp_path = os.path.join(self.targets_dir, test_data.target_path)
541-
542516
self.sim = RepositorySimulator()
543-
self.sim.add_succinct_roles("targets", test_data.bit_length, "bin")
517+
self.sim.add_succinct_roles("targets", 8, "bin")
544518
self.sim.update_snapshot()
545519

546-
self.sim.add_target(
547-
test_data.expected_target_bin, b"abc", test_data.target_path
548-
)
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+
)
549531

550532
updater = self._init_updater()
551533
# Call explicitly refresh to simplify the expected_calls list.
552534
updater.refresh()
553-
self.sim.fetch_tracker.metadata.clear()
554-
# Check that metadata dir contains only top-level roles
555-
self._assert_files_exist(TOP_LEVEL_ROLE_NAMES)
556-
557-
# Verify that the target info was successfully found
558-
# and the correct delegated metadata file was downloaded
559-
target_info = updater.get_targetinfo(test_data.target_path)
560-
assert target_info is not None
561-
self.assertEqual(target_info.path, test_data.target_path)
562-
target_file = updater.download_target(target_info)
563-
self.assertEqual(target_file, exp_path)
564535

565-
# Check that the delegated roles were visited in the expected
566-
# order and the corresponding metadata files were persisted.
567-
self.assertListEqual(self.sim.fetch_tracker.metadata, exp_calls)
568-
self._assert_files_exist(exp_files)
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) as target:
544+
target_content = target.readline()
545+
self.assertEqual(
546+
target_content, os.path.basename(target_full_path)
547+
)
569548

570549
finally:
571550
self.teardown_subtest()

0 commit comments

Comments
 (0)