-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathhttp_client_tests.cpp
More file actions
50 lines (44 loc) · 1.81 KB
/
Copy pathhttp_client_tests.cpp
File metadata and controls
50 lines (44 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <nlohmann/json.hpp>
#include <optional>
#include "databento/detail/http_client.hpp"
#include "databento/log.hpp"
#include "mock/mock_http_server.hpp"
#include "mock/mock_log_receiver.hpp"
namespace databento::detail::tests {
class HttpClientTests : public ::testing::Test {
protected:
static constexpr auto kApiKey = "HIST_SECRET";
databento::tests::mock::MockHttpServer mock_server_{kApiKey};
};
TEST_F(HttpClientTests, TestLogWarnings) {
const nlohmann::json warnings{"DeprecationWarning: stype product_id is deprecated",
"Warning: Large request"};
mock_server_.MockGetJson("/warn", {}, {}, warnings);
const auto port = mock_server_.ListenOnThread();
databento::tests::mock::MockLogReceiver mock_logger{
[](auto call_count, databento::LogLevel level, const std::string& msg) {
EXPECT_EQ(level, LogLevel::Warning);
if (call_count == 0) {
EXPECT_THAT(msg,
testing::EndsWith(
"Server DeprecationWarning: stype product_id is deprecated"));
} else {
EXPECT_THAT(msg, testing::EndsWith("Server Warning: Large request"));
}
}};
HttpClient target{&mock_logger, kApiKey, "localhost",
static_cast<std::uint16_t>(port), std::nullopt};
target.GetJson("/warn", {});
ASSERT_EQ(mock_logger.CallCount(), 2);
}
TEST_F(HttpClientTests, TestHttpClientCallbackInvoked) {
const auto port = mock_server_.ListenOnThread();
bool called = false;
HttpClient target{ILogReceiver::Default(), kApiKey, "localhost",
static_cast<std::uint16_t>(port),
HttpClientCallback{[&called](httplib::Client&) { called = true; }}};
EXPECT_TRUE(called);
}
} // namespace databento::detail::tests