From: Remi Gacogne Date: Tue, 16 Jul 2019 15:03:05 +0000 (+0200) Subject: dnsdist: Proper creation of the LMDB and CDB test databases X-Git-Tag: dnsdist-1.4.0-rc2~9^2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8d5de4c869d2babec53e5c738487adb8f4eaa78;p=thirdparty%2Fpdns.git dnsdist: Proper creation of the LMDB and CDB test databases --- diff --git a/pdns/dnsdistdist/test-dnsdistkvs_cc.cc b/pdns/dnsdistdist/test-dnsdistkvs_cc.cc index ccd40983e2..8a92c57a32 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();