1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import json
import subprocess
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
class CrateFetchTests(unittest.TestCase):
def evaluate(self, attrs):
expression = (
f"let fetch = import {ROOT}/nix/fetch-crate.nix (args: args); "
f"in fetch (builtins.fromJSON {json.dumps(json.dumps(attrs))})"
)
return json.loads(
subprocess.check_output(
["nix", "eval", "--impure", "--json", "--expr", expression], text=True
)
)
def test_crate_uses_static_archive_and_keeps_hash(self):
attrs = {
"name": "download-hashbrown-0.16.1",
"url": "https://crates.io/api/v1/crates/hashbrown/0.16.1/download",
"sha256": "locked-checksum",
}
self.assertEqual(
self.evaluate(attrs),
{
**attrs,
"url": "https://static.crates.io/crates/hashbrown/hashbrown-0.16.1.crate",
},
)
def test_other_downloads_are_unchanged(self):
attrs = {"url": "https://example.org/source.tar.gz", "hash": "unchanged"}
self.assertEqual(self.evaluate(attrs), attrs)
def test_url_lists_are_unchanged(self):
attrs = {"urls": ["https://example.org/source.tar.gz"], "hash": "unchanged"}
self.assertEqual(self.evaluate(attrs), attrs)
|