-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2024 Daniel Frey and Dr. Colin Hirsch | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include "../getenv.hpp" | ||
#include "../macros.hpp" | ||
|
||
#include <exception> | ||
#include <format> | ||
#include <iostream> | ||
|
||
#include <tao/pq.hpp> | ||
|
||
namespace | ||
{ | ||
void run() | ||
{ | ||
// overwrite the default with an environment variable if needed | ||
const auto connection_string = tao::pq::internal::getenv( "TAOPQ_TEST_DATABASE", "dbname=template1" ); | ||
|
||
// open a connection to the database | ||
const auto conn = tao::pq::connection::create( connection_string ); | ||
|
||
// prevent cleartext passwords from showing up in logs, traces, etc. | ||
const auto cleartext_password = "secret123"; | ||
const auto encrypted_password = conn->password( cleartext_password, "tao_test_role" ); | ||
|
||
// execute commands | ||
conn->execute( "DROP ROLE IF EXISTS tao_test_role" ); | ||
conn->execute( std::format( "CREATE ROLE tao_test_role PASSWORD '{}'", encrypted_password ) ); | ||
} | ||
|
||
} // namespace | ||
|
||
auto main() -> int // NOLINT(bugprone-exception-escape) | ||
{ | ||
try { | ||
run(); | ||
} | ||
// LCOV_EXCL_START | ||
catch( const std::exception& e ) { | ||
std::cerr << "exception: " << e.what() << '\n'; | ||
throw; | ||
} | ||
catch( ... ) { | ||
std::cerr << "unknown exception\n"; | ||
throw; | ||
} | ||
// LCOV_EXCL_STOP | ||
} |