Added the test infrastructure for postgres

This commit is contained in:
Dr. Patrick Urbanke
2025-04-19 10:56:38 +02:00
parent c63fd12e7b
commit 39d78d7cb5
4 changed files with 49 additions and 1 deletions

View File

@@ -23,7 +23,7 @@ class Connection : public sqlgen::Connection {
public:
Connection(const Credentials& _credentials)
: credentials_(_credentials), conn_(make_conn(_credentials.to_str())) {}
: conn_(make_conn(_credentials.to_str())), credentials_(_credentials) {}
static rfl::Result<Ref<sqlgen::Connection>> make(
const Credentials& _credentials) noexcept;

View File

@@ -23,6 +23,10 @@ target_link_libraries(
find_package(GTest)
gtest_discover_tests(sqlgen-tests)
if(SQLGEN_POSTGRES)
add_subdirectory(postgres)
endif()
if(SQLGEN_SQLITE3)
add_subdirectory(sqlite)
endif()

View File

@@ -0,0 +1,19 @@
project(sqlgen-postgres-tests)
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")
add_executable(
sqlgen-postgres-tests
${SOURCES}
)
target_precompile_headers(sqlgen-postgres-tests PRIVATE [["sqlgen.hpp"]] <iostream> <string> <functional> <gtest/gtest.h>)
target_link_libraries(
sqlgen-postgres-tests
PRIVATE
"${SQLGEN_GTEST_LIB}"
)
find_package(GTest)
gtest_discover_tests(sqlgen-postgres-tests)

View File

@@ -0,0 +1,25 @@
#include <gtest/gtest.h>
#include <sqlgen.hpp>
#include <sqlgen/postgres.hpp>
#include <sqlgen/transpilation/to_select_from.hpp>
namespace test_to_select_from {
struct TestTable {
std::string field1;
int32_t field2;
sqlgen::PrimaryKey<uint32_t> id;
std::optional<std::string> nullable;
};
TEST(postgres, test_to_select_from) {
/*const auto select_from_stmt =
sqlgen::transpilation::to_select_from<TestTable>();
const auto conn = sqlgen::postgres::connect().value();
const auto expected =
R"(SELECT "field1", "field2", "id", "nullable" FROM "TestTable";)";
EXPECT_EQ(conn->to_sql(select_from_stmt), expected);*/
}
} // namespace test_to_select_from