Skip to content

Commit 55bbc07

Browse files
committed
Add system tests for transport API (#216)
1 parent f849556 commit 55bbc07

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

test/system/HttpAuthST.cxx

+26
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// SOFTWARE.
2222

2323
#include "SystemTest.h"
24+
#include "InfluxDBBuilder.h"
2425

2526
namespace influxdb::test
2627
{
@@ -43,4 +44,29 @@ namespace influxdb::test
4344
CHECK_THAT(response, ContainsSubstring(user.name));
4445
}
4546
}
47+
48+
TEST_CASE("Http authentication methods", "[HttpAuthTest]")
49+
{
50+
using Catch::Matchers::ContainsSubstring;
51+
52+
const auto user = getUserFromEnv();
53+
54+
SECTION("Authenticate through factory")
55+
{
56+
auto db = InfluxDBFactory::Get("http://" + (user.name + ":" + user.pass + "@") + getHostFromEnv() + ":8086?db=ignore");
57+
58+
const auto response = db->execute("show users");
59+
CHECK_THAT(response, ContainsSubstring(user.name));
60+
}
61+
62+
SECTION("Authenticate through builder")
63+
{
64+
auto db = InfluxDBBuilder::http("http://" + getHostFromEnv() + ":8086?db=ignore")
65+
.setBasicAuthentication(user.name, user.pass)
66+
.connect();
67+
68+
const auto response = db->execute("show users");
69+
CHECK_THAT(response, ContainsSubstring(user.name));
70+
}
71+
}
4672
}

test/system/InfluxDBST.cxx

+22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// SOFTWARE.
2222

2323
#include "SystemTest.h"
24+
#include "InfluxDBBuilder.h"
2425

2526
namespace influxdb::test
2627
{
@@ -38,6 +39,27 @@ namespace influxdb::test
3839
}
3940
}
4041

42+
TEST_CASE("Connection configuration", "[InfluxDBST]")
43+
{
44+
using namespace Catch::Matchers;
45+
46+
SECTION("Connect through factory")
47+
{
48+
auto db = InfluxDBFactory::Get("http://" + getHostFromEnv() + ":8086?db=ignore");
49+
const auto response = db->execute("show databases");
50+
CHECK(response.empty() == false);
51+
}
52+
53+
SECTION("Connect through builder")
54+
{
55+
auto db = InfluxDBBuilder::http("http://" + getHostFromEnv() + ":8086?db=ignore")
56+
.setTimeout(std::chrono::seconds{5})
57+
.connect();
58+
const auto response = db->execute("show databases");
59+
CHECK(response.empty() == false);
60+
}
61+
}
62+
4163
TEST_CASE("InfluxDB system test", "[InfluxDBST]")
4264
{
4365
using namespace Catch::Matchers;

test/system/SystemTest.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ namespace influxdb::test
6161
return {*user, *pass};
6262
}
6363

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

0 commit comments

Comments
 (0)