diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-12 20:31:17 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-12 20:31:17 +0100 |
commit | 5c9443849dd33e91690369f8194ac0cd725f23ec (patch) | |
tree | c0495ffb12436a4535d2a15e375826a15c744883 /test | |
parent | Avoid direct use of runtime_error in MySQL stuff (diff) | |
download | mygrate-5c9443849dd33e91690369f8194ac0cd725f23ec.tar.bz2 mygrate-5c9443849dd33e91690369f8194ac0cd725f23ec.tar.xz mygrate-5c9443849dd33e91690369f8194ac0cd725f23ec.zip |
Create a basic MySQL testing database class
Diffstat (limited to 'test')
-rw-r--r-- | test/Jamfile.jam | 9 | ||||
-rw-r--r-- | test/test-mysql.cpp | 6 | ||||
-rw-r--r-- | test/testdb-mysql.cpp | 26 | ||||
-rw-r--r-- | test/testdb-mysql.h | 16 |
4 files changed, 55 insertions, 2 deletions
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 <library>../lib//mygrate - <library>boost_unit_test_framework + <library>boost_unit_test_framework/<link>shared <define>BOOST_TEST_DYN_LINK ; +lib testdb : + [ glob testdb-*.cpp ] : + <link>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 : : : <library>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 <boost/test/unit_test.hpp> +#include "testdb-mysql.h" #include <cstdint> #include <cstdlib> #include <dbConn.h> @@ -60,3 +61,8 @@ BOOST_AUTO_TEST_CASE(stmt) BOOST_CHECK(std::get<std::string_view>(rs->at(0, 0)).starts_with("mariadb")); BOOST_CHECK_GE(std::get<int64_t>(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 <cstdlib> +#include <helpers.h> +#include <input/mysqlConn.h> + +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 <input/mysqlConn.h> + +namespace MyGrate { + namespace Testing { + class MySQLDB : public Input::MySQLConn { + public: + MySQLDB(); + ~MySQLDB(); + }; + } +} + +#endif |