|
43 | 43 | TEST_CASE("C API: Test context tags", "[capi][ctx-tags]") { |
44 | 44 | tiledb_ctx_t* ctx = nullptr; |
45 | 45 | REQUIRE(tiledb_ctx_alloc(nullptr, &ctx) == TILEDB_OK); |
46 | | - tiledb::sm::StorageManager* sm = ctx->storage_manager(); |
47 | 46 |
|
48 | | - // Check defaults |
49 | | - REQUIRE(sm->tags().size() == 2); |
50 | | - REQUIRE(sm->tags().at("x-tiledb-api-language") == "c"); |
51 | | - REQUIRE( |
52 | | - sm->tags().at("x-tiledb-version") == |
53 | | - (std::to_string(tiledb::sm::constants::library_version[0]) + "." + |
54 | | - std::to_string(tiledb::sm::constants::library_version[1]) + "." + |
55 | | - std::to_string(tiledb::sm::constants::library_version[2]))); |
| 47 | + // Only run these tests if the rest client has been initialized |
| 48 | + if (ctx->has_rest_client()) { |
| 49 | + auto& rest_client{ctx->rest_client()}; |
| 50 | + SECTION("Defaults") { |
| 51 | + REQUIRE(rest_client.extra_headers().size() == 2); |
| 52 | + REQUIRE(rest_client.extra_headers().at("x-tiledb-api-language") == "c"); |
| 53 | + REQUIRE( |
| 54 | + rest_client.extra_headers().at("x-tiledb-version") == |
| 55 | + (std::to_string(tiledb::sm::constants::library_version[0]) + "." + |
| 56 | + std::to_string(tiledb::sm::constants::library_version[1]) + "." + |
| 57 | + std::to_string(tiledb::sm::constants::library_version[2]))); |
| 58 | + } |
| 59 | + SECTION("tiledb_ctx_set_tag") { |
| 60 | + REQUIRE(tiledb_ctx_set_tag(ctx, "tag1", "value1") == TILEDB_OK); |
| 61 | + REQUIRE(rest_client.extra_headers().size() == 3); |
| 62 | + REQUIRE(rest_client.extra_headers().at("tag1") == "value1"); |
56 | 63 |
|
57 | | - // Check setter |
58 | | - REQUIRE(tiledb_ctx_set_tag(ctx, "tag1", "value1") == TILEDB_OK); |
59 | | - REQUIRE(sm->tags().size() == 3); |
60 | | - REQUIRE(sm->tags().at("tag1") == "value1"); |
61 | | - |
62 | | - REQUIRE(tiledb_ctx_set_tag(ctx, "tag2", "value2") == TILEDB_OK); |
63 | | - REQUIRE(sm->tags().size() == 4); |
64 | | - REQUIRE(sm->tags().at("tag2") == "value2"); |
65 | | - |
66 | | - REQUIRE(tiledb_ctx_set_tag(ctx, "tag1", "value3") == TILEDB_OK); |
67 | | - REQUIRE(sm->tags().size() == 4); |
68 | | - REQUIRE(sm->tags().at("tag1") == "value3"); |
| 64 | + REQUIRE(tiledb_ctx_set_tag(ctx, "tag2", "value2") == TILEDB_OK); |
| 65 | + REQUIRE(rest_client.extra_headers().size() == 4); |
| 66 | + REQUIRE(rest_client.extra_headers().at("tag2") == "value2"); |
69 | 67 |
|
| 68 | + REQUIRE(tiledb_ctx_set_tag(ctx, "tag1", "value3") == TILEDB_OK); |
| 69 | + REQUIRE(rest_client.extra_headers().size() == 4); |
| 70 | + REQUIRE(rest_client.extra_headers().at("tag1") == "value3"); |
| 71 | + } |
| 72 | + } |
70 | 73 | tiledb_ctx_free(&ctx); |
71 | 74 | } |
72 | 75 |
|
73 | 76 | TEST_CASE("C++ API: Test context tags", "[cppapi][ctx-tags]") { |
74 | 77 | tiledb::Context ctx; |
75 | | - tiledb::sm::StorageManager* sm = ctx.ptr().get()->storage_manager(); |
76 | | - |
77 | | - // Check defaults |
78 | | - REQUIRE(sm->tags().size() == 2); |
79 | | - REQUIRE(sm->tags().at("x-tiledb-api-language") == "c++"); |
80 | | - REQUIRE( |
81 | | - sm->tags().at("x-tiledb-version") == |
82 | | - (std::to_string(tiledb::sm::constants::library_version[0]) + "." + |
83 | | - std::to_string(tiledb::sm::constants::library_version[1]) + "." + |
84 | | - std::to_string(tiledb::sm::constants::library_version[2]))); |
85 | 78 |
|
86 | | - // Check setter |
87 | | - REQUIRE_NOTHROW(ctx.set_tag("tag1", "value1")); |
88 | | - REQUIRE(sm->tags().size() == 3); |
89 | | - REQUIRE(sm->tags().at("tag1") == "value1"); |
| 79 | + // Only run these tests if the rest client has been initialized |
| 80 | + if (ctx.ptr().get()->has_rest_client()) { |
| 81 | + auto& rest_client{ctx.ptr().get()->rest_client()}; |
| 82 | + SECTION("Defaults") { |
| 83 | + REQUIRE(rest_client.extra_headers().size() == 2); |
| 84 | + REQUIRE(rest_client.extra_headers().at("x-tiledb-api-language") == "c++"); |
| 85 | + REQUIRE( |
| 86 | + rest_client.extra_headers().at("x-tiledb-version") == |
| 87 | + (std::to_string(tiledb::sm::constants::library_version[0]) + "." + |
| 88 | + std::to_string(tiledb::sm::constants::library_version[1]) + "." + |
| 89 | + std::to_string(tiledb::sm::constants::library_version[2]))); |
| 90 | + } |
| 91 | + SECTION("tiledb_ctx_set_tag") { |
| 92 | + REQUIRE_NOTHROW(ctx.set_tag("tag1", "value1")); |
| 93 | + REQUIRE(rest_client.extra_headers().size() == 3); |
| 94 | + REQUIRE(rest_client.extra_headers().at("tag1") == "value1"); |
90 | 95 |
|
91 | | - REQUIRE_NOTHROW(ctx.set_tag("tag2", "value2")); |
92 | | - REQUIRE(sm->tags().size() == 4); |
93 | | - REQUIRE(sm->tags().at("tag2") == "value2"); |
| 96 | + REQUIRE_NOTHROW(ctx.set_tag("tag2", "value2")); |
| 97 | + REQUIRE(rest_client.extra_headers().size() == 4); |
| 98 | + REQUIRE(rest_client.extra_headers().at("tag2") == "value2"); |
94 | 99 |
|
95 | | - REQUIRE_NOTHROW(ctx.set_tag("tag1", "value3")); |
96 | | - REQUIRE(sm->tags().size() == 4); |
97 | | - REQUIRE(sm->tags().at("tag1") == "value3"); |
| 100 | + REQUIRE_NOTHROW(ctx.set_tag("tag1", "value3")); |
| 101 | + REQUIRE(rest_client.extra_headers().size() == 4); |
| 102 | + REQUIRE(rest_client.extra_headers().at("tag1") == "value3"); |
| 103 | + } |
| 104 | + } |
98 | 105 | } |
0 commit comments