Add tests for read-only local store

Make sure we don't go down the path of making temproots when doing
operations on a read-only store
This commit is contained in:
cidkidnix 2023-05-17 13:48:59 -05:00 committed by Ben Radford
parent 5966b76c97
commit 85a2453052
3 changed files with 35 additions and 1 deletions

View file

@ -110,6 +110,10 @@ void LocalStore::createTempRootsFile()
void LocalStore::addTempRoot(const StorePath & path)
{
if (readOnly) {
debug("Read-only store doesn't support creating lock files for temp roots, but nothing can be deleted anyways.");
return;
}
createTempRootsFile();
/* Open/create the global GC lock file. */

View file

@ -134,7 +134,8 @@ nix_tests = \
flakes/show.sh \
impure-derivations.sh \
path-from-hash-part.sh \
toString-path.sh
toString-path.sh \
read-only-store.sh
ifeq ($(HAVE_LIBCPUID), 1)
nix_tests += compute-levels.sh

29
tests/read-only-store.sh Normal file
View file

@ -0,0 +1,29 @@
source common.sh
clearStore
## Testing read-only mode without forcing the underlying store to actually be read-only
# Make sure the command fails when the store doesn't already have a database
expectStderr 1 nix-store --store local?read-only=true --add dummy | grepQuiet "unable to create database while in read-only mode"
# Make sure the store actually has a current-database
nix-store --add dummy
# Try again and make sure we fail when adding a item not already in the store
expectStderr 1 nix-store --store local?read-only=true --add eval.nix | grepQuiet "attempt to write a readonly database"
# Make sure we can get an already-present store-path in the database
nix-store --store local?read-only=true --add dummy
## Ensure store is actually read-only
chmod -R -w $TEST_ROOT/store
chmod -R -w $TEST_ROOT/var
# Make sure we fail on add operations on the read-only store
# This is only for adding files that are not *already* in the store
expectStderr 1 nix-store --add eval.nix | grepQuiet "error: opening lock file '$(readlink -e $TEST_ROOT)/var/nix/db/big-lock'"
expectStderr 1 nix-store --store local?read-only=true --add eval.nix | grepQuiet "Permission denied"
# Should succeed
nix-store --store local?read-only=true --add dummy