Skip to content

Commit

Permalink
add v6 localhost test
Browse files Browse the repository at this point in the history
  • Loading branch information
bradh352 committed Dec 27, 2024
1 parent 2be799d commit 0435d33
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/ares-test-mock-ai.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,58 @@ CONTAINED_TEST_P(ContainedMockChannelAISysConfig, v4OnlyLocalHostUnspec,
}


static NameContentList files_localhost_v6localhostonly = {
{"/etc/resolv.conf", "nameserver 1.2.3.4\n" // Will be replaced
"search example.com example.org\n"
"options edns0 trust-ad\n"}, // ndots:1 is default
{"/etc/hosts", "::1 localhost\n"},
{"/etc/nsswitch.conf", "hosts: files dns\n"}};
CONTAINED_TEST_P(ContainedMockChannelAISysConfig, v6OnlyLocalHostv4,
"myhostname", "mydomainname.org", files_localhost_v6localhostonly) {
AddrInfoResult result = {};
struct ares_addrinfo_hints hints = {0, 0, 0, 0};
hints.ai_family = AF_INET;
hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "localhost", NULL, &hints, AddrInfoCallback, &result);
Process();
EXPECT_TRUE(result.done_);
EXPECT_EQ(result.status_, ARES_SUCCESS);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result.ai_, IncludesV4Address("127.0.0.1"));
return HasFailure();
}

CONTAINED_TEST_P(ContainedMockChannelAISysConfig, v6OnlyLocalHostv6,
"myhostname", "mydomainname.org", files_localhost_v6localhostonly) {
AddrInfoResult result = {};
struct ares_addrinfo_hints hints = {0, 0, 0, 0};
hints.ai_family = AF_INET6;
hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "localhost", NULL, &hints, AddrInfoCallback, &result);
Process();
EXPECT_TRUE(result.done_);
EXPECT_EQ(result.status_, ARES_SUCCESS);
EXPECT_THAT(result.ai_, IncludesNumAddresses(1));
EXPECT_THAT(result.ai_, IncludesV6Address("0000:0000:0000:0000:0000:0000:0000:0001"));
return HasFailure();
}

CONTAINED_TEST_P(ContainedMockChannelAISysConfig, v6OnlyLocalHostUnspec,
"myhostname", "mydomainname.org", files_localhost_v6localhostonly) {
AddrInfoResult result = {};
struct ares_addrinfo_hints hints = {0, 0, 0, 0};
hints.ai_family = AF_UNSPEC;
hints.ai_flags = ARES_AI_NOSORT;
ares_getaddrinfo(channel_, "localhost", NULL, &hints, AddrInfoCallback, &result);
Process();
EXPECT_TRUE(result.done_);
EXPECT_EQ(result.status_, ARES_SUCCESS);
EXPECT_THAT(result.ai_, IncludesNumAddresses(2));
EXPECT_THAT(result.ai_, IncludesV4Address("127.0.0.1"));
EXPECT_THAT(result.ai_, IncludesV6Address("0000:0000:0000:0000:0000:0000:0000:0001"));
return HasFailure();
}

INSTANTIATE_TEST_SUITE_P(AddressFamiliesAI, ContainedMockChannelAISysConfig, ::testing::ValuesIn(ares::test::families_modes), PrintFamilyMode);
#endif

Expand Down

0 comments on commit 0435d33

Please sign in to comment.