Create an ephemeral PostgreSQL database per test

This commit is contained in:
Graham Christensen
2021-02-22 13:47:41 -05:00
parent b15d8edab1
commit fe1f2f0806
3 changed files with 34 additions and 10 deletions

View File

@ -13,10 +13,16 @@ struct Connection : pqxx::connection
{
using namespace nix;
auto s = getEnv("HYDRA_DBI").value_or("dbi:Pg:dbname=hydra;");
std::string prefix = "dbi:Pg:";
if (std::string(s, 0, prefix.size()) != prefix)
throw Error("$HYDRA_DBI does not denote a PostgreSQL database");
return concatStringsSep(" ", tokenizeString<Strings>(string(s, prefix.size()), ";"));
std::string lower_prefix = "dbi:Pg:";
std::string upper_prefix = "DBI:Pg:";
if ((std::string(s, 0, lower_prefix.size()) == lower_prefix) ||
(std::string(s, 0, upper_prefix.size()) == upper_prefix)) {
return concatStringsSep(" ", tokenizeString<Strings>(string(s, lower_prefix.size()), ";"));
}
throw Error("$HYDRA_DBI does not denote a PostgreSQL database");
}
};