Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunrd0 committed Mar 8, 2024
1 parent a75489d commit 557214f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/src/unit-curl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@
*/

#include <test/support/tdb_catch.h>
#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"
#else
#include "tiledb/sm/filesystem/posix.h"
#endif

#include <filesystem>
#include <fstream>

using namespace tiledb::sm;

TEST_CASE("CURL: Test curl's header parsing callback", "[curl]") {
Expand Down Expand Up @@ -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");
}
4 changes: 4 additions & 0 deletions tiledb/sm/rest/rest_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 557214f

Please sign in to comment.