summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-05-24 01:01:30 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-05-24 01:01:30 +0100
commit15c1e5566f7ad8448985ca6e52805ceb4ec389a8 (patch)
tree14908b221d01cca00975da84656adcea57898620 /test
parentMinor tidy up of replStream (diff)
downloadmygrate-15c1e5566f7ad8448985ca6e52805ceb4ec389a8.tar.bz2
mygrate-15c1e5566f7ad8448985ca6e52805ceb4ec389a8.tar.xz
mygrate-15c1e5566f7ad8448985ca6e52805ceb4ec389a8.zip
Basic support for queries with bound parameters
Bit of a reshuffle to make the types not DB specific, add some basic tests over query execution, no selects yet and no validation anything is actually right.
Diffstat (limited to 'test')
-rw-r--r--test/Jamfile.jam2
-rw-r--r--test/test-mysql.cpp25
-rw-r--r--test/test-postgresql.cpp28
-rw-r--r--test/test-rawDataReader.cpp6
-rw-r--r--test/test-streams.cpp4
5 files changed, 60 insertions, 5 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam
index 3c479b9..2cdf94c 100644
--- a/test/Jamfile.jam
+++ b/test/Jamfile.jam
@@ -10,3 +10,5 @@ run test-rawDataReader.cpp ;
run test-bitset.cpp ;
run test-streams.cpp ;
run test-misc.cpp ;
+run test-mysql.cpp ;
+run test-postgresql.cpp ;
diff --git a/test/test-mysql.cpp b/test/test-mysql.cpp
new file mode 100644
index 0000000..5a22567
--- /dev/null
+++ b/test/test-mysql.cpp
@@ -0,0 +1,25 @@
+#define BOOST_TEST_MODULE MySQL
+#include <boost/test/unit_test.hpp>
+
+#include <dbTypes.h>
+#include <input/mysqlConn.h>
+#include <stdexcept>
+
+BOOST_AUTO_TEST_CASE(simple)
+{
+ BOOST_CHECK_THROW(([]() {
+ MyGrate::Input::MySQLConn {"192.168.1.38", "repl", "repl", 3306};
+ }()),
+ std::runtime_error);
+ MyGrate::Input::MySQLConn c {"192.168.1.38", "repl", "r3pl", 3306};
+ BOOST_CHECK_NO_THROW(c.query("SET @var = ''"));
+ BOOST_CHECK_NO_THROW(c.query("SET @var = 'something'"));
+ BOOST_CHECK_THROW(c.query("SET @var = "), std::runtime_error);
+ BOOST_CHECK_THROW(c.query("SET @var = ?", {}), std::logic_error);
+ BOOST_CHECK_NO_THROW(c.query("SET @var = ''", {}));
+ BOOST_CHECK_NO_THROW(c.query("SET @var = ?", {1}));
+ BOOST_CHECK_NO_THROW(c.query("SET @var = ?", {"string_view"}));
+ BOOST_CHECK_NO_THROW(c.query("SET @var = ?", {nullptr}));
+ BOOST_CHECK_NO_THROW(c.query("SET @var = ?", {1.2}));
+ BOOST_CHECK_THROW(c.query("SET @var = ?", {MyGrate::Time {}}), std::runtime_error);
+}
diff --git a/test/test-postgresql.cpp b/test/test-postgresql.cpp
new file mode 100644
index 0000000..5940b38
--- /dev/null
+++ b/test/test-postgresql.cpp
@@ -0,0 +1,28 @@
+#define BOOST_TEST_MODULE PostgreSQL
+#include <boost/test/unit_test.hpp>
+
+#include <dbTypes.h>
+#include <output/pq/pqConn.h>
+#include <stdexcept>
+
+BOOST_AUTO_TEST_CASE(simple)
+{
+ BOOST_CHECK_THROW(([]() {
+ MyGrate::Output::Pq::PqConn {"nonsense"};
+ }()),
+ std::runtime_error);
+ MyGrate::Output::Pq::PqConn c {"user=postgres"};
+ BOOST_CHECK_NO_THROW(c.query("SET application_name = ''"));
+ BOOST_CHECK_NO_THROW(c.query("SET application_name = 'something'"));
+ BOOST_CHECK_THROW(c.query("SET application_name = "), std::runtime_error);
+ // BOOST_CHECK_THROW(c.query("SET application_name = $1", {}), std::logic_error);
+ BOOST_CHECK_NO_THROW(c.query("SET application_name = 'something'", {}));
+ c.query("DROP TABLE IF EXISTS test");
+ c.query("CREATE TABLE test(c text)");
+ BOOST_CHECK_NO_THROW(c.query("INSERT INTO test VALUES($1)", {1}));
+ BOOST_CHECK_NO_THROW(c.query("INSERT INTO test VALUES($1)", {"string_view"}));
+ BOOST_CHECK_NO_THROW(c.query("INSERT INTO test VALUES($1)", {nullptr}));
+ BOOST_CHECK_NO_THROW(c.query("INSERT INTO test VALUES($1)", {1.2}));
+ BOOST_CHECK_THROW(c.query("INSERT INTO test VALUES($1)", {MyGrate::Time {}}), std::runtime_error);
+ c.query("DROP TABLE test");
+}
diff --git a/test/test-rawDataReader.cpp b/test/test-rawDataReader.cpp
index b211fe3..3d34bff 100644
--- a/test/test-rawDataReader.cpp
+++ b/test/test-rawDataReader.cpp
@@ -4,12 +4,12 @@
#include <boost/test/unit_test.hpp>
#include "bitset.h"
+#include "dbTypes.h"
#include "helpers.h"
#include "mariadb_repl.h"
#include <cstddef>
#include <cstdint>
#include <mysql.h>
-#include <mysql_types.h>
#include <rawDataReader.h>
#include <stdexcept>
#include <streamSupport.h>
@@ -125,7 +125,7 @@ BOOST_DATA_TEST_CASE(read_bytes,
bytes)
{
RawDataReader rdr {bytes.data(), bytes.size()};
- const auto out {rdr.viewValue<MyGrate::MySQL::Blob>(bytes.size())};
+ const auto out {rdr.viewValue<MyGrate::Blob>(bytes.size())};
BOOST_CHECK_EQUAL_COLLECTIONS(out.begin(), out.end(), bytes.begin(), bytes.end());
}
@@ -140,7 +140,7 @@ BOOST_DATA_TEST_CASE(read_bytes_overflow,
bytes)
{
RawDataReader rdr {bytes.data(), bytes.size()};
- BOOST_CHECK_THROW(rdr.viewValue<MyGrate::MySQL::Blob>(bytes.size() + 1), std::range_error);
+ BOOST_CHECK_THROW(rdr.viewValue<MyGrate::Blob>(bytes.size() + 1), std::range_error);
}
BOOST_DATA_TEST_CASE(read_field_type,
diff --git a/test/test-streams.cpp b/test/test-streams.cpp
index 3958e36..a4ff1a5 100644
--- a/test/test-streams.cpp
+++ b/test/test-streams.cpp
@@ -3,9 +3,9 @@
#include <boost/test/unit_test.hpp>
#include "bitset.h"
+#include "dbTypes.h"
#include "helpers.h"
#include "mariadb_repl.h"
-#include "mysql_types.h"
#include <array>
#include <cstddef>
#include <ctime>
@@ -46,7 +46,7 @@ BOOST_DATA_TEST_CASE(tms,
}
BOOST_DATA_TEST_CASE(rts,
- boost::unit_test::data::make<ToStream<MyGrate::MySQL::DateTime>>({
+ boost::unit_test::data::make<ToStream<MyGrate::DateTime>>({
{{{2016, 1, 4}, {12, 13, 14}}, "2016-01-04 12:13:14"},
{{{2016, 12, 31}, {0, 0, 1}}, "2016-12-31 00:00:01"},
}),