PostgreSQL: added test case for failed connection attempt.

This commit is contained in:
Friedrich Wilckens 2023-10-30 13:23:18 -07:00
parent c7b6fa17be
commit 148affed30
2 changed files with 32 additions and 1 deletions

View File

@ -140,6 +140,33 @@ void PostgreSQLTest::testConnectNoDB()
}
}
void PostgreSQLTest::testFailedConnect()
{
std::string dbConnString;
dbConnString += "host=" + getHost();
dbConnString += " user=invalid";
dbConnString += " password=invalid";
dbConnString += " port=" + getPort();
Poco::SharedPtr<Poco::Data::Session> pInvalidSession;
try
{
std::cout << "Attempting to Connect to [" << dbConnString << "] with invalid credentials: " << std::endl;
Session session(PostgreSQL::Connector::KEY, dbConnString);
fail ("must fail");
}
catch (ConnectionFailedException& ex)
{
std::cout << ex.displayText() << std::endl;
}
catch (ConnectionException& ex)
{
std::cout << ex.displayText() << std::endl;
}
}
void PostgreSQLTest::testPostgreSQLOIDs()
{
if (!_pSession) fail ("Test not available.");
@ -309,6 +336,7 @@ void PostgreSQLTest::testBarebonePostgreSQL()
}
void PostgreSQLTest::testSimpleAccess()
{
if (!_pSession) fail ("Test not available.");
@ -775,7 +803,7 @@ void PostgreSQLTest::testSqlState()
}
catch (const Poco::Data::PostgreSQL::PostgreSQLException & exception)
{
assertTrue(exception.sqlState() == std::string("42601"));
assertTrue(exception.sqlState() == std::string("42601"));
}
}
@ -1236,6 +1264,7 @@ CppUnit::Test* PostgreSQLTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("PostgreSQLTest");
CppUnit_addTest(pSuite, PostgreSQLTest, testConnectNoDB);
CppUnit_addTest(pSuite, PostgreSQLTest, testFailedConnect);
CppUnit_addTest(pSuite, PostgreSQLTest, testPostgreSQLOIDs);
//CppUnit_addTest(pSuite, PostgreSQLTest, testBarebonePostgreSQL);
CppUnit_addTest(pSuite, PostgreSQLTest, testSimpleAccess);

View File

@ -36,9 +36,11 @@ public:
~PostgreSQLTest();
void testConnectNoDB();
void testFailedConnect();
void testPostgreSQLOIDs();
void testBarebonePostgreSQL();
void testSimpleAccess();
void testComplexType();
void testSimpleAccessVector();