Skip to content

Commit 3308c29

Browse files
authored
Merge pull request #2031 from MVrachev/tap15-download-target-test
Tests: download a target with succinct_roles enabled
2 parents 7da578f + 01b30cc commit 3308c29

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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)