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
46
tests/pgintegration/PgTestEnvironment.h
Normal file
46
tests/pgintegration/PgTestEnvironment.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <optional>
|
||||
#include <QString>
|
||||
|
||||
namespace pgtest {
|
||||
|
||||
/// Value of the TEST_DATABASE_URL environment variable, if set and non-empty.
|
||||
std::optional<QString> baseUrl();
|
||||
|
||||
/// Same as baseUrl() but with the database name replaced.
|
||||
QString urlForDb(const QString &db);
|
||||
|
||||
/// True when a server is configured and the template database was created.
|
||||
bool available();
|
||||
|
||||
/// server_version_num of the server under test (0 when unavailable).
|
||||
int serverVersionNum();
|
||||
|
||||
/// Portable process id.
|
||||
qint64 processId();
|
||||
|
||||
/// Name of the template database for this process.
|
||||
QString templateDbName();
|
||||
|
||||
/// Quotes an identifier for use in SQL.
|
||||
QString quoteIdent(const QString &name);
|
||||
|
||||
/// Global environment, register it in main():
|
||||
/// ::testing::AddGlobalTestEnvironment(new pgtest::PgEnv(PGTEST_FIXTURE_DIR));
|
||||
/// Creates a template database from <fixtureDir>/schema.sql once per process.
|
||||
class PgEnv : public ::testing::Environment {
|
||||
public:
|
||||
explicit PgEnv(QString fixtureDir) : fixtureDir_(std::move(fixtureDir)) {}
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
|
||||
private:
|
||||
QString fixtureDir_;
|
||||
};
|
||||
|
||||
} // namespace pgtest
|
||||
|
||||
#define REQUIRE_PG_AT_LEAST(v) \
|
||||
if (pgtest::serverVersionNum() < (v) * 10000) GTEST_SKIP() << "needs PG " #v
|
||||
Loading…
Add table
Add a link
Reference in a new issue