From b8d5de4c869d2babec53e5c738487adb8f4eaa78 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 16 Jul 2019 17:03:05 +0200 Subject: [PATCH] dnsdist: Proper creation of the LMDB and CDB test databases --- pdns/dnsdistdist/test-dnsdistkvs_cc.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pdns/dnsdistdist/test-dnsdistkvs_cc.cc b/pdns/dnsdistdist/test-dnsdistkvs_cc.cc index ccd40983e..8a92c57a3 100644 --- a/pdns/dnsdistdist/test-dnsdistkvs_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistkvs_cc.cc @@ -29,7 +29,16 @@ BOOST_AUTO_TEST_CASE(test_LMDB) { DNSQuestion dq(&qname, qtype, qclass, qname.wirelength(), &lc, &rem, &dh, bufferSize, queryLen, isTcp, &queryRealTime); - auto lmdb = make_unique("/data/Dumps/lmdb", "db-name"); + const string dbPath("/tmp/test_lmdb.XXXXXX"); + { + MDBEnv env(dbPath.c_str(), MDB_NOSUBDIR, 0600); + auto transaction = env.getRWTransaction(); + auto dbi = transaction.openDB("db-name", MDB_CREATE); + transaction.put(dbi, MDBInVal(std::string(reinterpret_cast(&dq.remote->sin4.sin_addr.s_addr), sizeof(dq.remote->sin4.sin_addr.s_addr))), MDBInVal("this is the value of the tag")); + transaction.commit(); + } + + auto lmdb = make_unique(dbPath, "db-name"); auto lookupKey = make_unique(); std::string value; @@ -69,11 +78,13 @@ BOOST_AUTO_TEST_CASE(test_CDB) { DNSQuestion dq(&qname, qtype, qclass, qname.wirelength(), &lc, &rem, &dh, bufferSize, queryLen, isTcp, &queryRealTime); char db[] = "/tmp/test_cdb.XXXXXX"; - int fd = mkstemp(db); - BOOST_REQUIRE(fd >= 0); - CDBWriter writer(fd); - BOOST_REQUIRE(writer.addEntry(std::string(reinterpret_cast(&dq.remote->sin4.sin_addr.s_addr), sizeof(dq.remote->sin4.sin_addr.s_addr)), "this is the value of the tag")); - writer.close(); + { + int fd = mkstemp(db); + BOOST_REQUIRE(fd >= 0); + CDBWriter writer(fd); + BOOST_REQUIRE(writer.addEntry(std::string(reinterpret_cast(&dq.remote->sin4.sin_addr.s_addr), sizeof(dq.remote->sin4.sin_addr.s_addr)), "this is the value of the tag")); + writer.close(); + } auto cdb = make_unique(db); auto lookupKey = make_unique(); -- 2.40.0