Skip to content
Snippets Groups Projects
Commit 7a13db63 authored by Grigorii Demidov's avatar Grigorii Demidov
Browse files

tests: test_cache with non-global api

parents f01587ab 9e251215
No related branches found
No related tags found
No related merge requests found
......@@ -166,6 +166,8 @@ static int test_open(void **state, namedb_api_t *api)
static void test_open_fake_api(void **state)
{
bool res;
will_return(fake_test_init,KNOT_EINVAL);
assert_int_equal(test_open(state, fake_namedb_lmdb_api()),KNOT_EINVAL);
will_return(fake_test_init,KNOT_EOK);
assert_int_equal(test_open(state, fake_namedb_lmdb_api()),KNOT_EOK);
res = (((struct kr_cache *)(*state))->api == fake_namedb_lmdb_api());
......@@ -207,9 +209,21 @@ static struct kr_cache_txn *test_txn_rdonly(void **state)
/* test invalid parameters and some api failures */
static void test_fake_invalid (void **state)
{
assert_int_not_equal(kr_cache_txn_commit(&global_txn), KNOT_EOK);
will_return(fake_test_init,KNOT_EINVAL);
assert_int_equal(test_open(state, fake_namedb_lmdb_api()),KNOT_EINVAL);
struct kr_cache_txn *txn = NULL;
const namedb_api_t *api_saved;
knot_dname_t dname[] = "";
struct kr_cache_entry *ret;
assert_int_not_equal(kr_cache_txn_commit(txn), KNOT_EOK);
txn = test_txn_write(state);
assert_int_not_equal(kr_cache_txn_commit(txn), KNOT_EOK);
ret = kr_cache_peek(txn, KR_CACHE_USER, dname, KNOT_RRTYPE_TSIG, 0);
assert_int_equal(ret, &global_fake_ce);
api_saved = txn->owner->api;
txn->owner->api = NULL;
ret = kr_cache_peek(txn, KR_CACHE_USER, dname, KNOT_RRTYPE_TSIG, 0);
txn->owner->api = api_saved;
assert_null(ret);
}
static void test_fake_insert(void **state)
......@@ -247,6 +261,8 @@ static void test_invalid(void **state)
opts.path = global_env;
opts.mapsize = CACHE_SIZE;
knot_rrset_init_empty(&global_rr);
assert_int_equal(kr_cache_open(NULL, NULL, &opts, &global_mm),KNOT_EINVAL);
assert_int_not_equal(kr_cache_txn_begin(NULL, &global_txn, 0), 0);
assert_int_not_equal(kr_cache_txn_begin(*state, NULL, 0), 0);
......
......@@ -73,6 +73,8 @@ static PyObject* init(PyObject* self, PyObject* args)
opts.mapsize = 100 * 4096;
int ret = kr_cache_open(&global_context.cache, NULL, &opts, &global_mm);
assert(ret == 0);
if (ret != 0)
return NULL;
/* No configuration parsing support yet. */
if (strstr(config, "query-minimization: on") == NULL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment