tests.overriding: tests-fetchgit: use generated non-zero hashes
Don't use zero hashes where the hash is supposed to be non-zero. Don't depend on nix.src.hash as nix.src might be wrapped to accept patches.
This commit is contained in:
@@ -148,11 +148,41 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
Take two positional arguments `fakeHash` and `partialHash`,
|
||||
and return a modified version of fakeHash whose hash body is partially substituted by `partialHash` from the beginning,
|
||||
used to assert a specific fake hash variant is used by an overridden FOD.
|
||||
|
||||
# Inputs
|
||||
|
||||
`fakeHash`
|
||||
|
||||
: The specified zero fake hash
|
||||
|
||||
`partialHash`
|
||||
|
||||
: A trimmed non-zero hash body, to substitute the beginning of the zero hash body.
|
||||
*/
|
||||
genNonzeroFakeHash =
|
||||
fakeHash:
|
||||
let
|
||||
isSRIHash = lib.hasInfix "-" fakeHash;
|
||||
defaultHashAlgo = lib.optionalString isSRIHash lib.head (lib.splitString "-" lib.fakeHash);
|
||||
defaultHashPrefix = lib.optionalString isSRIHash (defaultHashAlgo + "-");
|
||||
defaultHashBody = lib.removePrefix defaultHashPrefix fakeHash;
|
||||
in
|
||||
partialHash:
|
||||
defaultHashPrefix
|
||||
+ partialHash
|
||||
+ (lib.substring (lib.stringLength partialHash) (lib.stringLength defaultHashBody) defaultHashBody);
|
||||
|
||||
tests-fetchgit =
|
||||
let
|
||||
fakeSha256-1 = genNonzeroFakeHash lib.fakeSha256 "1";
|
||||
fakeHash-2 = genNonzeroFakeHash lib.fakeHash "B";
|
||||
src-with-sha256 = pkgs.fetchgit {
|
||||
url = "https://example.com/source.git";
|
||||
sha256 = lib.fakeSha256;
|
||||
sha256 = fakeSha256-1;
|
||||
};
|
||||
in
|
||||
{
|
||||
@@ -164,19 +194,19 @@ let
|
||||
;
|
||||
};
|
||||
expected = {
|
||||
outputHash = lib.fakeSha256;
|
||||
outputHash = fakeSha256-1;
|
||||
outputHashAlgo = "sha256";
|
||||
};
|
||||
};
|
||||
test-fetchgit-overrideAttrs-hash = {
|
||||
expr = {
|
||||
inherit (src-with-sha256.overrideAttrs { hash = pkgs.nix.src.hash; })
|
||||
inherit (src-with-sha256.overrideAttrs { hash = fakeHash-2; })
|
||||
outputHash
|
||||
outputHashAlgo
|
||||
;
|
||||
};
|
||||
expected = {
|
||||
outputHash = pkgs.nix.src.hash;
|
||||
outputHash = fakeHash-2;
|
||||
outputHashAlgo = null;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user