Skip to content

Commit

Permalink
Make Context::HasKey const (open-telemetry#671)
Browse files Browse the repository at this point in the history
- Update `Context::HasKey` to be const
- Add const qualifier to HasKey,GetValue to validate constness
  • Loading branch information
eyjohn authored Apr 12, 2021
1 parent 9a99b97 commit d129d42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/include/opentelemetry/context/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Context
}

// Checks for key and returns true if found
bool HasKey(const nostd::string_view key) noexcept
bool HasKey(const nostd::string_view key) const noexcept
{
for (DataList *data = head_.get(); data != nullptr; data = data->next_.get())
{
Expand Down
4 changes: 2 additions & 2 deletions api/test/context/context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(ContextTest, ContextGetValueReturnsExpectedValue)
{
std::map<std::string, context::ContextValue> map_test = {{"test_key", (int64_t)123},
{"foo_key", (int64_t)456}};
context::Context test_context = context::Context(map_test);
const context::Context test_context = context::Context(map_test);
EXPECT_EQ(nostd::get<int64_t>(test_context.GetValue("test_key")), 123);
EXPECT_EQ(nostd::get<int64_t>(test_context.GetValue("foo_key")), 456);
}
Expand Down Expand Up @@ -119,7 +119,7 @@ TEST(ContextTest, ContextEmptyMap)
TEST(ContextTest, ContextHasKey)
{
std::map<std::string, context::ContextValue> map_test = {{"test_key", (int64_t)123}};
context::Context context_test = context::Context(map_test);
const context::Context context_test = context::Context(map_test);
EXPECT_TRUE(context_test.HasKey("test_key"));
EXPECT_FALSE(context_test.HasKey("foo_key"));
}
Expand Down

0 comments on commit d129d42

Please sign in to comment.