diff --git a/CMakeLists.txt b/CMakeLists.txt index a2da241..8306ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,9 @@ add_library(alternator_client_cpp add_library(ScyllaDB::alternator_client_cpp ALIAS alternator_client_cpp) target_compile_features(alternator_client_cpp PUBLIC cxx_std_17) +target_compile_definitions(alternator_client_cpp + PUBLIC + SCYLLADB_ALTERNATOR_CLIENT_CPP_VERSION="${PROJECT_VERSION}") target_include_directories(alternator_client_cpp PUBLIC $ @@ -106,6 +109,7 @@ if(ALTERNATOR_CLIENT_CPP_BUILD_TESTS) set(ALTERNATOR_CLIENT_CPP_CORE_TEST_SOURCES tests/attribute_value_test.cpp + tests/config_test.cpp tests/header_optimization_test.cpp tests/http_client_test.cpp tests/key_route_affinity_test.cpp diff --git a/include/scylladb/alternator/config.h b/include/scylladb/alternator/config.h index b7e43e4..59822f7 100644 --- a/include/scylladb/alternator/config.h +++ b/include/scylladb/alternator/config.h @@ -10,6 +10,10 @@ #include #include +#ifndef SCYLLADB_ALTERNATOR_CLIENT_CPP_VERSION +#define SCYLLADB_ALTERNATOR_CLIENT_CPP_VERSION "devel" +#endif + namespace scylladb::alternator { struct Credentials { @@ -88,7 +92,7 @@ struct Config { unsigned max_connections = 100; bool reuse_discovery_connections = true; std::vector> content_encoding_decoders; - std::string user_agent = "scylladb-alternator-client-cpp/devel"; + std::string user_agent = "scylladb-alternator-client-cpp/" SCYLLADB_ALTERNATOR_CLIENT_CPP_VERSION; std::shared_ptr header_optimization; NodeHealthStoreConfig node_health; diff --git a/tests/config_test.cpp b/tests/config_test.cpp new file mode 100644 index 0000000..3deea4f --- /dev/null +++ b/tests/config_test.cpp @@ -0,0 +1,24 @@ +#include + +#include + +#include + +using namespace scylladb::alternator; + +TEST(Config, DefaultUserAgentUsesProjectVersion) { + const Config config; + + EXPECT_EQ( + config.user_agent, + std::string("scylladb-alternator-client-cpp/") + SCYLLADB_ALTERNATOR_CLIENT_CPP_VERSION); + EXPECT_NE(config.user_agent, "scylladb-alternator-client-cpp/devel"); +} + +TEST(Config, UserAgentCanBeCleared) { + Config config; + + config.user_agent.clear(); + + EXPECT_TRUE(config.user_agent.empty()); +}