Skip to content

Commit e94dca6

Browse files
author
Martin Vrachev
committed
Tests: download a target with succonct_roles
Add test downloading a target file when succonct_roles is used and as such test the whole updater downloading workflow. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent e07fa27 commit e94dca6

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/test_updater_delegation_graphs.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,66 @@ 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+
536+
try:
537+
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+
542+
self.sim = RepositorySimulator()
543+
self.sim.add_succinct_roles("targets", test_data.bit_length, "bin")
544+
self.sim.update_snapshot()
545+
546+
self.sim.add_target(
547+
test_data.expected_target_bin, b"abc", test_data.target_path
548+
)
549+
550+
updater = self._init_updater()
551+
# Call explicitly refresh to simplify the expected_calls list.
552+
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)
564+
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)
569+
570+
finally:
571+
self.teardown_subtest()
572+
513573

514574
class TestTargetFileSearch(TestDelegations):
515575
r"""

0 commit comments

Comments
 (0)