Add framework for executing tests against multiple postgresql versions using docker compose.
This commit is contained in:
parent
655c6fceb1
commit
c3bf9e88e4
13 changed files with 457 additions and 0 deletions
55
tests/pgintegration/DbTest.cpp
Normal file
55
tests/pgintegration/DbTest.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "DbTest.h"
|
||||
#include "PgTestEnvironment.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace pgtest {
|
||||
|
||||
namespace {
|
||||
std::atomic<int> g_counter{0};
|
||||
}
|
||||
|
||||
QString DbTest::dbUrl() const
|
||||
{
|
||||
return urlForDb(dbName_);
|
||||
}
|
||||
|
||||
void DbTest::SetUp()
|
||||
{
|
||||
if (!available())
|
||||
GTEST_SKIP() << "TEST_DATABASE_URL not set or template database unavailable";
|
||||
|
||||
dbName_ = QString("t_%1_%2").arg(g_counter++).arg(processId());
|
||||
try {
|
||||
{
|
||||
Pgsql::Connection admin;
|
||||
admin.connect(*baseUrl());
|
||||
admin.query(QString("CREATE DATABASE %1 TEMPLATE %2")
|
||||
.arg(quoteIdent(dbName_), quoteIdent(templateDbName())));
|
||||
}
|
||||
conn_ = std::make_unique<Pgsql::Connection>();
|
||||
conn_->connect(dbUrl());
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
FAIL() << "Creating test database failed: " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void DbTest::TearDown()
|
||||
{
|
||||
conn_.reset();
|
||||
if (dbName_.isEmpty())
|
||||
return;
|
||||
try {
|
||||
Pgsql::Connection admin;
|
||||
admin.connect(*baseUrl());
|
||||
admin.query(QString("DROP DATABASE IF EXISTS %1 WITH (FORCE)").arg(quoteIdent(dbName_)));
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
ADD_FAILURE() << "Dropping test database failed: " << e.what();
|
||||
}
|
||||
dbName_.clear();
|
||||
}
|
||||
|
||||
} // namespace pgtest
|
||||
Loading…
Add table
Add a link
Reference in a new issue