diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Jamfile.jam | 1 | ||||
-rw-r--r-- | test/test-postgresql.cpp | 8 | ||||
-rw-r--r-- | test/testdb-postgresql.cpp | 11 | ||||
-rw-r--r-- | test/testdb-postgresql.h | 1 |
4 files changed, 21 insertions, 0 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 691a68f..8025839 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -4,6 +4,7 @@ project : requirements <library>../lib//mygrate <library>boost_unit_test_framework/<link>shared <define>BOOST_TEST_DYN_LINK + <define>ROOT=\\\"$(root)\\\" ; lib testdb : diff --git a/test/test-postgresql.cpp b/test/test-postgresql.cpp index 38feb3c..faafcc0 100644 --- a/test/test-postgresql.cpp +++ b/test/test-postgresql.cpp @@ -82,3 +82,11 @@ BOOST_AUTO_TEST_CASE(mock) auto rs = MyGrate::DbStmt<"SELECT CURRENT_DATABASE()">::execute(&mdb); BOOST_CHECK_EQUAL(rs->at(0, 0).get<std::string_view>().substr(0, 13), "mygrate_test_"); } + +BOOST_AUTO_TEST_CASE(mock_schema) +{ + MyGrate::Testing::PqConnDB db {ROOT "/db/schema.sql"}; + auto mdb = db.mock(); + auto rs = MyGrate::DbStmt<"SELECT COUNT(*) FROM mygrate.source">::execute(&mdb); + BOOST_CHECK_EQUAL(rs->at(0, 0).operator unsigned int(), 0); +} diff --git a/test/testdb-postgresql.cpp b/test/testdb-postgresql.cpp index 55f163f..c59640a 100644 --- a/test/testdb-postgresql.cpp +++ b/test/testdb-postgresql.cpp @@ -1,6 +1,7 @@ #include "testdb-postgresql.h" #include <compileTimeFormatter.h> #include <cstdlib> +#include <fstream> #include <helpers.h> #include <output/pq/pqConn.h> @@ -15,6 +16,16 @@ namespace MyGrate { query(("CREATE DATABASE " + mockname).c_str()); } + PqConnDB::PqConnDB(const std::string & schemaFile) : PqConnDB() + { + auto mdb = mock(); + + std::stringstream buffer; + buffer << std::ifstream(schemaFile).rdbuf(); + + mdb.query(buffer.str().c_str()); + } + PqConnDB::~PqConnDB() { query(("DROP DATABASE IF EXISTS " + mockname).c_str()); diff --git a/test/testdb-postgresql.h b/test/testdb-postgresql.h index fc73d2a..c1cd14a 100644 --- a/test/testdb-postgresql.h +++ b/test/testdb-postgresql.h @@ -8,6 +8,7 @@ namespace MyGrate { class PqConnDB : public Output::Pq::PqConn { public: PqConnDB(); + PqConnDB(const std::string & schemaFile); ~PqConnDB(); Output::Pq::PqConn mock() const; |