Skip to content

Commit 8e6fefc

Browse files
committed
more tests pass
1 parent 6f7dbcd commit 8e6fefc

5 files changed

Lines changed: 33 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ endif()
319319
enable_testing()
320320

321321
# Register tests with CTest
322-
add_test(NAME test-influxdb-cpp-rest COMMAND test-influxdb-cpp-rest)
323-
add_test(NAME test-influx-c-rest COMMAND test-influx-c-rest)
324-
add_test(NAME test-influxdb-cpp-auth COMMAND test-influxdb-cpp-auth)
322+
add_test(NAME test-influxdb-cpp-rest COMMAND ${CMAKE_BINARY_DIR}/bin/test-influxdb-cpp-rest)
323+
add_test(NAME test-influx-c-rest COMMAND ${CMAKE_BINARY_DIR}/bin/test-influx-c-rest)
324+
add_test(NAME test-influxdb-cpp-auth COMMAND ${CMAKE_BINARY_DIR}/bin/test-influxdb-cpp-auth)
325325

326326
# Set output directories for executables
327327
set_target_properties(test-influxdb-cpp-rest test-influx-c-rest test-influxdb-cpp-auth

src/auth_test/auth_test.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,21 @@
2020
#include <chrono>
2121
#include <thread>
2222
#include <iostream>
23+
#include <random>
2324

2425
const char* url = "http://localhost:8086";
25-
const char* db_name = "auth_test";
26+
std::string db_name;
27+
28+
// Generate random database name at startup
29+
static struct db_name_initializer {
30+
db_name_initializer() {
31+
std::random_device rd;
32+
std::mt19937 gen(rd());
33+
std::uniform_int_distribution<> dis(0, 999999);
34+
db_name = "auth_test_" + std::to_string(dis(gen));
35+
}
36+
} db_name_init;
37+
2638
const std::string username = "admin";
2739
const std::string password = "auth";
2840

@@ -45,14 +57,14 @@ struct authentication_test {
4557
db.with_authentication(username, password);
4658

4759
asyncdb = std::shared_ptr<influx_c_rest_async_t>(
48-
influx_c_rest_async_new_auth(url, db_name, username.c_str(), password.c_str()),
60+
influx_c_rest_async_new_auth(url, db_name.c_str(), username.c_str(), password.c_str()),
4961
influx_c_rest_async_destroy
5062
);
5163

5264
REQUIRE(asyncdb.get());
5365

5466
query = std::shared_ptr<influx_c_rest_query_t>(
55-
influx_c_rest_query_new_auth(url, db_name, username.c_str(), password.c_str()),
67+
influx_c_rest_query_new_auth(url, db_name.c_str(), username.c_str(), password.c_str()),
5668
influx_c_rest_query_destroy
5769
);
5870

src/test/fixtures.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
#include <chrono>
1313
#include <thread>
1414

15-
connected_test::connected_test()
16-
{
17-
// Generate random database name to ensure tests are idempotent
15+
std::string connected_test::generate_random_db_name() {
1816
std::random_device rd;
1917
std::mt19937 gen(rd());
2018
std::uniform_int_distribution<> dis(0, 999999);
21-
db_name = "testdb_" + std::to_string(dis(gen));
22-
23-
raw_db = influxdb::raw::db_utf8("http://localhost:8086", db_name);
19+
return "testdb_" + std::to_string(dis(gen));
20+
}
21+
22+
connected_test::connected_test()
23+
: db_name(generate_random_db_name()),
24+
raw_db("http://localhost:8086", db_name)
25+
{
2426
raw_db.post(std::string("drop database ") + db_name);
2527
wait_for_no_db(db_name);
2628
raw_db.post(std::string("create database ") + db_name);

src/test/fixtures.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
#include <random>
1313

1414
struct connected_test {
15+
std::string db_name;
1516
influxdb::raw::db_utf8 raw_db;
1617
const int milliseconds_waiting_time = 100;
17-
std::string db_name;
1818

19+
private:
20+
static std::string generate_random_db_name();
21+
22+
public:
1923
// drop and create test db
2024
connected_test();
2125

src/test/utf8_client_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
#include "fixtures.h"
1212

1313
TEST_CASE_METHOD(connected_test, "creating a database", "[connected]") {
14-
CHECK(database_exists("testdb"));
14+
CHECK(database_exists(db_name));
1515
}
1616

1717

1818
TEST_CASE_METHOD(connected_test, "posting simple values", "[connected]") {
1919
auto testdb_test_entries = [this]() {
20-
return raw_db.get("select * from testdb..test");
20+
return raw_db.get("select * from " + db_name + "..test");
2121
};
2222
CHECK(testdb_test_entries().find("hello") == std::string::npos);
2323

0 commit comments

Comments
 (0)