about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-05-30T12·53+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-05-30T13·18+0200
commitbac123ddd9eaecb9044f7d7c9572f77825a18ad5 (patch)
tree51293a222a745d0cfa4dd00fe5d63956e9baf170
parent3593c8285dec644f07156496fd8cd84ef70ec665 (diff)
Test the NAR info cache
-rw-r--r--src/libstore/local-binary-cache-store.cc7
-rw-r--r--tests/binary-cache.sh15
-rw-r--r--tests/nix-channel.sh13
-rw-r--r--tests/nix-profile.sh13
-rw-r--r--tests/tarball.sh3
-rw-r--r--tests/user-envs.sh3
6 files changed, 25 insertions, 29 deletions
diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc
index e979a94b7aca..b418c9c04148 100644
--- a/src/libstore/local-binary-cache-store.cc
+++ b/src/libstore/local-binary-cache-store.cc
@@ -1,5 +1,6 @@
 #include "binary-cache-store.hh"
 #include "globals.hh"
+#include "nar-info-disk-cache.hh"
 
 namespace nix {
 
@@ -16,6 +17,9 @@ public:
         : BinaryCacheStore(params)
         , binaryCacheDir(binaryCacheDir)
     {
+        /* For testing the NAR info cache. */
+        if (getEnv("_NIX_CACHE_FILE_URLS") == "1")
+            diskCache = getNarInfoDiskCache();
     }
 
     void init() override;
@@ -53,6 +57,9 @@ void LocalBinaryCacheStore::init()
 {
     createDirs(binaryCacheDir + "/nar");
     BinaryCacheStore::init();
+
+    if (diskCache && !diskCache->cacheExists(getUri()))
+        diskCache->createCache(getUri(), wantMassQuery_, priority);
 }
 
 static void atomicWrite(const Path & path, const std::string & s)
diff --git a/tests/binary-cache.sh b/tests/binary-cache.sh
index b0b91905ad9e..09e25b29fdb6 100644
--- a/tests/binary-cache.sh
+++ b/tests/binary-cache.sh
@@ -12,7 +12,7 @@ nix-push --dest $cacheDir $outPath
 # By default, a binary cache doesn't support "nix-env -qas", but does
 # support installation.
 clearStore
-rm -f $NIX_STATE_DIR/binary-cache*
+clearCacheCache
 
 export _NIX_CACHE_FILE_URLS=1
 
@@ -25,7 +25,7 @@ nix-store --option binary-caches "file://$cacheDir" -r $outPath
 
 # But with the right configuration, "nix-env -qas" should also work.
 clearStore
-rm -f $NIX_STATE_DIR/binary-cache*
+clearCacheCache
 echo "WantMassQuery: 1" >> $cacheDir/nix-cache-info
 
 nix-env --option binary-caches "file://$cacheDir" -f dependencies.nix -qas \* | grep -- "--S"
@@ -55,8 +55,7 @@ mv $nar.good $nar
 
 # Test whether this unsigned cache is rejected if the user requires signed caches.
 clearStore
-
-rm -f $NIX_STATE_DIR/binary-cache*
+clearCacheCache
 
 if nix-store --option binary-caches "file://$cacheDir" --option signed-binary-caches '*' -r $outPath; then
     echo "unsigned binary cache incorrectly accepted"
@@ -107,16 +106,14 @@ nix-push --dest $cacheDir --key-file $TEST_ROOT/sk1 $outPath
 
 # Downloading should fail if we don't provide a key.
 clearStore
-
-rm -f $NIX_STATE_DIR/binary-cache*
+clearCacheCache
 
 (! nix-store -r $outPath --option binary-caches "file://$cacheDir" --option signed-binary-caches '*' )
 
 
 # And it should fail if we provide an incorrect key.
 clearStore
-
-rm -f $NIX_STATE_DIR/binary-cache*
+clearCacheCache
 
 (! nix-store -r $outPath --option binary-caches "file://$cacheDir" --option signed-binary-caches '*' --option binary-cache-public-keys "$badKey")
 
@@ -133,7 +130,7 @@ for i in $cacheDir/*.narinfo; do
     mv $i.tmp $i
 done
 
-rm -f $NIX_STATE_DIR/binary-cache*
+clearCacheCache
 
 (! nix-store -r $outPath --option binary-caches "file://$cacheDir" --option signed-binary-caches '*' --option binary-cache-public-keys "$publicKey")
 
diff --git a/tests/nix-channel.sh b/tests/nix-channel.sh
index c538afd606be..2ec986dd415b 100644
--- a/tests/nix-channel.sh
+++ b/tests/nix-channel.sh
@@ -2,18 +2,15 @@ source common.sh
 
 clearProfiles
 
-rm -f $TEST_ROOT/.nix-channels
-
-# Override location of ~/.nix-channels.
-export HOME=$TEST_ROOT
+rm -f $TEST_HOME/.nix-channels $TEST_HOME/.nix-profile
 
 # Test add/list/remove.
 nix-channel --add http://foo/bar xyzzy
 nix-channel --list | grep -q http://foo/bar
 nix-channel --remove xyzzy
 
-[ -e $TEST_ROOT/.nix-channels ]
-[ "$(cat $TEST_ROOT/.nix-channels)" = '' ]
+[ -e $TEST_HOME/.nix-channels ]
+[ "$(cat $TEST_HOME/.nix-channels)" = '' ]
 
 # Create a channel.
 rm -rf $TEST_ROOT/foo
@@ -41,10 +38,8 @@ grep -q 'item.*attrPath="foo".*name="dependencies"' $TEST_ROOT/meta.xml
 nix-env -i dependencies
 [ -e $TEST_ROOT/var/nix/profiles/default/foobar ]
 
-
-
 clearProfiles
-rm -f $TEST_ROOT/.nix-channels
+rm -f $TEST_HOME/.nix-channels
 
 # Test updating from a tarball
 nix-channel --add file://$TEST_ROOT/foo/nixexprs.tar.bz2 foo
diff --git a/tests/nix-profile.sh b/tests/nix-profile.sh
index db1edd73eef0..2cc3910ba12d 100644
--- a/tests/nix-profile.sh
+++ b/tests/nix-profile.sh
@@ -1,11 +1,10 @@
 source common.sh
 
-home=$TEST_ROOT/home
 user=$(whoami)
-rm -rf $home
-mkdir -p $home
-HOME=$home USER=$user $SHELL -e -c ". ../scripts/nix-profile.sh"
-HOME=$home USER=$user $SHELL -e -c ". ../scripts/nix-profile.sh" # test idempotency
+rm -rf $TEST_HOME
+mkdir -p $TEST_HOME
+USER=$user $SHELL -e -c ". ../scripts/nix-profile.sh"
+USER=$user $SHELL -e -c ". ../scripts/nix-profile.sh" # test idempotency
 
-[ -L $home/.nix-profile ]
-[ -e $home/.nix-channels ]
+[ -L $TEST_HOME/.nix-profile ]
+[ -e $TEST_HOME/.nix-channels ]
diff --git a/tests/tarball.sh b/tests/tarball.sh
index 254c4b626b87..329e73b91696 100644
--- a/tests/tarball.sh
+++ b/tests/tarball.sh
@@ -2,8 +2,7 @@ source common.sh
 
 clearStore
 
-export HOME=$TEST_ROOT/home
-rm -rf $TEST_ROOT/home
+rm -rf $TEST_HOME
 
 tarroot=$TEST_ROOT/tarball
 rm -rf $tarroot
diff --git a/tests/user-envs.sh b/tests/user-envs.sh
index 5e4fcb7bc7f5..526c1267cefe 100644
--- a/tests/user-envs.sh
+++ b/tests/user-envs.sh
@@ -6,8 +6,7 @@ clearProfiles
 # Query installed: should be empty.
 test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0
 
-export HOME=$TEST_ROOT/home
-mkdir -p $HOME
+mkdir -p $TEST_HOME
 nix-env --switch-profile $profiles/test
 
 # Query available: should contain several.