mirror of
https://github.com/NixOS/nix
synced 2025-07-08 06:53:54 +02:00
C API: refactor test support
This commit is contained in:
parent
693e8ec8fe
commit
2e1dbbe307
6 changed files with 55 additions and 74 deletions
|
@ -10,21 +10,16 @@
|
|||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace nixC {
|
||||
class nix_api_store_test : public nix_api_util_context
|
||||
{
|
||||
public:
|
||||
nix_api_store_test()
|
||||
{
|
||||
nix_libstore_init(ctx);
|
||||
|
||||
auto tmpl = nix::getEnv("TMPDIR").value_or("/tmp") + "/tests_nix-store.XXXXXX";
|
||||
nixStoreDir = mkdtemp((char *) tmpl.c_str());
|
||||
|
||||
// Options documented in `nix help-stores`
|
||||
const char * p1[] = {"root", nixStoreDir.c_str()};
|
||||
const char ** params[] = {p1, nullptr};
|
||||
store = nix_store_open(ctx, "local", params);
|
||||
init_local_store();
|
||||
};
|
||||
|
||||
~nix_api_store_test() override
|
||||
{
|
||||
nix_store_free(store);
|
||||
|
@ -37,4 +32,17 @@ public:
|
|||
|
||||
Store * store;
|
||||
std::string nixStoreDir;
|
||||
|
||||
protected:
|
||||
void init_local_store()
|
||||
{
|
||||
auto tmpl = nix::getEnv("TMPDIR").value_or("/tmp") + "/tests_nix-store.XXXXXX";
|
||||
nixStoreDir = mkdtemp((char *) tmpl.c_str());
|
||||
|
||||
// Options documented in `nix help-stores`
|
||||
const char * p1[] = {"root", nixStoreDir.c_str()};
|
||||
const char ** params[] = {p1, nullptr};
|
||||
store = nix_store_open(ctx, "local", params);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue