2023-12-14 21:14:58 +02:00
|
|
|
#include "nix_api_util.h"
|
|
|
|
#include "nix_api_util_internal.h"
|
|
|
|
#include "nix_api_store.h"
|
|
|
|
#include "nix_api_store_internal.h"
|
2024-01-03 20:10:43 +02:00
|
|
|
|
|
|
|
#include "tests/nix_api_store.hh"
|
2023-12-14 21:14:58 +02:00
|
|
|
|
|
|
|
namespace nixC {
|
|
|
|
|
2024-03-27 18:50:36 +02:00
|
|
|
void observe_string_cb(const char * start, unsigned int n, std::string * user_data)
|
|
|
|
{
|
|
|
|
*user_data = std::string(start);
|
|
|
|
}
|
|
|
|
|
2024-02-29 19:33:07 +02:00
|
|
|
std::string PATH_SUFFIX = "/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-name";
|
|
|
|
|
2023-12-14 21:14:58 +02:00
|
|
|
TEST_F(nix_api_util_context, nix_libstore_init)
|
|
|
|
{
|
|
|
|
auto ret = nix_libstore_init(ctx);
|
|
|
|
ASSERT_EQ(NIX_OK, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(nix_api_store_test, nix_store_get_uri)
|
|
|
|
{
|
2024-03-27 18:50:36 +02:00
|
|
|
std::string str;
|
|
|
|
auto ret = nix_store_get_uri(ctx, store, (void *) observe_string_cb, &str);
|
2023-12-14 21:14:58 +02:00
|
|
|
ASSERT_EQ(NIX_OK, ret);
|
2024-03-27 18:50:36 +02:00
|
|
|
ASSERT_STREQ("local", str.c_str());
|
2023-12-14 21:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(nix_api_store_test, InvalidPathFails)
|
|
|
|
{
|
|
|
|
nix_store_parse_path(ctx, store, "invalid-path");
|
|
|
|
ASSERT_EQ(ctx->last_err_code, NIX_ERR_NIX_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(nix_api_store_test, ReturnsValidStorePath)
|
|
|
|
{
|
2024-02-29 19:33:07 +02:00
|
|
|
StorePath * result = nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str());
|
2023-12-14 21:14:58 +02:00
|
|
|
ASSERT_NE(result, nullptr);
|
2024-02-29 19:33:07 +02:00
|
|
|
ASSERT_STREQ("name", result->path.name().data());
|
|
|
|
ASSERT_STREQ(PATH_SUFFIX.substr(1).c_str(), result->path.to_string().data());
|
2023-12-14 21:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(nix_api_store_test, SetsLastErrCodeToNixOk)
|
|
|
|
{
|
2024-02-29 19:33:07 +02:00
|
|
|
nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str());
|
2023-12-14 21:14:58 +02:00
|
|
|
ASSERT_EQ(ctx->last_err_code, NIX_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(nix_api_store_test, DoesNotCrashWhenContextIsNull)
|
|
|
|
{
|
2024-02-29 19:33:07 +02:00
|
|
|
ASSERT_NO_THROW(nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str()));
|
2023-12-14 21:14:58 +02:00
|
|
|
}
|
|
|
|
|
2024-01-03 20:10:43 +02:00
|
|
|
TEST_F(nix_api_store_test, get_version)
|
|
|
|
{
|
2024-03-27 18:50:36 +02:00
|
|
|
std::string str;
|
|
|
|
auto ret = nix_store_get_version(ctx, store, (void *) observe_string_cb, &str);
|
2024-01-03 20:10:43 +02:00
|
|
|
ASSERT_EQ(NIX_OK, ret);
|
2024-03-27 18:50:36 +02:00
|
|
|
ASSERT_STREQ(PACKAGE_VERSION, str.c_str());
|
2024-01-03 20:10:43 +02:00
|
|
|
}
|
|
|
|
|
2024-01-11 23:41:57 +02:00
|
|
|
TEST_F(nix_api_util_context, nix_store_open_dummy)
|
|
|
|
{
|
|
|
|
nix_libstore_init(ctx);
|
|
|
|
Store * store = nix_store_open(ctx, "dummy://", nullptr);
|
|
|
|
ASSERT_EQ(NIX_OK, ctx->last_err_code);
|
|
|
|
ASSERT_STREQ("dummy", store->ptr->getUri().c_str());
|
2024-02-22 01:22:54 +02:00
|
|
|
|
2024-03-27 18:50:36 +02:00
|
|
|
std::string str;
|
|
|
|
nix_store_get_version(ctx, store, (void *) observe_string_cb, &str);
|
|
|
|
ASSERT_STREQ("", str.c_str());
|
2024-02-22 01:22:54 +02:00
|
|
|
|
2024-02-25 15:20:57 +02:00
|
|
|
nix_store_free(store);
|
2024-01-11 23:41:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(nix_api_util_context, nix_store_open_invalid)
|
|
|
|
{
|
|
|
|
nix_libstore_init(ctx);
|
|
|
|
Store * store = nix_store_open(ctx, "invalid://", nullptr);
|
|
|
|
ASSERT_EQ(NIX_ERR_NIX_ERROR, ctx->last_err_code);
|
|
|
|
ASSERT_EQ(nullptr, store);
|
2024-02-25 15:20:57 +02:00
|
|
|
nix_store_free(store);
|
2024-01-11 23:41:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(nix_api_store_test, nix_store_is_valid_path_not_in_store)
|
|
|
|
{
|
2024-02-29 19:33:07 +02:00
|
|
|
StorePath * path = nix_store_parse_path(ctx, store, (nixStoreDir + PATH_SUFFIX).c_str());
|
2024-01-11 23:41:57 +02:00
|
|
|
ASSERT_EQ(false, nix_store_is_valid_path(ctx, store, path));
|
|
|
|
}
|
|
|
|
|
2023-12-14 21:14:58 +02:00
|
|
|
}
|