Skip to content

Commit

Permalink
add ut for gatewayconfig parse hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasLi1024 committed Jan 29, 2024
1 parent 4e7cd43 commit ec0a5d6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions bcos-gateway/test/unittests/GatewayConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,33 @@ BOOST_AUTO_TEST_CASE(test_validIP)
BOOST_CHECK(config->isValidIP("1111::1111:1111:1111:1111"));
}

BOOST_AUTO_TEST_CASE(test_isIPAddress)
{
auto config = std::make_shared<GatewayConfig>();

BOOST_CHECK(!config->isIPAddress("a"));
BOOST_CHECK(!config->isIPAddress("127"));
BOOST_CHECK(!config->isIPAddress("127.0"));
BOOST_CHECK(!config->isIPAddress("127.0.0"));
BOOST_CHECK(!config->isIPAddress("127.0.0.1.0"));

// ipv4
BOOST_CHECK(config->isIPAddress("127.0.0.1"));
BOOST_CHECK(config->isIPAddress("192.168.0.1"));
BOOST_CHECK(config->isIPAddress("64.120.121.206"));

// ipv6
BOOST_CHECK(config->isIPAddress("::1"));
BOOST_CHECK(config->isIPAddress("fe80::58da:28ff:fe08:5d91"));
BOOST_CHECK(config->isIPAddress("1111::1111:1111:1111:1111"));
}

BOOST_AUTO_TEST_CASE(test_isHostname)
{
auto config = std::make_shared<GatewayConfig>();
BOOST_CHECK(config->isHostname("localhost"));
}

BOOST_AUTO_TEST_CASE(test_hostAndPort2Endpoint)
{
auto config = std::make_shared<GatewayConfig>();
Expand All @@ -74,6 +101,14 @@ BOOST_AUTO_TEST_CASE(test_hostAndPort2Endpoint)
BOOST_CHECK(!endpoint.isIPv6());
}

{
NodeIPEndpoint endpoint;
BOOST_CHECK_NO_THROW(config->hostAndPort2Endpoint("localhost:2333", endpoint));
BOOST_CHECK_EQUAL(endpoint.address(), "127.0.0.1");
BOOST_CHECK_EQUAL(endpoint.port(), 2333);
BOOST_CHECK(!endpoint.isIPv6());
}

{
NodeIPEndpoint endpoint;
BOOST_CHECK_NO_THROW(config->hostAndPort2Endpoint("[::1]:1234", endpoint));
Expand Down

0 comments on commit ec0a5d6

Please sign in to comment.