Skip to content

Commit d9c808f

Browse files
committed
refactor(tests/nixos/s3-binary-cache-store): add verify_packages_in_store helper
1 parent 55ea3d3 commit d9c808f

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

tests/nixos/s3-binary-cache-store.nix

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ in
131131
print(output)
132132
raise Exception(f"{error_msg}: expected {expected}, got {actual}")
133133
134+
def verify_packages_in_store(machine, pkg_paths, should_exist=True):
135+
"""
136+
Verify whether packages exist in the store.
137+
138+
Args:
139+
machine: The machine to check on
140+
pkg_paths: List of package paths to check (or single path)
141+
should_exist: If True, verify packages exist; if False, verify they don't
142+
"""
143+
paths = [pkg_paths] if isinstance(pkg_paths, str) else pkg_paths
144+
for pkg in paths:
145+
if should_exist:
146+
machine.succeed(f"nix path-info {pkg}")
147+
else:
148+
machine.fail(f"nix path-info {pkg}")
149+
134150
def setup_s3(populate_bucket=[], public=False):
135151
"""
136152
Decorator that creates/destroys a unique bucket for each test.
@@ -321,7 +337,7 @@ in
321337
print(f" ✓ Store URL: {store_info['url']}")
322338
323339
# Test copy from store
324-
client.fail(f"nix path-info {PKGS['A']}")
340+
verify_packages_in_store(client, PKGS['A'], should_exist=False)
325341
326342
output = client.succeed(
327343
f"{ENV_WITH_CREDS} nix copy --debug --no-check-sigs "
@@ -335,7 +351,7 @@ in
335351
"Client credential provider caching failed"
336352
)
337353
338-
client.succeed(f"nix path-info {PKGS['A']}")
354+
verify_packages_in_store(client, [PKGS['A'], PKGS['B'], PKGS['C']])
339355
340356
print(" ✓ nix copy works")
341357
print(" ✓ Credentials cached on client")
@@ -361,8 +377,7 @@ in
361377
print(f" ✓ Store URL: {store_info['url']}")
362378
363379
# Verify packages are not yet in client store
364-
client.fail(f"nix path-info {PKGS['A']}")
365-
client.fail(f"nix path-info {PKGS['B']}")
380+
verify_packages_in_store(client, [PKGS['A'], PKGS['B']], should_exist=False)
366381
367382
# Test copy from public bucket without credentials
368383
client.succeed(
@@ -371,8 +386,7 @@ in
371386
)
372387
373388
# Verify packages were copied successfully
374-
client.succeed(f"nix path-info {PKGS['A']}")
375-
client.succeed(f"nix path-info {PKGS['B']}")
389+
verify_packages_in_store(client, [PKGS['A'], PKGS['B']])
376390
377391
print(" ✓ nix copy from public bucket works without credentials")
378392
@@ -475,7 +489,7 @@ in
475489
476490
# Verify client can download and decompress
477491
client.succeed(f"{ENV_WITH_CREDS} nix copy --from '{store_url}' --no-check-sigs {PKGS['B']}")
478-
client.succeed(f"nix path-info {PKGS['B']}")
492+
verify_packages_in_store(client, PKGS['B'])
479493
480494
print(" ✓ Client decompressed .narinfo successfully")
481495
@@ -503,7 +517,7 @@ in
503517
504518
# Verify client can download with mixed compression
505519
client.succeed(f"{ENV_WITH_CREDS} nix copy --from '{store_url}' --no-check-sigs {PKGS['C']}")
506-
client.succeed(f"nix path-info {PKGS['C']}")
520+
verify_packages_in_store(client, PKGS['C'])
507521
508522
print(" ✓ Client downloaded package with mixed compression")
509523

0 commit comments

Comments
 (0)