mirror of
https://github.com/NixOS/nix.git
synced 2025-11-14 14:32:42 +01:00
Merge pull request #14128 from obsidiansystems/expose-dummy-store-for-tests-somewhat
Expose some core implementation details and write a basic unit test for the dummy store
This commit is contained in:
commit
2774e67c60
6 changed files with 87 additions and 20 deletions
27
src/libstore-tests/dummy-store.cc
Normal file
27
src/libstore-tests/dummy-store.cc
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "nix/store/dummy-store.hh"
|
||||||
|
#include "nix/store/globals.hh"
|
||||||
|
#include "nix/store/realisation.hh"
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
|
TEST(DummyStore, realisation_read)
|
||||||
|
{
|
||||||
|
initLibStore(/*loadConfig=*/false);
|
||||||
|
|
||||||
|
auto store = [] {
|
||||||
|
auto cfg = make_ref<DummyStoreConfig>(StoreReference::Params{});
|
||||||
|
cfg->readOnly = false;
|
||||||
|
return cfg->openStore();
|
||||||
|
}();
|
||||||
|
|
||||||
|
auto drvHash = Hash::parseExplicitFormatUnprefixed(
|
||||||
|
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", HashAlgorithm::SHA256, HashFormat::Base16);
|
||||||
|
|
||||||
|
auto outputName = "foo";
|
||||||
|
|
||||||
|
EXPECT_EQ(store->queryRealisation({drvHash, outputName}), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace nix
|
||||||
|
|
@ -61,6 +61,7 @@ sources = files(
|
||||||
'derivation.cc',
|
'derivation.cc',
|
||||||
'derived-path.cc',
|
'derived-path.cc',
|
||||||
'downstream-placeholder.cc',
|
'downstream-placeholder.cc',
|
||||||
|
'dummy-store.cc',
|
||||||
'http-binary-cache-store.cc',
|
'http-binary-cache-store.cc',
|
||||||
'legacy-ssh-store.cc',
|
'legacy-ssh-store.cc',
|
||||||
'local-binary-cache-store.cc',
|
'local-binary-cache-store.cc',
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#include "nix/util/archive.hh"
|
#include "nix/util/archive.hh"
|
||||||
#include "nix/util/callback.hh"
|
#include "nix/util/callback.hh"
|
||||||
#include "nix/util/memory-source-accessor.hh"
|
#include "nix/util/memory-source-accessor.hh"
|
||||||
#include "nix/store/dummy-store.hh"
|
#include "nix/store/dummy-store-impl.hh"
|
||||||
|
|
||||||
#include <boost/unordered/concurrent_flat_map.hpp>
|
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||||
|
|
||||||
|
|
@ -108,24 +108,15 @@ public:
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
struct DummyStore : virtual Store
|
ref<Store> DummyStoreConfig::openStore() const
|
||||||
|
{
|
||||||
|
return openDummyStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DummyStoreImpl : DummyStore
|
||||||
{
|
{
|
||||||
using Config = DummyStoreConfig;
|
using Config = DummyStoreConfig;
|
||||||
|
|
||||||
ref<const Config> config;
|
|
||||||
|
|
||||||
struct PathInfoAndContents
|
|
||||||
{
|
|
||||||
UnkeyedValidPathInfo info;
|
|
||||||
ref<MemorySourceAccessor> contents;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is map conceptually owns the file system objects for each
|
|
||||||
* store object.
|
|
||||||
*/
|
|
||||||
boost::concurrent_flat_map<StorePath, PathInfoAndContents> contents;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This view conceptually just borrows the file systems objects of
|
* This view conceptually just borrows the file systems objects of
|
||||||
* each store object from `contents`, and combines them together
|
* each store object from `contents`, and combines them together
|
||||||
|
|
@ -135,9 +126,9 @@ struct DummyStore : virtual Store
|
||||||
*/
|
*/
|
||||||
ref<WholeStoreViewAccessor> wholeStoreView = make_ref<WholeStoreViewAccessor>();
|
ref<WholeStoreViewAccessor> wholeStoreView = make_ref<WholeStoreViewAccessor>();
|
||||||
|
|
||||||
DummyStore(ref<const Config> config)
|
DummyStoreImpl(ref<const Config> config)
|
||||||
: Store{*config}
|
: Store{*config}
|
||||||
, config(config)
|
, DummyStore{config}
|
||||||
{
|
{
|
||||||
wholeStoreView->setPathDisplay(config->storeDir);
|
wholeStoreView->setPathDisplay(config->storeDir);
|
||||||
}
|
}
|
||||||
|
|
@ -294,9 +285,9 @@ struct DummyStore : virtual Store
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ref<Store> DummyStore::Config::openStore() const
|
ref<DummyStore> DummyStore::Config::openDummyStore() const
|
||||||
{
|
{
|
||||||
return make_ref<DummyStore>(ref{shared_from_this()});
|
return make_ref<DummyStoreImpl>(ref{shared_from_this()});
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterStoreImplementation<DummyStore::Config> regDummyStore;
|
static RegisterStoreImplementation<DummyStore::Config> regDummyStore;
|
||||||
|
|
|
||||||
40
src/libstore/include/nix/store/dummy-store-impl.hh
Normal file
40
src/libstore/include/nix/store/dummy-store-impl.hh
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#pragma once
|
||||||
|
///@file
|
||||||
|
|
||||||
|
#include "nix/store/dummy-store.hh"
|
||||||
|
|
||||||
|
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
|
struct MemorySourceAccessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enough of the Dummy Store exposed for sake of writing unit tests
|
||||||
|
*/
|
||||||
|
struct DummyStore : virtual Store
|
||||||
|
{
|
||||||
|
using Config = DummyStoreConfig;
|
||||||
|
|
||||||
|
ref<const Config> config;
|
||||||
|
|
||||||
|
struct PathInfoAndContents
|
||||||
|
{
|
||||||
|
UnkeyedValidPathInfo info;
|
||||||
|
ref<MemorySourceAccessor> contents;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is map conceptually owns the file system objects for each
|
||||||
|
* store object.
|
||||||
|
*/
|
||||||
|
boost::concurrent_flat_map<StorePath, PathInfoAndContents> contents;
|
||||||
|
|
||||||
|
DummyStore(ref<const Config> config)
|
||||||
|
: Store{*config}
|
||||||
|
, config(config)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nix
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
struct DummyStore;
|
||||||
|
|
||||||
struct DummyStoreConfig : public std::enable_shared_from_this<DummyStoreConfig>, virtual StoreConfig
|
struct DummyStoreConfig : public std::enable_shared_from_this<DummyStoreConfig>, virtual StoreConfig
|
||||||
{
|
{
|
||||||
DummyStoreConfig(const Params & params)
|
DummyStoreConfig(const Params & params)
|
||||||
|
|
@ -42,6 +44,11 @@ struct DummyStoreConfig : public std::enable_shared_from_this<DummyStoreConfig>,
|
||||||
return {"dummy"};
|
return {"dummy"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as `openStore`, just with a more precise return type.
|
||||||
|
*/
|
||||||
|
ref<DummyStore> openDummyStore() const;
|
||||||
|
|
||||||
ref<Store> openStore() const override;
|
ref<Store> openStore() const override;
|
||||||
|
|
||||||
StoreReference getReference() const override
|
StoreReference getReference() const override
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ headers = [ config_pub_h ] + files(
|
||||||
'derived-path-map.hh',
|
'derived-path-map.hh',
|
||||||
'derived-path.hh',
|
'derived-path.hh',
|
||||||
'downstream-placeholder.hh',
|
'downstream-placeholder.hh',
|
||||||
|
'dummy-store-impl.hh',
|
||||||
'dummy-store.hh',
|
'dummy-store.hh',
|
||||||
'export-import.hh',
|
'export-import.hh',
|
||||||
'filetransfer.hh',
|
'filetransfer.hh',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue