diff --git a/test/src/unit-curl.cc b/test/src/unit-curl.cc index 7ae68275e38..6d0befd5aca 100644 --- a/test/src/unit-curl.cc +++ b/test/src/unit-curl.cc @@ -31,7 +31,9 @@ */ #include +#include "test/support/src/helpers.h" #include "tiledb/sm/rest/curl.h" +#include "tiledb/sm/rest/rest_client.h" #ifdef _WIN32 #include "tiledb/sm/filesystem/win.h" @@ -39,6 +41,9 @@ #include "tiledb/sm/filesystem/posix.h" #endif +#include +#include + using namespace tiledb::sm; TEST_CASE("CURL: Test curl's header parsing callback", "[curl]") { @@ -91,3 +96,38 @@ TEST_CASE("CURL: Test curl's header parsing callback", "[curl]") { userdata.redirect_uri_map->find(ns_array)->second == "tiledb://my_username"); } + +TEST_CASE( + "RestClient: Remove trailing slash from rest_server_", "[rest-client]") { + std::string rest_server = + GENERATE("http://localhost:8080/", "http://localhost:8080//"); + tiledb::sm::Config cfg; + SECTION("rest.server_address set in Config") { + cfg.set("rest.server_address", rest_server).ok(); + } + SECTION("rest.server_address set in environment") { + setenv("TILEDB_REST_SERVER_ADDRESS", rest_server.c_str(), 1); + } + SECTION("rest.server_address set by loaded config file") { + std::string cfg_file = "tiledb_config.txt"; + std::ofstream file(cfg_file); + file << "rest.server_address " << rest_server << std::endl; + file.close(); + cfg.load_from_file(cfg_file).ok(); + std::filesystem::remove(cfg_file); + } + + ThreadPool tp{1}; + ContextResources resources( + cfg, tiledb::test::g_helper_logger(), 1, 1, "test"); + tiledb::sm::RestClient rest_client; + REQUIRE(rest_client + .init( + &tiledb::test::g_helper_stats, + &cfg, + &tp, + tiledb::test::g_helper_logger(), + resources) + .ok()); + CHECK(rest_client.rest_server() == "http://localhost:8080"); +} diff --git a/tiledb/sm/rest/rest_client.h b/tiledb/sm/rest/rest_client.h index 737e671ebc4..e3e67ddb3b7 100644 --- a/tiledb/sm/rest/rest_client.h +++ b/tiledb/sm/rest/rest_client.h @@ -385,6 +385,10 @@ class RestClient { */ Status post_vacuum_to_rest(const URI& uri, const Config& config); + inline std::string rest_server() const { + return rest_server_; + } + private: /* ********************************* */ /* PRIVATE ATTRIBUTES */