1
0
Fork 0
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:
José Luis Lafuente 2024-02-25 18:14:32 +01:00 committed by José Luis Lafuente
parent 693e8ec8fe
commit 2e1dbbe307
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A
6 changed files with 55 additions and 74 deletions

View file

@ -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);
}
};
}