Skip to content

Commit

Permalink
Add system tests for transport API (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
offa committed Feb 1, 2024
1 parent f849556 commit da572db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions test/system/InfluxDBST.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// SOFTWARE.

#include "SystemTest.h"
#include "InfluxDBBuilder.h"

namespace influxdb::test
{
Expand All @@ -38,6 +39,27 @@ namespace influxdb::test
}
}

TEST_CASE("Connection configuration", "[InfluxDBST]")
{
using namespace Catch::Matchers;

SECTION("Connect through factory")
{
auto db = InfluxDBFactory::Get("http://" + getHostFromEnv() + ":8086?db=ignore");
const auto response = db->execute("show databases");
CHECK(response.empty() == false);
}

SECTION("Connect through builder")
{
auto db = InfluxDBBuilder::http("http://" + getHostFromEnv() + ":8086?db=ignore")
.setTimeout(std::chrono::seconds{5})
.connect();
const auto response = db->execute("show databases");
CHECK(response.empty() == false);
}
}

TEST_CASE("InfluxDB system test", "[InfluxDBST]")
{
using namespace Catch::Matchers;
Expand Down
8 changes: 6 additions & 2 deletions test/system/SystemTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ namespace influxdb::test
return {*user, *pass};
}

inline std::string getHostFromEnv()
{
return getEnv("INFLUXDBCXX_SYSTEMTEST_HOST").value_or("localhost");
}

inline std::unique_ptr<InfluxDB> configure(const std::string& db, std::optional<User> user = {})
{
const auto host = getEnv("INFLUXDBCXX_SYSTEMTEST_HOST").value_or("localhost");
const std::string authString{user ? (user->name + ":" + user->pass + "@") : ""};
return InfluxDBFactory::Get("http://" + authString + host + ":8086?db=" + db);
return InfluxDBFactory::Get("http://" + authString + getHostFromEnv() + ":8086?db=" + db);
}
}

0 comments on commit da572db

Please sign in to comment.