diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-13 14:15:41 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-13 14:15:41 +0100 |
commit | 2b610c8bdef32c4662938f2d0244f85b6acb6b27 (patch) | |
tree | 100a3fcd4c9917cf56af024f19af3afe8e5d310d /test | |
parent | Remember PQ connection string (diff) | |
download | mygrate-2b610c8bdef32c4662938f2d0244f85b6acb6b27.tar.bz2 mygrate-2b610c8bdef32c4662938f2d0244f85b6acb6b27.tar.xz mygrate-2b610c8bdef32c4662938f2d0244f85b6acb6b27.zip |
Single implementation for getting MySQL test connection details
Diffstat (limited to 'test')
-rw-r--r-- | test/test-mysql.cpp | 13 | ||||
-rw-r--r-- | test/testdb-mysql.cpp | 8 | ||||
-rw-r--r-- | test/testdb-mysql.h | 7 |
3 files changed, 16 insertions, 12 deletions
diff --git a/test/test-mysql.cpp b/test/test-mysql.cpp index e4551f0..8da3f7b 100644 --- a/test/test-mysql.cpp +++ b/test/test-mysql.cpp @@ -17,18 +17,14 @@ #include <type_traits> #include <variant> -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"))}; - BOOST_AUTO_TEST_CASE(simple) { + using namespace MyGrate::Testing; BOOST_CHECK_THROW(([]() { - MyGrate::Input::MySQLConn {SERVER, USER, "badpass", PORT}; + MyGrate::Input::MySQLConn {MySQLDB::SERVER, MySQLDB::USER, "badpass", MySQLDB::PORT}; }()), MyGrate::Input::MySQLErr); - MyGrate::Input::MySQLConn c {SERVER, USER, PASSWORD, PORT}; + MyGrate::Input::MySQLConn c {MySQLDB::SERVER, MySQLDB::USER, MySQLDB::PASSWORD, MySQLDB::PORT}; BOOST_CHECK_NO_THROW(c.query("SET @var = ''")); BOOST_CHECK_NO_THROW(c.query("SET @var = 'something'")); BOOST_CHECK_THROW(c.query("SET @var = "), MyGrate::Input::MySQLErr); @@ -53,7 +49,8 @@ static_assert(SomeUpdate::paramCount(MyGrate::ParamMode::QMark) == 2); BOOST_AUTO_TEST_CASE(stmt) { - MyGrate::Input::MySQLConn c {SERVER, USER, PASSWORD, PORT}; + using namespace MyGrate::Testing; + MyGrate::Input::MySQLConn c {MySQLDB::SERVER, MySQLDB::USER, MySQLDB::PASSWORD, MySQLDB::PORT}; const auto rs {SomeShow::execute(&c)}; BOOST_REQUIRE(rs); BOOST_REQUIRE_EQUAL(rs->rows(), 1); diff --git a/test/testdb-mysql.cpp b/test/testdb-mysql.cpp index 4b6c62e..17bc241 100644 --- a/test/testdb-mysql.cpp +++ b/test/testdb-mysql.cpp @@ -6,10 +6,10 @@ 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"))}; + const char * const MySQLDB::SERVER {MyGrate::getenv("MYGRATE_MYSQL_SERVER", "localhost")}; + const char * const MySQLDB::USER {MyGrate::getenv("MYGRATE_MYSQL_USER", ::getenv("LOGNAME"))}; + const char * const MySQLDB::PASSWORD {::getenv("MYGRATE_MYSQL_PASSWORD")}; + const unsigned short MySQLDB::PORT {(unsigned short)std::atoi(MyGrate::getenv("MYGRATE_MYSQL_PORT", "3306"))}; std::size_t MySQLDB::mocknum; MySQLDB::MySQLDB() : diff --git a/test/testdb-mysql.h b/test/testdb-mysql.h index 3334e24..c77ade2 100644 --- a/test/testdb-mysql.h +++ b/test/testdb-mysql.h @@ -13,6 +13,13 @@ namespace MyGrate { Input::MySQLConn mock() const; std::string mockname; + + static const char * const SERVER; + static const char * const USER; + static const char * const PASSWORD; + static const unsigned short PORT; + + private: static std::size_t mocknum; }; } |