|
11 | 11 | import tempfile
|
12 | 12 | import unittest
|
13 | 13 | from dataclasses import astuple, dataclass, field
|
14 |
| -from typing import Iterable, List, Optional, Tuple |
| 14 | +from typing import Iterable, List, Optional |
15 | 15 |
|
16 | 16 | from tests import utils
|
17 | 17 | from tests.repository_simulator import RepositorySimulator
|
@@ -53,6 +53,13 @@ class DelegationsTestCase:
|
53 | 53 | visited_order: List[str] = field(default_factory=list)
|
54 | 54 |
|
55 | 55 |
|
| 56 | +@dataclass |
| 57 | +class TargetTestCase: |
| 58 | + targetpath: str |
| 59 | + found: bool |
| 60 | + visited_order: List[str] = field(default_factory=list) |
| 61 | + |
| 62 | + |
56 | 63 | class TestDelegations(unittest.TestCase):
|
57 | 64 | """Base class for delegation tests"""
|
58 | 65 |
|
@@ -358,35 +365,39 @@ def setUp(self) -> None:
|
358 | 365 |
|
359 | 366 | # fmt: off
|
360 | 367 | targets: utils.DataSet = {
|
361 |
| - "target found, no delegations": ("targetfile", True, []), |
362 |
| - "targetpath matches wildcard": ("README.md", True, ["A"]), |
363 |
| - "targetpath with separators x": ("releases/x/x_v1", True, ["B", "C"]), |
364 |
| - "targetpath with separators y": ("releases/y/y_v1.zip", True, ["B", "D"]), |
365 |
| - "target exists, path is not delegated": ("releases/z/z_v1.zip", False, ["B"]), |
| 368 | + "no delegations": |
| 369 | + TargetTestCase("targetfile", True, []), |
| 370 | + "targetpath matches wildcard": |
| 371 | + TargetTestCase("README.md", True, ["A"]), |
| 372 | + "targetpath with separators x": |
| 373 | + TargetTestCase("releases/x/x_v1", True, ["B", "C"]), |
| 374 | + "targetpath with separators y": |
| 375 | + TargetTestCase("releases/y/y_v1.zip", True, ["B", "D"]), |
| 376 | + "targetpath is not delegated by all roles in the chain": |
| 377 | + TargetTestCase("releases/z/z_v1.zip", False, ["B"]), |
366 | 378 | }
|
367 | 379 | # fmt: on
|
368 | 380 |
|
369 | 381 | @utils.run_sub_tests_with_dataset(targets)
|
370 |
| - def test_targetfile_search( |
371 |
| - self, test_data: Tuple[str, bool, List[str]] |
372 |
| - ) -> None: |
| 382 | + def test_targetfile_search(self, test_data: TargetTestCase) -> None: |
373 | 383 | try:
|
374 | 384 | self.setup_subtest()
|
375 |
| - targetpath, found, visited_order = test_data |
376 |
| - exp_files = [*TOP_LEVEL_ROLE_NAMES, *visited_order] |
377 |
| - exp_calls = [(role, 1) for role in visited_order] |
| 385 | + # targetpath, found, visited_order = test_data |
| 386 | + exp_files = [*TOP_LEVEL_ROLE_NAMES, *test_data.visited_order] |
| 387 | + exp_calls = [(role, 1) for role in test_data.visited_order] |
| 388 | + exp_target = self.sim.target_files[test_data.targetpath].target_file |
| 389 | + |
378 | 390 | updater = self._init_updater()
|
379 | 391 | # Call explicitly refresh to simplify the expected_calls list
|
380 | 392 | updater.refresh()
|
381 | 393 | self.sim.fetch_tracker.metadata.clear()
|
382 |
| - target = updater.get_targetinfo(targetpath) |
| 394 | + target = updater.get_targetinfo(test_data.targetpath) |
383 | 395 | if target is not None:
|
384 | 396 | # Confirm that the expected TargetFile is found
|
385 |
| - self.assertTrue(found) |
386 |
| - exp_target = self.sim.target_files[targetpath].target_file |
| 397 | + self.assertTrue(test_data.found) |
387 | 398 | self.assertDictEqual(target.to_dict(), exp_target.to_dict())
|
388 | 399 | else:
|
389 |
| - self.assertFalse(found) |
| 400 | + self.assertFalse(test_data.found) |
390 | 401 | # Check that the delegated roles were visited in the expected
|
391 | 402 | # order and the corresponding metadata files were persisted
|
392 | 403 | self.assertListEqual(self.sim.fetch_tracker.metadata, exp_calls)
|
|
0 commit comments