summaryrefslogtreecommitdiffstats
path: root/src/lib/mysql
diff options
context:
space:
mode:
authorAndrei Pavel <andrei@isc.org>2023-01-20 21:41:53 +0100
committerAndrei Pavel <andrei@isc.org>2023-01-23 17:48:14 +0100
commit135bfa4ad700ab7fe30baed20e2dd2ea0f7a5176 (patch)
tree6485c3d5319fb149ce49bd5934cae4fc15d0ced8 /src/lib/mysql
parent[#2693] Addressed review comments (diff)
downloadkea-135bfa4ad700ab7fe30baed20e2dd2ea0f7a5176.tar.xz
kea-135bfa4ad700ab7fe30baed20e2dd2ea0f7a5176.zip
[#2727] introduce HAVE_MYSQL_GET_OPTION
Addresses error: mysql_connection_unittest.cc: In member function ‘virtual void {anonymous}::MySqlConnectionTest_connectionTimeout_Test::TestBody()’: mysql_connection_unittest.cc:633:77: error: ‘mysql_get_option’ was not declared in this scope EXPECT_EQ(0, mysql_get_option(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout));
Diffstat (limited to 'src/lib/mysql')
-rw-r--r--src/lib/mysql/tests/mysql_connection_unittest.cc70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/lib/mysql/tests/mysql_connection_unittest.cc b/src/lib/mysql/tests/mysql_connection_unittest.cc
index a6d4bbde49..cc2b21d3ea 100644
--- a/src/lib/mysql/tests/mysql_connection_unittest.cc
+++ b/src/lib/mysql/tests/mysql_connection_unittest.cc
@@ -173,7 +173,6 @@ public:
mysql_stmt_close(stmt);
}
-
/// @brief Tests inserting and retrieving data from the database.
///
/// In this test data carried in the bindings is inserted into the database.
@@ -618,22 +617,6 @@ TEST_F(MySqlConnectionTest, portInvalid) {
EXPECT_THROW(conn.openDatabase(), DbInvalidPort);
}
-
-// Tests that valid connection timeout is accepted.
-TEST_F(MySqlConnectionTest, connectionTimeout) {
- std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
- VALID_HOST_TCP, VALID_USER,
- VALID_PASSWORD, VALID_TIMEOUT);
- MySqlConnection conn(DatabaseConnection::parse(conn_str));
- ASSERT_NO_THROW_LOG(conn.openDatabase());
-
- auto mysql = static_cast<MYSQL*>(conn.mysql_);
- ASSERT_TRUE(mysql);
- unsigned int timeout = 123;
- EXPECT_EQ(0, mysql_get_option(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout));
- EXPECT_EQ(10, timeout);
-}
-
// Tests that invalid timeout value type causes an error.
TEST_F(MySqlConnectionTest, connectionTimeoutInvalid) {
std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
@@ -661,6 +644,41 @@ TEST_F(MySqlConnectionTest, connectionTimeoutInvalid3) {
EXPECT_THROW(conn.openDatabase(), DbInvalidTimeout);
}
+// Tests that an invalid read timeout causes an error.
+TEST_F(MySqlConnectionTest, readTimeoutInvalid) {
+ std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
+ VALID_HOST_TCP, VALID_USER,
+ VALID_PASSWORD, INVALID_READ_TIMEOUT_1);
+ MySqlConnection conn(DatabaseConnection::parse(conn_str));
+ EXPECT_THROW(conn.openDatabase(), DbInvalidTimeout);
+}
+
+// Tests that an invalid write timeout causes an error.
+TEST_F(MySqlConnectionTest, writeTimeoutInvalid) {
+ std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
+ VALID_HOST_TCP, VALID_USER,
+ VALID_PASSWORD, INVALID_WRITE_TIMEOUT_1);
+ MySqlConnection conn(DatabaseConnection::parse(conn_str));
+ EXPECT_THROW(conn.openDatabase(), DbInvalidTimeout);
+}
+
+#ifdef HAVE_MYSQL_GET_OPTION
+
+// Tests that valid connection timeout is accepted.
+TEST_F(MySqlConnectionTest, connectionTimeout) {
+ std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
+ VALID_HOST_TCP, VALID_USER,
+ VALID_PASSWORD, VALID_TIMEOUT);
+ MySqlConnection conn(DatabaseConnection::parse(conn_str));
+ ASSERT_NO_THROW_LOG(conn.openDatabase());
+
+ auto mysql = static_cast<MYSQL*>(conn.mysql_);
+ ASSERT_TRUE(mysql);
+ unsigned int timeout = 123;
+ EXPECT_EQ(0, mysql_get_option(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout));
+ EXPECT_EQ(10, timeout);
+}
+
// Tests that a valid read timeout is accepted.
TEST_F(MySqlConnectionTest, readTimeout) {
std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
@@ -691,15 +709,6 @@ TEST_F(MySqlConnectionTest, readTimeoutZero) {
EXPECT_EQ(0, timeout);
}
-// Tests that an invalid read timeout causes an error.
-TEST_F(MySqlConnectionTest, readTimeoutInvalid) {
- std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
- VALID_HOST_TCP, VALID_USER,
- VALID_PASSWORD, INVALID_READ_TIMEOUT_1);
- MySqlConnection conn(DatabaseConnection::parse(conn_str));
- EXPECT_THROW(conn.openDatabase(), DbInvalidTimeout);
-}
-
// Tests that a valid write timeout is accepted.
TEST_F(MySqlConnectionTest, writeTimeout) {
std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
@@ -730,14 +739,7 @@ TEST_F(MySqlConnectionTest, writeTimeoutZero) {
EXPECT_EQ(0, timeout);
}
-// Tests that an invalid write timeout causes an error.
-TEST_F(MySqlConnectionTest, writeTimeoutInvalid) {
- std::string conn_str = connectionString(MYSQL_VALID_TYPE, VALID_NAME,
- VALID_HOST_TCP, VALID_USER,
- VALID_PASSWORD, INVALID_WRITE_TIMEOUT_1);
- MySqlConnection conn(DatabaseConnection::parse(conn_str));
- EXPECT_THROW(conn.openDatabase(), DbInvalidTimeout);
-}
+#endif // HAVE_MYSQL_GET_OPTION
TEST_F(MySqlConnectionWithPrimaryKeyTest, select) {
select();