Skip to content

Commit

Permalink
dynamic_modules: add more test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
  • Loading branch information
mathetake committed Feb 21, 2025
1 parent f1e276f commit 54b4372
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/extensions/dynamic_modules/http/abi_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,21 @@ TEST(ABIImpl, dynamic_metadata) {
&filter, namespace_ptr, namespace_length, key_ptr, key_length, &result_str_ptr,
&result_str_length));

// With namespace but non existing key.
const char* non_existing_key = "non_existing";
envoy_dynamic_module_type_buffer_module_ptr non_existing_key_ptr =
const_cast<char*>(non_existing_key);
size_t non_existing_key_length = strlen(non_existing_key);
// This will create the namespace.
EXPECT_TRUE(envoy_dynamic_module_callback_http_set_dynamic_metadata_number(
&filter, namespace_ptr, namespace_length, key_ptr, key_length, value));
EXPECT_FALSE(envoy_dynamic_module_callback_http_get_dynamic_metadata_number(
&filter, namespace_ptr, namespace_length, non_existing_key_ptr, non_existing_key_length,
&result_number));
EXPECT_FALSE(envoy_dynamic_module_callback_http_get_dynamic_metadata_string(
&filter, namespace_ptr, namespace_length, non_existing_key_ptr, non_existing_key_length,
&result_str_ptr, &result_str_length));

// With namespace and key.
EXPECT_TRUE(envoy_dynamic_module_callback_http_set_dynamic_metadata_number(
&filter, namespace_ptr, namespace_length, key_ptr, key_length, value));
Expand Down Expand Up @@ -565,6 +580,17 @@ TEST(ABIImpl, ResponseBody) {
EXPECT_FALSE(envoy_dynamic_module_callback_http_append_response_body(&filter, nullptr, 0));
EXPECT_FALSE(envoy_dynamic_module_callback_http_drain_response_body(&filter, 0));

// Buffer is available via current_response_body_, not the stream encoder.
const std::string data = "foo";
Buffer::OwnedImpl current_buffer;
filter.current_response_body_ = &current_buffer;
EXPECT_TRUE(envoy_dynamic_module_callback_http_append_response_body(
&filter, const_cast<char*>(data.data()), 3));
EXPECT_EQ(current_buffer.toString(), data);
EXPECT_TRUE(envoy_dynamic_module_callback_http_drain_response_body(&filter, 3));
EXPECT_EQ(current_buffer.toString(), "");
filter.current_response_body_ = nullptr;

Buffer::OwnedImpl buffer;
EXPECT_CALL(callbacks, encodingBuffer()).WillRepeatedly(testing::Return(&buffer));
EXPECT_CALL(callbacks, modifyEncodingBuffer(_))
Expand All @@ -577,7 +603,6 @@ TEST(ABIImpl, ResponseBody) {
EXPECT_TRUE(envoy_dynamic_module_callback_http_drain_response_body(&filter, 0));

// Append data to the buffer.
const std::string data = "foo";
envoy_dynamic_module_type_buffer_module_ptr data_ptr = const_cast<char*>(data.data());
size_t data_length = data.size();
EXPECT_TRUE(
Expand Down

0 comments on commit 54b4372

Please sign in to comment.