Skip to content

Commit

Permalink
Simplify linking; fix log setting; improve unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xg0nz0 committed Mar 1, 2024
1 parent da30bcb commit 690a699
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
}
}
],
"testMate.cpp.log.logpanel": true,
"testMate.cpp.log.logfile": "/workspaces/iggy-cpp-client/testMate.log",
"files.associations": {
"any": "cpp",
"array": "cpp",
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ add_library(
)
target_compile_features(iggy PRIVATE cxx_std_17)
target_include_directories(iggy PRIVATE ${SODIUM_INCLUDE_DIR} ${ADA_INCLUDE_DIR})
target_link_libraries(
iggy PRIVATE

ada::ada
libuv::uv_a
unofficial-sodium::sodium
)

if (BUILD_TESTS)
add_subdirectory(tests)
Expand Down
1 change: 1 addition & 0 deletions sdk/net/address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ iggy::net::address::LogicalAddress::LogicalAddress(const std::string& url, const
}
auto value = parse_result.value();
auto protocol = value.get_protocol();
protocol = protocol.substr(0, protocol.length() - 1);
if (!protocolProvider->isSupported(protocol)) {
throw std::invalid_argument("Unsupported protocol: " + protocol);
}
Expand Down
5 changes: 4 additions & 1 deletion sdk/net/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class LogicalAddress {
/**
* @brief Gets the protocol; you have a guarantee that it will be one of the supported protocols from ProtocolProvider.
*/
const std::string getProtocol() const noexcept { return url.get_protocol(); }
const std::string getProtocol() const noexcept {
auto protocol = url.get_protocol();
return protocol.substr(0, protocol.length() - 1);
}

/**
* @brief Gets the hostname to connect to or raw IP address.
Expand Down
12 changes: 6 additions & 6 deletions sdk/net/iggy.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const unsigned short DEFAULT_HTTP_PORT = 3000;
const unsigned short DEFAULT_TCP_PORT = 8090;
const unsigned short DEFAULT_QUIC_PORT = 8080;

const std::string QUIC_PROTOCOL = "iggy:quic";
const std::string TCP_PROTOCOL = "iggy:tcp";
const std::string TCP_TLS_PROTOCOL = "iggy:tcp+tls";
const std::string HTTP_PROTOCOL = "iggy:http";
const std::string HTTP_TLS_PROTOCOL = "iggy:http+tls";
const std::string QUIC_PROTOCOL = "quic";
const std::string TCP_PROTOCOL = "tcp";
const std::string TCP_TLS_PROTOCOL = "tcp+tls";
const std::string HTTP_PROTOCOL = "http";
const std::string HTTP_TLS_PROTOCOL = "http+tls";

using iggy::net::protocol::MessageEncoding;
using iggy::net::protocol::ProtocolDefinition;
Expand All @@ -24,7 +24,7 @@ using iggy::net::protocol::ProtocolDefinition;
*
* At this time we support iggy:quic, iggy:tcp (binary messaging) and iggy:http (with JSON messaging).
*/
class IggyProtocolProvider : iggy::net::protocol::ProtocolProvider {
class IggyProtocolProvider : public iggy::net::protocol::ProtocolProvider {
private:
std::vector<ProtocolDefinition> supportedProtocols = {
ProtocolDefinition(QUIC_PROTOCOL, DEFAULT_QUIC_PORT, iggy::net::transport::QUIC, true, MessageEncoding::BINARY),
Expand Down
8 changes: 2 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ if(BUILD_TESTS)
iggy_cpp_test

model_test.cc
iggy_protocol_provider_test.cc
)
target_link_libraries(
iggy_cpp_test

iggy
Catch2::Catch2
Catch2::Catch2WithMain
libuv::uv_a
reproc++
unofficial-sodium::sodium
)

add_executable(
Expand All @@ -33,8 +31,6 @@ if(BUILD_TESTS)
iggy
Catch2::Catch2
Catch2::Catch2WithMain
libuv::uv_a
reproc++
unofficial-sodium::sodium
)
)
endif()
34 changes: 34 additions & 0 deletions tests/iggy_protocol_provider_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#define CATCH_CONFIG_MAIN
#include "../sdk/net/iggy.h"
#include "unit_testutils.h"

TEST_CASE("check supported Iggy protocols", UT_TAG) {
iggy::net::IggyProtocolProvider provider;

SECTION("enumerate supported protocols") {
REQUIRE(provider.getSupportedProtocols().size() == 5);
}

SECTION("check supported protocol definitions") {
auto [protocolName, tlsSupported] =
GENERATE(table<std::string, bool>({{"quic", true}, {"tcp", false}, {"tcp+tls", true}, {"http", false}, {"http+tls", true}}));

REQUIRE(provider.isSupported(protocolName));
REQUIRE(provider.getProtocolDefinition(protocolName).getName() == protocolName);
REQUIRE(provider.getProtocolDefinition(protocolName).isTlsSupported() == tlsSupported);
}

SECTION("create addresses") {
auto [address, protocolName, host, port] =
GENERATE(table<std::string, std::string, std::string, int>({{"quic://localhost:1234", "quic", "localhost", 1234},
{"tcp://localhost:1234", "tcp", "localhost", 1234},
{"tcp+tls://localhost:1234", "tcp+tls", "localhost", 1234},
{"http://localhost:1234", "http", "localhost", 1234},
{"http+tls://localhost:1234", "http+tls", "localhost", 1234}}));

auto addr = provider.createAddress(address);
REQUIRE(addr.getProtocol() == protocolName);
REQUIRE(addr.getHost() == host);
REQUIRE(addr.getPort() == port);
}
}

0 comments on commit 690a699

Please sign in to comment.