From b3932390793b0caeb04e34a8ab082901344e5cf7 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Mon, 27 Jun 2022 11:07:53 +0300 Subject: [PATCH] [#2445] PostgreSQL lease manager tests --- .../dhcpsrv/tests/pgsql_lease_mgr_unittest.cc | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index 1a3df9d1d9..818cc3d256 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -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 " + ", 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