diff options
Diffstat (limited to 'test/testdata/eval-okay-convertHash.nix')
-rw-r--r-- | test/testdata/eval-okay-convertHash.nix | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/testdata/eval-okay-convertHash.nix b/test/testdata/eval-okay-convertHash.nix new file mode 100644 index 0000000..a0191ee --- /dev/null +++ b/test/testdata/eval-okay-convertHash.nix | |||
@@ -0,0 +1,33 @@ | |||
1 | let | ||
2 | hashAlgos = [ "md5" "md5" "md5" "sha1" "sha1" "sha1" "sha256" "sha256" "sha256" "sha512" "sha512" "sha512" ]; | ||
3 | hashesBase16 = import ./eval-okay-hashstring.exp; | ||
4 | map2 = f: { fsts, snds }: if fsts == [ ] then [ ] else [ (f (builtins.head fsts) (builtins.head snds)) ] ++ map2 f { fsts = builtins.tail fsts; snds = builtins.tail snds; }; | ||
5 | map2' = f: fsts: snds: map2 f { inherit fsts snds; }; | ||
6 | getOutputHashes = hashes: { | ||
7 | hashesBase16 = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "base16";}) hashAlgos hashes; | ||
8 | hashesNix32 = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "nix32";}) hashAlgos hashes; | ||
9 | hashesBase32 = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "base32";}) hashAlgos hashes; | ||
10 | hashesBase64 = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "base64";}) hashAlgos hashes; | ||
11 | hashesSRI = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "sri" ;}) hashAlgos hashes; | ||
12 | }; | ||
13 | getOutputHashesColon = hashes: { | ||
14 | hashesBase16 = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "base16";}) hashAlgos hashes; | ||
15 | hashesNix32 = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "nix32";}) hashAlgos hashes; | ||
16 | hashesBase32 = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "base32";}) hashAlgos hashes; | ||
17 | hashesBase64 = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "base64";}) hashAlgos hashes; | ||
18 | hashesSRI = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "sri" ;}) hashAlgos hashes; | ||
19 | }; | ||
20 | outputHashes = getOutputHashes hashesBase16; | ||
21 | in | ||
22 | # map2'` | ||
23 | assert map2' (s1: s2: s1 + s2) [ "a" "b" ] [ "c" "d" ] == [ "ac" "bd" ]; | ||
24 | # hashesBase16 | ||
25 | assert outputHashes.hashesBase16 == hashesBase16; | ||
26 | # standard SRI hashes | ||
27 | assert outputHashes.hashesSRI == (map2' (hashAlgo: hashBody: hashAlgo + "-" + hashBody) hashAlgos outputHashes.hashesBase64); | ||
28 | # without prefix | ||
29 | assert builtins.all (x: getOutputHashes x == outputHashes) (builtins.attrValues outputHashes); | ||
30 | # colon-separated. | ||
31 | # Note that colon prefix must not be applied to the standard SRI. e.g. "sha256:sha256-..." is illegal. | ||
32 | assert builtins.all (x: getOutputHashesColon x == outputHashes) (with outputHashes; [ hashesBase16 hashesBase32 hashesBase64 ]); | ||
33 | outputHashes | ||