mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
Add a test for fetchClosure and 'nix store make-content-addressed'
This commit is contained in:
parent
4120930ac1
commit
28186b7044
5 changed files with 64 additions and 4 deletions
|
@ -53,7 +53,9 @@ static void prim_fetchClosure(EvalState & state, const Pos & pos, Value * * args
|
||||||
|
|
||||||
auto parsedURL = parseURL(*fromStoreUrl);
|
auto parsedURL = parseURL(*fromStoreUrl);
|
||||||
|
|
||||||
if (parsedURL.scheme != "http" && parsedURL.scheme != "https")
|
if (parsedURL.scheme != "http" &&
|
||||||
|
parsedURL.scheme != "https" &&
|
||||||
|
!(getEnv("_NIX_IN_TEST").has_value() && parsedURL.scheme == "file"))
|
||||||
throw Error({
|
throw Error({
|
||||||
.msg = hintfmt("'fetchClosure' only supports http:// and https:// stores"),
|
.msg = hintfmt("'fetchClosure' only supports http:// and https:// stores"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
|
|
|
@ -52,7 +52,7 @@ std::map<StorePath, StorePath> makeContentAddressed(
|
||||||
auto dstPath = dstStore.makeFixedOutputPath(
|
auto dstPath = dstStore.makeFixedOutputPath(
|
||||||
FileIngestionMethod::Recursive, narModuloHash, path.name(), references, hasSelfReference);
|
FileIngestionMethod::Recursive, narModuloHash, path.name(), references, hasSelfReference);
|
||||||
|
|
||||||
printInfo("rewroting '%s' to '%s'", pathS, srcStore.printStorePath(dstPath));
|
printInfo("rewriting '%s' to '%s'", pathS, srcStore.printStorePath(dstPath));
|
||||||
|
|
||||||
StringSink sink2;
|
StringSink sink2;
|
||||||
RewritingSink rsink2(oldHashPart, std::string(dstPath.hashPart()), sink2);
|
RewritingSink rsink2(oldHashPart, std::string(dstPath.hashPart()), sink2);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
source common.sh
|
source common.sh
|
||||||
|
|
||||||
needLocalStore "“--no-require-sigs” can’t be used with the daemon"
|
needLocalStore "'--no-require-sigs' can’t be used with the daemon"
|
||||||
|
|
||||||
# We can produce drvs directly into the binary cache
|
# We can produce drvs directly into the binary cache
|
||||||
clearStore
|
clearStore
|
||||||
|
|
57
tests/fetchClosure.sh
Normal file
57
tests/fetchClosure.sh
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
source common.sh
|
||||||
|
|
||||||
|
needLocalStore "'--no-require-sigs' can’t be used with the daemon"
|
||||||
|
|
||||||
|
clearStore
|
||||||
|
clearCacheCache
|
||||||
|
|
||||||
|
# Initialize binary cache.
|
||||||
|
nonCaPath=$(nix build --json --file ./dependencies.nix | jq -r .[].outputs.out)
|
||||||
|
caPath=$(nix store make-content-addressed --json $nonCaPath | jq -r '.rewrites | map(.) | .[]')
|
||||||
|
nix copy --to file://$cacheDir $nonCaPath
|
||||||
|
|
||||||
|
# Test basic fetchClosure rewriting from non-CA to CA.
|
||||||
|
clearStore
|
||||||
|
|
||||||
|
[ ! -e $nonCaPath ]
|
||||||
|
[ ! -e $caPath ]
|
||||||
|
|
||||||
|
[[ $(nix eval -v --raw --expr "
|
||||||
|
builtins.fetchClosure {
|
||||||
|
fromStore = \"file://$cacheDir\";
|
||||||
|
fromPath = $nonCaPath;
|
||||||
|
toPath = $caPath;
|
||||||
|
}
|
||||||
|
") = $caPath ]]
|
||||||
|
|
||||||
|
[ ! -e $nonCaPath ]
|
||||||
|
[ -e $caPath ]
|
||||||
|
|
||||||
|
# In impure mode, we can use non-CA paths.
|
||||||
|
[[ $(nix eval --raw --no-require-sigs --impure --expr "
|
||||||
|
builtins.fetchClosure {
|
||||||
|
fromStore = \"file://$cacheDir\";
|
||||||
|
fromPath = $nonCaPath;
|
||||||
|
}
|
||||||
|
") = $nonCaPath ]]
|
||||||
|
|
||||||
|
[ -e $nonCaPath ]
|
||||||
|
|
||||||
|
# 'toPath' set to empty string should fail but print the expected path.
|
||||||
|
nix eval -v --json --expr "
|
||||||
|
builtins.fetchClosure {
|
||||||
|
fromStore = \"file://$cacheDir\";
|
||||||
|
fromPath = $nonCaPath;
|
||||||
|
toPath = \"\";
|
||||||
|
}
|
||||||
|
" 2>&1 | grep "error: rewriting.*$nonCaPath.*yielded.*$caPath"
|
||||||
|
|
||||||
|
# If fromPath is CA, then toPath isn't needed.
|
||||||
|
nix copy --to file://$cacheDir $caPath
|
||||||
|
|
||||||
|
[[ $(nix eval -v --raw --expr "
|
||||||
|
builtins.fetchClosure {
|
||||||
|
fromStore = \"file://$cacheDir\";
|
||||||
|
fromPath = $caPath;
|
||||||
|
}
|
||||||
|
") = $caPath ]]
|
|
@ -96,7 +96,8 @@ nix_tests = \
|
||||||
describe-stores.sh \
|
describe-stores.sh \
|
||||||
nix-profile.sh \
|
nix-profile.sh \
|
||||||
suggestions.sh \
|
suggestions.sh \
|
||||||
store-ping.sh
|
store-ping.sh \
|
||||||
|
fetchClosure.sh
|
||||||
|
|
||||||
ifeq ($(HAVE_LIBCPUID), 1)
|
ifeq ($(HAVE_LIBCPUID), 1)
|
||||||
nix_tests += compute-levels.sh
|
nix_tests += compute-levels.sh
|
||||||
|
|
Loading…
Reference in a new issue