提交 a3b83dcf 编写于 作者: X xy0 提交者: LINGuanRen

fix unittest: test_election_base

上级 a1f04865
......@@ -41,15 +41,25 @@ TEST_F(TestObElectionBase, get_self_addr)
EXPECT_EQ(OB_INVALID_ARGUMENT, get_self_addr(addr, NULL, 0));
{
const char* dev = "null";
const char *dev = "null";
EXPECT_EQ(OB_INVALID_ARGUMENT, get_self_addr(addr, dev, port));
}
{
const char* dev = "bond0";
EXPECT_EQ(OB_SUCCESS, get_self_addr(addr, dev, port));
uint32_t ip = obsys::CNetUtil::getLocalAddr(dev);
EXPECT_EQ(ip, addr.get_ipv4());
EXPECT_EQ(port, addr.get_port());
struct ifaddrs *ifaddr, *ifa;
char host[NI_MAXHOST];
EXPECT_EQ(getifaddrs(&ifaddr), 0);
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL)
continue;
getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (ifa->ifa_addr->sa_family == AF_INET) {
const char *dev = ifa->ifa_name;
EXPECT_EQ(OB_SUCCESS, get_self_addr(addr, dev, port));
uint32_t ip = obsys::CNetUtil::getLocalAddr(dev);
EXPECT_EQ(ip, addr.get_ipv4());
EXPECT_EQ(port, addr.get_port());
}
}
}
}
......@@ -78,7 +88,7 @@ TEST_F(TestObElectionBase, election_stage_name)
} // namespace unittest
} // namespace oceanbase
int main(int argc, char** argv)
int main(int argc, char **argv)
{
int ret = -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册