ORE Studio 0.0.4
Loading...
Searching...
No Matches
test_database_manager.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_TESTING_TEST_DATABASE_MANAGER_HPP
21#define ORES_TESTING_TEST_DATABASE_MANAGER_HPP
22
23#include <string>
24#include "ores.utility/log/make_logger.hpp"
25#include "ores.database/domain/context.hpp"
26#include "ores.database/domain/database_options.hpp"
27
28namespace ores::testing {
29
41private:
42 inline static std::string_view logger_name =
43 "ores.testing.test_database_manager";
44
45 static auto& lg() {
46 static auto instance = ores::utility::log::make_logger(logger_name);
47 return instance;
48 }
49
55 static database::context make_admin_context();
56
57 public:
62
67
76 static std::string generate_test_database_name();
77
87 static void create_test_database(const std::string& db_name);
88
97 static void drop_test_database(const std::string& db_name);
98
107 static void set_test_database_env(const std::string& db_name);
108};
109
110}
111
112#endif
Testing infrastructure common to all test projects.
Definition database_helper.hpp:27
Context for the operations on a postgres database.
Definition context.hpp:30
Configuration for database connection.
Definition database_options.hpp:33
Manages isolated test databases for parallel test execution.
Definition test_database_manager.hpp:40
static void set_test_database_env(const std::string &db_name)
Sets the TEST_ORES_DB_DATABASE environment variable.
Definition test_database_manager.cpp:201
static void drop_test_database(const std::string &db_name)
Drops the test database.
Definition test_database_manager.cpp:149
static void create_test_database(const std::string &db_name)
Creates a test database from the oresdb_template.
Definition test_database_manager.cpp:113
static database::database_options make_database_options()
Creates database options from environment variables.
Definition test_database_manager.cpp:77
static std::string generate_test_database_name()
Generates a unique database name for this test process.
Definition test_database_manager.cpp:92
static database::context make_context()
Creates a database context from environment variables.
Definition test_database_manager.cpp:63