summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test-mysql.cpp3
-rw-r--r--test/testdb-mysql.cpp20
-rw-r--r--test/testdb-mysql.h5
3 files changed, 22 insertions, 6 deletions
diff --git a/test/test-mysql.cpp b/test/test-mysql.cpp
index 954a121..e4551f0 100644
--- a/test/test-mysql.cpp
+++ b/test/test-mysql.cpp
@@ -65,4 +65,7 @@ BOOST_AUTO_TEST_CASE(stmt)
BOOST_AUTO_TEST_CASE(mock)
{
MyGrate::Testing::MySQLDB db;
+ auto mdb = db.mock();
+ auto rs = MyGrate::DbStmt<"SELECT DATABASE()">::execute(&mdb);
+ BOOST_CHECK_EQUAL(rs->at(0, 0).get<std::string_view>().substr(0, 13), "mygrate_test_");
}
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()};
}
}
}
diff --git a/test/testdb-mysql.h b/test/testdb-mysql.h
index c7cceb3..3334e24 100644
--- a/test/testdb-mysql.h
+++ b/test/testdb-mysql.h
@@ -9,6 +9,11 @@ namespace MyGrate {
public:
MySQLDB();
~MySQLDB();
+
+ Input::MySQLConn mock() const;
+
+ std::string mockname;
+ static std::size_t mocknum;
};
}
}