Skip to content

Commit

Permalink
lua: adds test to cover LUA_TNIL metadata conversion (#34983)
Browse files Browse the repository at this point in the history
Commit Message: lua: adds test to cover LUA_TNIL metadata conversion
Additional Description: 
Previously, the conversion of LUA_TNIL type in dynamic 
metadata generation had no unit test coverage.
This modifies SetGetAndIterateDynamicMetadata test to cover the logic.


https://github.com/envoyproxy/envoy/blob/416e7a64d1d3f72bf3309938e22ca5f006fe429f/source/extensions/filters/common/lua/wrappers.cc#L140-L142

Risk Level: lo
Testing: done
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake committed Jul 5, 2024
1 parent 1f68c5b commit ad15deb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/extensions/filters/http/lua/wrappers_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,19 @@ TEST_F(LuaStreamInfoWrapperTest, ReturnRequestedServerName) {

// Set, get and iterate stream info dynamic metadata.
TEST_F(LuaStreamInfoWrapperTest, SetGetAndIterateDynamicMetadata) {
const std::string SCRIPT{R"EOF(
const std::string SCRIPT{
R"EOF(
function callMe(object)
testPrint(type(object:dynamicMetadata()))
object:dynamicMetadata():set("envoy.lb", "foo", "bar")
object:dynamicMetadata():set("envoy.lb", "so", "cool")
object:dynamicMetadata():set("envoy.lb", "nothing", nil)
testPrint(object:dynamicMetadata():get("envoy.lb")["foo"])
testPrint(object:dynamicMetadata():get("envoy.lb")["so"])
if object:dynamicMetadata():get("envoy.lb")["nothing"] == nil then
testPrint("yes")
end
for filter, entry in pairs(object:dynamicMetadata()) do
for key, value in pairs(entry) do
Expand All @@ -430,6 +435,7 @@ TEST_F(LuaStreamInfoWrapperTest, SetGetAndIterateDynamicMetadata) {
EXPECT_CALL(printer_, testPrint("cool"));
EXPECT_CALL(printer_, testPrint("'foo' 'bar'"));
EXPECT_CALL(printer_, testPrint("'so' 'cool'"));
EXPECT_CALL(printer_, testPrint("yes"));
EXPECT_CALL(printer_, testPrint("0"));
start("callMe");

Expand All @@ -440,6 +446,12 @@ TEST_F(LuaStreamInfoWrapperTest, SetGetAndIterateDynamicMetadata) {
.fields()
.at("foo")
.string_value());
EXPECT_TRUE(stream_info.dynamicMetadata()
.filter_metadata()
.at("envoy.lb")
.fields()
.at("nothing")
.has_null_value());
wrapper.reset();
}

Expand Down

0 comments on commit ad15deb

Please sign in to comment.