-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a helper class for runtime-derived uint32 #16398
Changes from 2 commits
0a34c9b
f553f65
eed421c
682f4c1
a1cffc4
0d86df8
9f39b77
9fd4ead
0610dcf
4e22777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,25 @@ class RuntimeProtosTest : public testing::Test { | |
NiceMock<MockLoader> runtime_; | ||
}; | ||
|
||
TEST_F(RuntimeProtosTest, UInt32Test) { | ||
envoy::config::core::v3::RuntimeUInt32 uint32_proto; | ||
std::string yaml(R"EOF( | ||
runtime_key: "foo.bar" | ||
default_value: 99 | ||
)EOF"); | ||
TestUtility::loadFromYamlAndValidate(yaml, uint32_proto); | ||
UInt32 test_uint32(uint32_proto, runtime_); | ||
|
||
EXPECT_CALL(runtime_.snapshot_, getInteger("foo.bar", 99)); | ||
EXPECT_EQ(99, test_uint32.value()); | ||
|
||
EXPECT_CALL(runtime_.snapshot_, getInteger("foo.bar", 99)).WillOnce(Return(1024)); | ||
EXPECT_EQ(1024, test_uint32.value()); | ||
|
||
EXPECT_CALL(runtime_.snapshot_, getInteger("foo.bar", 99)).WillOnce(Return(1ull << 33)); | ||
EXPECT_EQ(0, test_uint32.value()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In cases where getInteger returns a value larger than uint32 max, should this mask the returned value down to 32 bits or return the default value? Consistency between the behavior of getDouble and getInteger for values larger than uint64 max suggest that we should return the default in this case. https://github.com/envoyproxy/envoy/blob/main/source/common/runtime/runtime_impl.h#L104 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value is indeed more reasonable, I'll submit a commit to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in the latest commit. @antoniovicente |
||
} | ||
|
||
TEST_F(RuntimeProtosTest, PercentBasicTest) { | ||
envoy::config::core::v3::RuntimePercent percent_proto; | ||
std::string yaml(R"EOF( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding a unit test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.