Skip to content

Commit 1620cf3

Browse files
TEL-26: Add Unit tests for mysql plugin
https://perconadev.atlassian.net/browse/TEL-26 Percona Telemetry Component unit tests added
1 parent 08caf31 commit 1620cf3

File tree

5 files changed

+495
-4
lines changed

5 files changed

+495
-4
lines changed

components/percona_telemetry/data_provider.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DataProvider {
6161
SERVICE_TYPE(mysql_command_thread) & command_thread_service,
6262
Logger &logger);
6363

64-
~DataProvider() = default;
64+
virtual ~DataProvider() = default;
6565

6666
DataProvider(const DataProvider &rhs) = delete;
6767
DataProvider(DataProvider &&rhs) = delete;
@@ -73,9 +73,9 @@ class DataProvider {
7373
std::string get_report();
7474

7575
private:
76-
bool do_query(const std::string &query, QueryResult *result,
77-
unsigned int *err_no = nullptr,
78-
bool suppress_query_error_log = false);
76+
virtual bool do_query(const std::string &query, QueryResult *result,
77+
unsigned int *err_no = nullptr,
78+
bool suppress_query_error_log = false);
7979
bool collect_db_instance_id_info(rapidjson::Document *document);
8080
bool collect_product_version_info(rapidjson::Document *document);
8181
bool collect_plugins_info(rapidjson::Document *document);

unittest/gunit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ ADD_SUBDIRECTORY(innodb)
467467
ADD_SUBDIRECTORY(keyring)
468468
ADD_SUBDIRECTORY(components/mysql_server)
469469
ADD_SUBDIRECTORY(components/keyring_common)
470+
ADD_SUBDIRECTORY(components/percona_telemetry)
470471
ADD_SUBDIRECTORY(xplugin)
471472
ADD_SUBDIRECTORY(group_replication)
472473
ADD_SUBDIRECTORY(libmysqlgcs)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2024 Percona LLC and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU General Public License
5+
# as published by the Free Software Foundation; version 2 of
6+
# the License.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
17+
MY_CHECK_CXX_COMPILER_WARNING("-Wno-unused-local-typedefs" HAS_WARN_FLAG)
18+
IF(HAS_WARN_FLAG)
19+
STRING_APPEND(CMAKE_CXX_FLAGS " ${HAS_WARN_FLAG}")
20+
ENDIF()
21+
22+
INCLUDE_DIRECTORIES(SYSTEM
23+
${GMOCK_INCLUDE_DIRS}
24+
)
25+
26+
SET(PERCONA_TELEMETRY_COMPONENT_SRC
27+
${CMAKE_SOURCE_DIR}/components/percona_telemetry/data_provider.cc
28+
)
29+
30+
SET(LOCAL_MOCK_SRC
31+
logger.cc
32+
)
33+
34+
# Add tests
35+
SET(TESTS
36+
data_provider
37+
)
38+
39+
FOREACH(test ${TESTS})
40+
MYSQL_ADD_EXECUTABLE(${test}-t ${PERCONA_TELEMETRY_COMPONENT_SRC} ${LOCAL_MOCK_SRC} ${test}-t.cc ADD_TEST ${test} LINK_LIBRARIES ${PERCONA_TELEMETRY_COMPONENT_LIBS} DEPENDENCIES component_percona_telemetry)
41+
TARGET_LINK_LIBRARIES(${test}-t mysys gunit_small)
42+
ENDFOREACH()
43+

0 commit comments

Comments
 (0)