|
1 | 1 | { |
2 | | - lib, |
3 | 2 | config, |
4 | | - nixpkgs, |
5 | 3 | ... |
6 | 4 | }: |
7 | 5 |
|
|
147 | 145 | else: |
148 | 146 | machine.fail(f"nix path-info {pkg}") |
149 | 147 |
|
150 | | - def setup_s3(populate_bucket=[], public=False): |
| 148 | + def setup_s3(populate_bucket=[], public=False, versioned=False): |
151 | 149 | """ |
152 | 150 | Decorator that creates/destroys a unique bucket for each test. |
153 | 151 | Optionally pre-populates bucket with specified packages. |
|
156 | 154 | Args: |
157 | 155 | populate_bucket: List of packages to upload before test runs |
158 | 156 | public: If True, make the bucket publicly accessible |
| 157 | + versioned: If True, enable versioning on the bucket before populating |
159 | 158 | """ |
160 | 159 | def decorator(test_func): |
161 | 160 | def wrapper(): |
162 | 161 | bucket = str(uuid.uuid4()) |
163 | 162 | server.succeed(f"mc mb minio/{bucket}") |
164 | | - if public: |
165 | | - server.succeed(f"mc anonymous set download minio/{bucket}") |
166 | 163 | try: |
| 164 | + if public: |
| 165 | + server.succeed(f"mc anonymous set download minio/{bucket}") |
| 166 | + if versioned: |
| 167 | + server.succeed(f"mc version enable minio/{bucket}") |
167 | 168 | if populate_bucket: |
168 | 169 | store_url = make_s3_url(bucket) |
169 | 170 | for pkg in populate_bucket: |
|
597 | 598 |
|
598 | 599 | print(" ✓ File content verified correct (hash matches)") |
599 | 600 |
|
| 601 | + @setup_s3(populate_bucket=[PKGS['A']], versioned=True) |
| 602 | + def test_versioned_urls(bucket): |
| 603 | + """Test that versionId parameter is accepted in S3 URLs""" |
| 604 | + print("\n=== Testing Versioned URLs ===") |
| 605 | +
|
| 606 | + # Get the nix-cache-info file |
| 607 | + cache_info_url = make_s3_url(bucket, path="/nix-cache-info") |
| 608 | +
|
| 609 | + # Fetch without versionId should work |
| 610 | + client.succeed( |
| 611 | + f"{ENV_WITH_CREDS} nix eval --impure --expr " |
| 612 | + f"'builtins.fetchurl {{ name = \"cache-info\"; url = \"{cache_info_url}\"; }}'" |
| 613 | + ) |
| 614 | + print(" ✓ Fetch without versionId works") |
| 615 | +
|
| 616 | + # List versions to get a version ID |
| 617 | + # MinIO output format: [timestamp] size tier versionId versionNumber method filename |
| 618 | + versions_output = server.succeed(f"mc ls --versions minio/{bucket}/nix-cache-info") |
| 619 | +
|
| 620 | + # Extract version ID from output (4th field after STANDARD) |
| 621 | + import re |
| 622 | + version_match = re.search(r'STANDARD\s+(\S+)\s+v\d+', versions_output) |
| 623 | + if not version_match: |
| 624 | + print(f"Debug: versions output: {versions_output}") |
| 625 | + raise Exception("Could not extract version ID from MinIO output") |
| 626 | +
|
| 627 | + version_id = version_match.group(1) |
| 628 | + print(f" ✓ Found version ID: {version_id}") |
| 629 | +
|
| 630 | + # Version ID should not be "null" since versioning was enabled before upload |
| 631 | + if version_id == "null": |
| 632 | + raise Exception("Version ID is 'null' - versioning may not be working correctly") |
| 633 | +
|
| 634 | + # Fetch with versionId parameter |
| 635 | + versioned_url = f"{cache_info_url}&versionId={version_id}" |
| 636 | + client.succeed( |
| 637 | + f"{ENV_WITH_CREDS} nix eval --impure --expr " |
| 638 | + f"'builtins.fetchurl {{ name = \"cache-info-versioned\"; url = \"{versioned_url}\"; }}'" |
| 639 | + ) |
| 640 | + print(" ✓ Fetch with versionId parameter works") |
| 641 | +
|
600 | 642 | # ============================================================================ |
601 | 643 | # Main Test Execution |
602 | 644 | # ============================================================================ |
|
626 | 668 | test_compression_mixed() |
627 | 669 | test_compression_disabled() |
628 | 670 | test_nix_prefetch_url() |
| 671 | + test_versioned_urls() |
629 | 672 |
|
630 | 673 | print("\n" + "="*80) |
631 | 674 | print("✓ All S3 Binary Cache Store Tests Passed!") |
|
0 commit comments