From 792f9c03bb793bbbacdf651485214741d511ce6e Mon Sep 17 00:00:00 2001 From: Ali Beyad Date: Fri, 23 Aug 2024 19:03:37 +0000 Subject: [PATCH] more Signed-off-by: Ali Beyad --- .../udp/udp_proxy/udp_proxy_filter_test.cc | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/test/extensions/filters/udp/udp_proxy/udp_proxy_filter_test.cc b/test/extensions/filters/udp/udp_proxy/udp_proxy_filter_test.cc index 97119f4467be..51e658a86dbc 100644 --- a/test/extensions/filters/udp/udp_proxy/udp_proxy_filter_test.cc +++ b/test/extensions/filters/udp/udp_proxy/udp_proxy_filter_test.cc @@ -116,29 +116,46 @@ class UdpProxyFilterTest : public UdpProxyFilterBase { EXPECT_CALL(*socket_->io_handle_, connect(_)).Times(0); } if (!connect_sys_errno) { - EXPECT_CALL(*socket_->io_handle_, isConnected()).WillOnce(Return(false)); - EXPECT_CALL(*socket_->io_handle_, sendmsg(_, 1, 0, _, _)) - .WillOnce(Invoke( - [this, data, local_ip, sys_errno]( - const Buffer::RawSlice* slices, uint64_t, int, - const Network::Address::Ip* self_ip, - const Network::Address::Instance& peer_address) -> Api::IoCallUint64Result { - EXPECT_EQ(data, absl::string_view(static_cast(slices[0].mem_), - slices[0].len_)); - EXPECT_EQ(peer_address, *upstream_address_); - if (local_ip == nullptr) { - EXPECT_EQ(nullptr, self_ip); - } else { - EXPECT_EQ(self_ip->addressAsString(), local_ip->addressAsString()); - } - // For suppression of clang-tidy NewDeleteLeaks rule, don't use the ternary - // operator. - if (sys_errno == 0) { - return makeNoError(data.size()); - } else { - return makeError(sys_errno); - } - })); + if (expect_connect) { + EXPECT_CALL(*socket_->io_handle_, isConnected()).WillOnce(Return(true)); + EXPECT_CALL(*socket_->io_handle_, writev(_, 1)) + .WillOnce(Invoke([data, sys_errno](const Buffer::RawSlice* slices, + uint64_t) -> Api::IoCallUint64Result { + EXPECT_EQ(data, absl::string_view(static_cast(slices[0].mem_), + slices[0].len_)); + // For suppression of clang-tidy NewDeleteLeaks rule, don't use the ternary + // operator. + if (sys_errno == 0) { + return makeNoError(data.size()); + } else { + return makeError(sys_errno); + } + })); + } else { + EXPECT_CALL(*socket_->io_handle_, isConnected()).WillOnce(Return(false)); + EXPECT_CALL(*socket_->io_handle_, sendmsg(_, 1, 0, _, _)) + .WillOnce(Invoke( + [this, data, local_ip, sys_errno]( + const Buffer::RawSlice* slices, uint64_t, int, + const Network::Address::Ip* self_ip, + const Network::Address::Instance& peer_address) -> Api::IoCallUint64Result { + EXPECT_EQ(data, absl::string_view(static_cast(slices[0].mem_), + slices[0].len_)); + EXPECT_EQ(peer_address, *upstream_address_); + if (local_ip == nullptr) { + EXPECT_EQ(nullptr, self_ip); + } else { + EXPECT_EQ(self_ip->addressAsString(), local_ip->addressAsString()); + } + // For suppression of clang-tidy NewDeleteLeaks rule, don't use the ternary + // operator. + if (sys_errno == 0) { + return makeNoError(data.size()); + } else { + return makeError(sys_errno); + } + })); + } } }