fix(3p/nix/tests): Fail DummyStore::addToStore on non-existent srcPath

Unfortunately, to guarantee correct behaviour of some evaluation (!)
tests, addToStore needs to actually check whether passed in source
files exist and fail appropriately.

There is a chance that the dependency on this behaviour is actually a
bug in the upstream test suite, but my attempts at finding out more
about this from, say, the git history have so far been unsuccessful.

Change-Id: I311999ea28fcedf5da13a4e627b1c1c8e4e59cbd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1276
Reviewed-by: isomer <isomer@tvl.fyi>
Reviewed-by: glittershark <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2020-07-19 00:27:35 +01:00 committed by tazjin
parent 989537f972
commit a802b4b44d
2 changed files with 8 additions and 3 deletions

View file

@ -1,5 +1,6 @@
#pragma once
#include <filesystem>
#include "libstore/store-api.hh"
namespace nix::tests {
@ -20,9 +21,13 @@ class DummyStore final : public Store {
bool recursive = true, HashType hashAlgo = htSHA256,
PathFilter& filter = defaultPathFilter,
RepairFlag repair = NoRepair) {
if (srcPath == "/exists-for-tests") {
return "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x";
}
throw SysError("file does not exist");
}
Path addTextToStore(const std::string& name, const std::string& s,
const PathSet& references, RepairFlag repair = NoRepair) {
return "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x";

View file

@ -116,7 +116,7 @@ TEST_F(JSONValueTest, Path) {
Value v;
PathSet ps;
mkPath(v, "test");
mkPathNoCopy(v, "/exists-for-tests");
printValueAsJSON(s, true, v, ss, ps);
ASSERT_EQ(ss.str(), "\"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x\"");
}
@ -128,7 +128,7 @@ TEST_F(JSONValueTest, PathNoCopy) {
Value v;
PathSet ps;
mkPathNoCopy(v, "test");
mkPathNoCopy(v, "/exists-for-tests");
printValueAsJSON(s, true, v, ss, ps);
ASSERT_EQ(ss.str(), "\"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x\"");
}