mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 05:55:28 +00:00
[2679] extracted non-sqlite3-specific param logic into sharable utility funcs
so that they can be used by other accessor implementations.
This commit is contained in:
@@ -19,8 +19,6 @@
|
||||
|
||||
#include <exceptions/exceptions.h>
|
||||
|
||||
#include <dns/name.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
@@ -30,7 +28,6 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
using isc::dns::Name;
|
||||
using namespace isc::datasrc;
|
||||
using namespace isc::datasrc::test;
|
||||
|
||||
@@ -44,68 +41,20 @@ createSQLite3Accessor() {
|
||||
if (std::system(install_cmd) != 0) {
|
||||
// any exception will do, this is failure in test setup, but nice
|
||||
// to show the command that fails, and shouldn't be caught
|
||||
isc_throw(isc::Exception,
|
||||
isc_throw(isc::Unexpected,
|
||||
"Error setting up; command failed: " << install_cmd);
|
||||
}
|
||||
|
||||
boost::shared_ptr<DatabaseAccessor> accessor(
|
||||
new SQLite3Accessor(TEST_DATA_BUILDDIR "/rwtest.sqlite3.copied",
|
||||
"IN"));
|
||||
|
||||
accessor->startUpdateZone("example.org.", true);
|
||||
string columns[DatabaseAccessor::ADD_COLUMN_COUNT];
|
||||
for (int i = 0; TEST_RECORDS[i][0] != NULL; ++i) {
|
||||
columns[DatabaseAccessor::ADD_NAME] = TEST_RECORDS[i][0];
|
||||
columns[DatabaseAccessor::ADD_REV_NAME] =
|
||||
Name(columns[DatabaseAccessor::ADD_NAME]).reverse().toText();
|
||||
columns[DatabaseAccessor::ADD_TYPE] = TEST_RECORDS[i][1];
|
||||
columns[DatabaseAccessor::ADD_TTL] = TEST_RECORDS[i][2];
|
||||
columns[DatabaseAccessor::ADD_SIGTYPE] = TEST_RECORDS[i][3];
|
||||
columns[DatabaseAccessor::ADD_RDATA] = TEST_RECORDS[i][4];
|
||||
|
||||
accessor->addRecordToZone(columns);
|
||||
}
|
||||
// We don't add NSEC3s until we are explicitly told we need them
|
||||
// in enableNSEC3(); these would break some non NSEC3 tests.
|
||||
accessor->commit();
|
||||
loadTestDataGeneric(*accessor);
|
||||
|
||||
return (accessor);
|
||||
}
|
||||
|
||||
void
|
||||
sqlite3EnableNSEC3(DatabaseAccessor& accessor) {
|
||||
accessor.startUpdateZone("example.org.", false);
|
||||
|
||||
// Add NSECPARAM at the zone origin
|
||||
for (int i = 0; TEST_NSEC3PARAM_RECORDS[i][0] != NULL; ++i) {
|
||||
const string param_columns[DatabaseAccessor::ADD_COLUMN_COUNT] = {
|
||||
TEST_NSEC3PARAM_RECORDS[i][0], // name
|
||||
Name(param_columns[DatabaseAccessor::ADD_NAME]).reverse().toText(),
|
||||
// revname
|
||||
TEST_NSEC3PARAM_RECORDS[i][2], // TTL
|
||||
TEST_NSEC3PARAM_RECORDS[i][1], // RR type
|
||||
TEST_NSEC3PARAM_RECORDS[i][3], // sigtype
|
||||
TEST_NSEC3PARAM_RECORDS[i][4] }; // RDATA
|
||||
accessor.addRecordToZone(param_columns);
|
||||
}
|
||||
|
||||
// Add NSEC3s
|
||||
for (int i = 0; TEST_NSEC3_RECORDS[i][0] != NULL; ++i) {
|
||||
const string nsec3_columns[DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT] =
|
||||
{
|
||||
Name(TEST_NSEC3_RECORDS[i][0]).split(0, 1).toText(true),
|
||||
TEST_NSEC3_RECORDS[i][2], // TTL
|
||||
TEST_NSEC3_RECORDS[i][1], // RR type
|
||||
TEST_NSEC3_RECORDS[i][4] // RDATA
|
||||
};
|
||||
accessor.addNSEC3RecordToZone(nsec3_columns);
|
||||
}
|
||||
|
||||
accessor.commit();
|
||||
}
|
||||
|
||||
const DatabaseClientTestParam sqlite3_param = { createSQLite3Accessor,
|
||||
sqlite3EnableNSEC3 };
|
||||
enableNSEC3Generic };
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SQLite3, DatabaseClientTest,
|
||||
::testing::Values(&sqlite3_param));
|
||||
|
@@ -1239,6 +1239,58 @@ DatabaseClientTest::allowMoreTransaction(bool is_allowed) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loadTestDataGeneric(DatabaseAccessor& accessor) {
|
||||
accessor.startUpdateZone("example.org.", true);
|
||||
string columns[DatabaseAccessor::ADD_COLUMN_COUNT];
|
||||
for (int i = 0; TEST_RECORDS[i][0] != NULL; ++i) {
|
||||
columns[DatabaseAccessor::ADD_NAME] = TEST_RECORDS[i][0];
|
||||
columns[DatabaseAccessor::ADD_REV_NAME] =
|
||||
Name(columns[DatabaseAccessor::ADD_NAME]).reverse().toText();
|
||||
columns[DatabaseAccessor::ADD_TYPE] = TEST_RECORDS[i][1];
|
||||
columns[DatabaseAccessor::ADD_TTL] = TEST_RECORDS[i][2];
|
||||
columns[DatabaseAccessor::ADD_SIGTYPE] = TEST_RECORDS[i][3];
|
||||
columns[DatabaseAccessor::ADD_RDATA] = TEST_RECORDS[i][4];
|
||||
|
||||
accessor.addRecordToZone(columns);
|
||||
}
|
||||
// We don't add NSEC3s until we are explicitly told we need them
|
||||
// in enableNSEC3(); these would break some non NSEC3 tests.
|
||||
accessor.commit();
|
||||
}
|
||||
|
||||
void
|
||||
enableNSEC3Generic(DatabaseAccessor& accessor) {
|
||||
accessor.startUpdateZone("example.org.", false);
|
||||
|
||||
// Add NSECPARAM at the zone origin
|
||||
for (int i = 0; TEST_NSEC3PARAM_RECORDS[i][0] != NULL; ++i) {
|
||||
const string param_columns[DatabaseAccessor::ADD_COLUMN_COUNT] = {
|
||||
TEST_NSEC3PARAM_RECORDS[i][0], // name
|
||||
Name(param_columns[DatabaseAccessor::ADD_NAME]).reverse().toText(),
|
||||
// revname
|
||||
TEST_NSEC3PARAM_RECORDS[i][2], // TTL
|
||||
TEST_NSEC3PARAM_RECORDS[i][1], // RR type
|
||||
TEST_NSEC3PARAM_RECORDS[i][3], // sigtype
|
||||
TEST_NSEC3PARAM_RECORDS[i][4] }; // RDATA
|
||||
accessor.addRecordToZone(param_columns);
|
||||
}
|
||||
|
||||
// Add NSEC3s
|
||||
for (int i = 0; TEST_NSEC3_RECORDS[i][0] != NULL; ++i) {
|
||||
const string nsec3_columns[DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT] =
|
||||
{
|
||||
Name(TEST_NSEC3_RECORDS[i][0]).split(0, 1).toText(true),
|
||||
TEST_NSEC3_RECORDS[i][2], // TTL
|
||||
TEST_NSEC3_RECORDS[i][1], // RR type
|
||||
TEST_NSEC3_RECORDS[i][4] // RDATA
|
||||
};
|
||||
accessor.addNSEC3RecordToZone(nsec3_columns);
|
||||
}
|
||||
|
||||
accessor.commit();
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace datasrc
|
||||
} // namespace isc
|
||||
|
@@ -104,7 +104,7 @@ struct DatabaseClientTestParam {
|
||||
class DatabaseClientTest :
|
||||
public ::testing::TestWithParam<const DatabaseClientTestParam*>
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
DatabaseClientTest();
|
||||
|
||||
// We create accessor and other objects that depend on it in SetUp, not
|
||||
@@ -207,6 +207,10 @@ protected:
|
||||
ZoneUpdaterPtr updater_;
|
||||
};
|
||||
|
||||
void loadTestDataGeneric(DatabaseAccessor& accessor);
|
||||
|
||||
void enableNSEC3Generic(DatabaseAccessor& accessor);
|
||||
|
||||
} // namespace test
|
||||
} // namespace datasrc
|
||||
} // namespace isc
|
||||
|
Reference in New Issue
Block a user