From 5c9443849dd33e91690369f8194ac0cd725f23ec Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 12 Jun 2021 20:31:17 +0100 Subject: Create a basic MySQL testing database class --- test/Jamfile.jam | 9 +++++++-- test/test-mysql.cpp | 6 ++++++ test/testdb-mysql.cpp | 26 ++++++++++++++++++++++++++ test/testdb-mysql.h | 16 ++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 test/testdb-mysql.cpp create mode 100644 test/testdb-mysql.h (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 2cdf94c..38bee41 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -2,13 +2,18 @@ lib boost_unit_test_framework ; project : requirements ../lib//mygrate - boost_unit_test_framework + boost_unit_test_framework/shared BOOST_TEST_DYN_LINK ; +lib testdb : + [ glob testdb-*.cpp ] : + static + ; + run test-rawDataReader.cpp ; run test-bitset.cpp ; run test-streams.cpp ; run test-misc.cpp ; -run test-mysql.cpp ; +run test-mysql.cpp : : : testdb ; run test-postgresql.cpp ; diff --git a/test/test-mysql.cpp b/test/test-mysql.cpp index d91f54e..954a121 100644 --- a/test/test-mysql.cpp +++ b/test/test-mysql.cpp @@ -1,6 +1,7 @@ #define BOOST_TEST_MODULE MySQL #include +#include "testdb-mysql.h" #include #include #include @@ -60,3 +61,8 @@ BOOST_AUTO_TEST_CASE(stmt) BOOST_CHECK(std::get(rs->at(0, 0)).starts_with("mariadb")); BOOST_CHECK_GE(std::get(rs->at(0, 1)), 4); } + +BOOST_AUTO_TEST_CASE(mock) +{ + MyGrate::Testing::MySQLDB db; +} diff --git a/test/testdb-mysql.cpp b/test/testdb-mysql.cpp new file mode 100644 index 0000000..20ba677 --- /dev/null +++ b/test/testdb-mysql.cpp @@ -0,0 +1,26 @@ +#include "testdb-mysql.h" +#include +#include +#include + +namespace MyGrate { + namespace Testing { + const auto SERVER {MyGrate::getenv("MYGRATE_MYSQL_SERVER", "localhost")}; + const auto USER {MyGrate::getenv("MYGRATE_MYSQL_USER", ::getenv("LOGNAME"))}; + const auto PASSWORD {::getenv("MYGRATE_MYSQL_PASSWORD")}; + const auto PORT {(unsigned short)std::atoi(MyGrate::getenv("MYGRATE_MYSQL_PORT", "3306"))}; + + MySQLDB::MySQLDB() : MySQLConn(SERVER, USER, PASSWORD, PORT) + { + query("DROP DATABASE IF EXISTS mygrate_test"); + query("CREATE DATABASE mygrate_test"); + query("USE mygrate_test"); + } + + MySQLDB::~MySQLDB() + { + query("USE mysql"); + query("DROP DATABASE IF EXISTS mygrate_test"); + } + } +} diff --git a/test/testdb-mysql.h b/test/testdb-mysql.h new file mode 100644 index 0000000..c7cceb3 --- /dev/null +++ b/test/testdb-mysql.h @@ -0,0 +1,16 @@ +#ifndef MYGRATE_TESTING_MYSQL_H +#define MYGRATE_TESTING_MYSQL_H + +#include + +namespace MyGrate { + namespace Testing { + class MySQLDB : public Input::MySQLConn { + public: + MySQLDB(); + ~MySQLDB(); + }; + } +} + +#endif -- cgit v1.2.3