From 168c24b605f7124fedb0a957659d2c76e979573f Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 17 Sep 2025 15:20:42 -0400 Subject: [PATCH] Declare `DummyStoreConfig` in a header This will useful for unit tests. --- src/libstore/dummy-store.cc | 43 +++---------------- src/libstore/include/nix/store/dummy-store.hh | 41 ++++++++++++++++++ src/libstore/include/nix/store/meson.build | 1 + 3 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 src/libstore/include/nix/store/dummy-store.hh diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc index d0e298968..defee4a98 100644 --- a/src/libstore/dummy-store.cc +++ b/src/libstore/dummy-store.cc @@ -1,48 +1,15 @@ #include "nix/store/store-registration.hh" #include "nix/util/callback.hh" +#include "nix/store/dummy-store.hh" namespace nix { -struct DummyStoreConfig : public std::enable_shared_from_this, virtual StoreConfig +std::string DummyStoreConfig::doc() { - using StoreConfig::StoreConfig; - - DummyStoreConfig(std::string_view scheme, std::string_view authority, const Params & params) - : StoreConfig(params) - { - if (!authority.empty()) - throw UsageError("`%s` store URIs must not contain an authority part %s", scheme, authority); - } - - static const std::string name() - { - return "Dummy Store"; - } - - static std::string doc() - { - return + return #include "dummy-store.md" - ; - } - - static StringSet uriSchemes() - { - return {"dummy"}; - } - - ref openStore() const override; - - StoreReference getReference() const override - { - return { - .variant = - StoreReference::Specified{ - .scheme = *uriSchemes().begin(), - }, - }; - } -}; + ; +} struct DummyStore : virtual Store { diff --git a/src/libstore/include/nix/store/dummy-store.hh b/src/libstore/include/nix/store/dummy-store.hh new file mode 100644 index 000000000..9cb26d8d4 --- /dev/null +++ b/src/libstore/include/nix/store/dummy-store.hh @@ -0,0 +1,41 @@ +#include "nix/store/store-api.hh" + +namespace nix { + +struct DummyStoreConfig : public std::enable_shared_from_this, virtual StoreConfig +{ + using StoreConfig::StoreConfig; + + DummyStoreConfig(std::string_view scheme, std::string_view authority, const Params & params) + : StoreConfig(params) + { + if (!authority.empty()) + throw UsageError("`%s` store URIs must not contain an authority part %s", scheme, authority); + } + + static const std::string name() + { + return "Dummy Store"; + } + + static std::string doc(); + + static StringSet uriSchemes() + { + return {"dummy"}; + } + + ref openStore() const override; + + StoreReference getReference() const override + { + return { + .variant = + StoreReference::Specified{ + .scheme = *uriSchemes().begin(), + }, + }; + } +}; + +} // namespace nix diff --git a/src/libstore/include/nix/store/meson.build b/src/libstore/include/nix/store/meson.build index 60af5ff53..428ef00f3 100644 --- a/src/libstore/include/nix/store/meson.build +++ b/src/libstore/include/nix/store/meson.build @@ -34,6 +34,7 @@ headers = [ config_pub_h ] + files( 'derived-path-map.hh', 'derived-path.hh', 'downstream-placeholder.hh', + 'dummy-store.hh', 'export-import.hh', 'filetransfer.hh', 'gc-store.hh',