aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-02-17 12:22:50 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-02-17 12:22:50 +0100
commit832377bbd6ccd43895ac346131cafe4901f7996b (patch)
tree427b36821bdb5c0bd6d2336df157c300e95b66f1 /tests
parenta9d99ab55fdaa1c9dde87eaa8d289ecdb8cf9068 (diff)
Add a test for repairing paths
Diffstat (limited to 'tests')
-rw-r--r--tests/binary-cache.sh4
-rw-r--r--tests/common.sh.in6
-rw-r--r--tests/local.mk4
-rw-r--r--tests/repair.sh47
-rw-r--r--tests/verify.sh3
5 files changed, 56 insertions, 8 deletions
diff --git a/tests/binary-cache.sh b/tests/binary-cache.sh
index 9bd4fecb6..45e67bee7 100644
--- a/tests/binary-cache.sh
+++ b/tests/binary-cache.sh
@@ -2,11 +2,9 @@ source common.sh
clearStore
clearManifests
+clearCache
# Create the binary cache.
-cacheDir=$TEST_ROOT/binary-cache
-rm -rf "$cacheDir"
-
outPath=$(nix-build dependencies.nix --no-out-link)
nix-push --dest $cacheDir $outPath
diff --git a/tests/common.sh.in b/tests/common.sh.in
index 0c4df7119..48ca7d2dd 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -29,6 +29,8 @@ export SHELL="@bash@"
export version=@PACKAGE_VERSION@
export system=@system@
+cacheDir=$TEST_ROOT/binary-cache
+
readLink() {
ls -l "$1" | sed 's/.*->\ //'
}
@@ -55,6 +57,10 @@ clearManifests() {
rm -f $NIX_STATE_DIR/manifests/*
}
+clearCache() {
+ rm -rf "$cacheDir"
+}
+
startDaemon() {
# Start the daemon, wait for the socket to appear. !!!
# ‘nix-daemon’ should have an option to fork into the background.
diff --git a/tests/local.mk b/tests/local.mk
index 87f4e25e6..6b82c0a35 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -4,13 +4,13 @@ check:
nix_tests = \
init.sh hash.sh lang.sh add.sh simple.sh dependencies.sh \
parallel.sh build-hook.sh substitutes.sh substitutes2.sh \
- fallback.sh nix-push.sh gc.sh gc-concurrent.sh verify.sh nix-pull.sh \
+ fallback.sh nix-push.sh gc.sh gc-concurrent.sh nix-pull.sh \
referrers.sh user-envs.sh logging.sh nix-build.sh misc.sh fixed.sh \
gc-runtime.sh install-package.sh check-refs.sh filter-source.sh \
remote-store.sh export.sh export-graph.sh negative-caching.sh \
binary-patching.sh timeout.sh secure-drv-outputs.sh nix-channel.sh \
multiple-outputs.sh import-derivation.sh fetchurl.sh optimise-store.sh \
- binary-cache.sh nix-profile.sh
+ binary-cache.sh nix-profile.sh repair.sh
install-tests += $(foreach x, $(nix_tests), tests/$(x))
diff --git a/tests/repair.sh b/tests/repair.sh
new file mode 100644
index 000000000..f17aef277
--- /dev/null
+++ b/tests/repair.sh
@@ -0,0 +1,47 @@
+source common.sh
+
+clearStore
+
+path=$(nix-build dependencies.nix -o $TEST_ROOT/result)
+path2=$(nix-store -qR $path | grep input-2)
+
+nix-store --verify --check-contents -v
+
+hash=$(nix-hash $path2)
+
+# Corrupt a path and check whether nix-build --repair can fix it.
+chmod u+w $path2
+touch $path2/bad
+
+if nix-store --verify --check-contents -v; then
+ echo "nix-store --verify succeeded unexpectedly" >&2
+ exit 1
+fi
+
+if nix-store --verify --check-contents --repair; then
+ echo "nix-store --verify --repair succeeded unexpectedly" >&2
+ exit 1
+fi
+
+nix-build dependencies.nix -o $TEST_ROOT/result --repair
+
+if [ "$(nix-hash $path2)" != "$hash" -o -e $path2/bad ]; then
+ echo "path not repaired properly" >&2
+ exit 1
+fi
+
+# Corrupt a path that has a substitute and check whether nix-store
+# --verify can fix it.
+clearCache
+
+nix-push --dest $cacheDir $path
+
+chmod u+w $path2
+rm -rf $path2
+
+nix-store --verify --check-contents --repair --option binary-caches "file://$cacheDir"
+
+if [ "$(nix-hash $path2)" != "$hash" -o -e $path2/bad ]; then
+ echo "path not repaired properly" >&2
+ exit 1
+fi
diff --git a/tests/verify.sh b/tests/verify.sh
deleted file mode 100644
index e0d68e849..000000000
--- a/tests/verify.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-source common.sh
-
-nix-store --verify