Skip to content

Commit

Permalink
test: fix V6EmptyOptions in coverage with IPv6 enable (envoyproxy#4155)
Browse files Browse the repository at this point in the history
Signed-off-by: Lizan Zhou <zlizan@google.com>
  • Loading branch information
lizan authored and Matt Klein committed Aug 16, 2018
1 parent 1b2219b commit 7c04ac2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -49,8 +49,6 @@ TEST_F(AddrFamilyAwareSocketOptionImplTest, V4EmptyOptionNames) {

// If a platform doesn't support IPv4 and IPv6 socket option variants for an IPv4 address, we fail
TEST_F(AddrFamilyAwareSocketOptionImplTest, V6EmptyOptionNames) {
EXPECT_CALL(os_sys_calls_, socket(_, _, _));
EXPECT_CALL(os_sys_calls_, close(_));
Address::Ipv6Instance address("::1:2:3:4", 5678);
const int fd = address.socket(Address::SocketType::Stream);
EXPECT_CALL(socket_, fd()).WillRepeatedly(Return(fd));
Expand Down
9 changes: 8 additions & 1 deletion test/common/network/socket_option_test.h
Expand Up @@ -23,7 +23,14 @@ class SocketOptionTest : public testing::Test {

NiceMock<MockListenSocket> socket_;
Api::MockOsSysCalls os_sys_calls_;
TestThreadsafeSingletonInjector<Api::OsSysCallsImpl> os_calls{&os_sys_calls_};

TestThreadsafeSingletonInjector<Api::OsSysCallsImpl> os_calls_{[this]() {
// Before injecting OsSysCallsImpl, make sure validateIpv{4,6}Supported is called so the static
// bool is initialized without requiring to mock ::socket and ::close.
std::make_unique<Address::Ipv4Instance>("1.2.3.4", 5678);
std::make_unique<Address::Ipv6Instance>("::1:2:3:4", 5678);
return &os_sys_calls_;
}()};

void testSetSocketOptionSuccess(
Socket::Option& socket_option, Network::SocketOptionName option_name, int option_val,
Expand Down

0 comments on commit 7c04ac2

Please sign in to comment.