2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[#2445] PostgreSQL lease manager tests

This commit is contained in:
Andrei Pavel 2022-06-27 11:07:53 +03:00
parent f5419843a1
commit b393239079
No known key found for this signature in database
GPG Key ID: 86E9385BC2203766

View File

@ -15,6 +15,7 @@
#include <exceptions/exceptions.h>
#include <pgsql/pgsql_connection.h>
#include <pgsql/testutils/pgsql_schema.h>
#include <testutils/gtest_utils.h>
#include <testutils/multi_threading_utils.h>
#include <util/multi_threading_mgr.h>
@ -1059,4 +1060,44 @@ TEST_F(PgSqlGenericBackendTest, leaseCount) {
EXPECT_EQ(0, countRows(conn, "lease4"));
}
/// @brief Checks that no exceptions are thrown when inquiring about JSON
/// support and prints an informative message.
TEST_F(PgSqlLeaseMgrTest, isJsonSupported) {
bool json_supported;
ASSERT_NO_THROW_LOG(json_supported = LeaseMgrFactory::instance().isJsonSupported());
std::cout << "JSON support is " << (json_supported ? "" : "not ") <<
"enabled in the database." << std::endl;
}
/// @brief Checks that a null user context allows allocation.
TEST_F(PgSqlLeaseMgrTest, checkLimitsNull) {
std::string text;
ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(nullptr));
EXPECT_TRUE(text.empty());
ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(nullptr));
EXPECT_TRUE(text.empty());
}
/// @brief Checks a few limit checking scenarios.
TEST_F(PgSqlLeaseMgrTest, checkLimits) {
// Limit checking should be precluded at reconfiguration time on systems
// that don't have JSON support in the database. It's fine if it throws.
if (!LeaseMgrFactory::instance().isJsonSupported()) {
ASSERT_THROW_MSG(LeaseMgrFactory::instance().checkLimits4(
isc::data::Element::createMap()), isc::db::DbOperationError,
"unable to set up for storing all results for "
"<SELECT checkLease4Limits(?)>, reason: FUNCTION "
"keatest.JSON_EXTRACT does not exist (error code 1305)");
ASSERT_THROW_MSG(LeaseMgrFactory::instance().checkLimits6(
isc::data::Element::createMap()), isc::db::DbOperationError,
"unable to set up for storing all results for "
"<SELECT checkLease6Limits(?)>, reason: FUNCTION "
"keatest.JSON_EXTRACT does not exist (error code 1305)");
return;
}
// The rest of the checks are only for databases with JSON support.
testLeaseLimits();
}
} // namespace