1919
2020#include " catch.hpp"
2121#include " Session.h"
22+ #include " SessionBuilder.h"
2223
2324using namespace std ;
2425
@@ -62,6 +63,42 @@ TEST_CASE("Create timeseries success", "[createTimeseries]") {
6263 session->deleteTimeseries (" root.test.d1.s1" );
6364}
6465
66+ TEST_CASE (" Test Session constructor with nodeUrls" , " [SessionInitAndOperate]" ) {
67+ CaseReporter cr (" SessionInitWithNodeUrls" );
68+
69+ std::vector<std::string> nodeUrls = {" 127.0.0.1:6667" };
70+ std::shared_ptr<Session> localSession = std::make_shared<Session>(nodeUrls, " root" , " root" );
71+ localSession->open ();
72+ if (!localSession->checkTimeseriesExists (" root.test.d1.s1" )) {
73+ localSession->createTimeseries (" root.test.d1.s1" , TSDataType::INT64 , TSEncoding::RLE , CompressionType::SNAPPY );
74+ }
75+ REQUIRE (localSession->checkTimeseriesExists (" root.test.d1.s1" ) == true );
76+ localSession->deleteTimeseries (" root.test.d1.s1" );
77+ localSession->close ();
78+ }
79+
80+ TEST_CASE (" Test Session builder with nodeUrls" , " [SessionBuilderInit]" ) {
81+ CaseReporter cr (" SessionInitWithNodeUrls" );
82+
83+ std::vector<std::string> nodeUrls = {" 127.0.0.1:6667" };
84+ auto builder = std::unique_ptr<SessionBuilder>(new SessionBuilder ());
85+ std::shared_ptr<Session> session =
86+ std::shared_ptr<Session>(
87+ builder
88+ ->username (" root" )
89+ ->password (" root" )
90+ ->nodeUrls (nodeUrls)
91+ ->build ()
92+ );
93+ session->open ();
94+ if (!session->checkTimeseriesExists (" root.test.d1.s1" )) {
95+ session->createTimeseries (" root.test.d1.s1" , TSDataType::INT64 , TSEncoding::RLE , CompressionType::SNAPPY );
96+ }
97+ REQUIRE (session->checkTimeseriesExists (" root.test.d1.s1" ) == true );
98+ session->deleteTimeseries (" root.test.d1.s1" );
99+ session->close ();
100+ }
101+
65102TEST_CASE (" Delete timeseries success" , " [deleteTimeseries]" ) {
66103 CaseReporter cr (" deleteTimeseries" );
67104 if (!session->checkTimeseriesExists (" root.test.d1.s1" )) {
@@ -715,3 +752,62 @@ TEST_CASE("Test executeLastDataQuery ", "[testExecuteLastDataQuery]") {
715752 sessionDataSet->setFetchSize (1024 );
716753 REQUIRE (sessionDataSet->hasNext () == false );
717754}
755+
756+ // Helper function for comparing TEndPoint with detailed error message
757+ void assertTEndPointEqual (const TEndPoint& actual,
758+ const std::string& expectedIp,
759+ int expectedPort,
760+ const char * file,
761+ int line) {
762+ if (actual.ip != expectedIp || actual.port != expectedPort) {
763+ std::stringstream ss;
764+ ss << " \n TEndPoint mismatch:\n Expected: " << expectedIp << " :" << expectedPort
765+ << " \n Actual: " << actual.ip << " :" << actual.port ;
766+ Catch::SourceLineInfo location (file, line);
767+ Catch::AssertionHandler handler (" TEndPoint comparison" , location, ss.str (), Catch::ResultDisposition::Normal);
768+ handler.handleMessage (Catch::ResultWas::ExplicitFailure, ss.str ());
769+ handler.complete ();
770+ }
771+ }
772+
773+ // Macro to simplify test assertions
774+ #define REQUIRE_TENDPOINT (actual, expectedIp, expectedPort ) \
775+ assertTEndPointEqual (actual, expectedIp, expectedPort, __FILE__, __LINE__)
776+
777+ TEST_CASE(" UrlUtils - parseTEndPointIpv4AndIpv6Url" , " [UrlUtils]" ) {
778+ // Test valid IPv4 addresses
779+ SECTION (" Valid IPv4" ) {
780+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" 192.168.1.1:8080" ), " 192.168.1.1" , 8080 );
781+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" 10.0.0.1:80" ), " 10.0.0.1" , 80 );
782+ }
783+
784+ // Test valid IPv6 addresses
785+ SECTION (" Valid IPv6" ) {
786+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" [2001:db8::1]:8080" ), " 2001:db8::1" , 8080 );
787+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" [::1]:80" ), " ::1" , 80 );
788+ }
789+
790+ // Test hostnames
791+ SECTION (" Hostnames" ) {
792+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" localhost:8080" ), " localhost" , 8080 );
793+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" example.com:443" ), " example.com" , 443 );
794+ }
795+
796+ // Test edge cases
797+ SECTION (" Edge cases" ) {
798+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" " ), " " , 0 );
799+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" 127.0.0.1" ), " 127.0.0.1" , 0 );
800+ }
801+
802+ // Test invalid inputs
803+ SECTION (" Invalid inputs" ) {
804+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" 192.168.1.1:abc" ), " 192.168.1.1:abc" , 0 );
805+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" ]invalid[:80" ), " ]invalid[" , 80 );
806+ }
807+
808+ // Test port ranges
809+ SECTION (" Port ranges" ) {
810+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" localhost:0" ), " localhost" , 0 );
811+ REQUIRE_TENDPOINT (UrlUtils::parseTEndPointIpv4AndIpv6Url (" 127.0.0.1:65535" ), " 127.0.0.1" , 65535 );
812+ }
813+ }
0 commit comments