diff options
Diffstat (limited to 'test/testdb-mysql.cpp')
-rw-r--r-- | test/testdb-mysql.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/test/testdb-mysql.cpp b/test/testdb-mysql.cpp index 20ba677..4b6c62e 100644 --- a/test/testdb-mysql.cpp +++ b/test/testdb-mysql.cpp @@ -1,4 +1,5 @@ #include "testdb-mysql.h" +#include <compileTimeFormatter.h> #include <cstdlib> #include <helpers.h> #include <input/mysqlConn.h> @@ -9,18 +10,25 @@ namespace MyGrate { 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"))}; + std::size_t MySQLDB::mocknum; - MySQLDB::MySQLDB() : MySQLConn(SERVER, USER, PASSWORD, PORT) + MySQLDB::MySQLDB() : + MySQLConn(SERVER, USER, PASSWORD, PORT), mockname {scprintf<"mygrate_test_%?_%?">(getpid(), mocknum++)} { - query("DROP DATABASE IF EXISTS mygrate_test"); - query("CREATE DATABASE mygrate_test"); - query("USE mygrate_test"); + query(("DROP DATABASE IF EXISTS " + mockname).c_str()); + query(("CREATE DATABASE " + mockname).c_str()); } MySQLDB::~MySQLDB() { - query("USE mysql"); - query("DROP DATABASE IF EXISTS mygrate_test"); + query(("DROP DATABASE IF EXISTS " + mockname).c_str()); + mockname.clear(); + } + + Input::MySQLConn + MySQLDB::mock() const + { + return {SERVER, USER, PASSWORD, PORT, mockname.c_str()}; } } } |