Skip to content

Commit

Permalink
refactor usage of tombstone in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Dec 12, 2023
1 parent e9ca7f4 commit de58fa4
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 106 deletions.
37 changes: 18 additions & 19 deletions libs/client-sdk/src/data_sources/data_source_event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ DataSourceEventHandler::MessageStatus DataSourceEventHandler::HandleMessage(
status_manager_.SetError(
DataSourceStatus::ErrorInfo::ErrorKind::kInvalidData,
kErrorParsingPut);
return DataSourceEventHandler::MessageStatus::kInvalidMessage;
return MessageStatus::kInvalidMessage;
}
auto res = boost::json::value_to<tl::expected<
std::optional<std::unordered_map<std::string, ItemDescriptor>>,
Expand All @@ -105,13 +105,13 @@ DataSourceEventHandler::MessageStatus DataSourceEventHandler::HandleMessage(

handler_.Init(context_, std::move(map));
status_manager_.SetState(DataSourceStatus::DataSourceState::kValid);
return DataSourceEventHandler::MessageStatus::kMessageHandled;
return MessageStatus::kMessageHandled;
}
LD_LOG(logger_, LogLevel::kError) << kErrorPutInvalid;
status_manager_.SetError(
DataSourceStatus::ErrorInfo::ErrorKind::kInvalidData,
kErrorPutInvalid);
return DataSourceEventHandler::MessageStatus::kInvalidMessage;
return MessageStatus::kInvalidMessage;
}
if (type == "patch") {
boost::json::error_code error_code;
Expand All @@ -121,21 +121,20 @@ DataSourceEventHandler::MessageStatus DataSourceEventHandler::HandleMessage(
status_manager_.SetError(
DataSourceStatus::ErrorInfo::ErrorKind::kInvalidData,
kErrorParsingPatch);
return DataSourceEventHandler::MessageStatus::kInvalidMessage;
return MessageStatus::kInvalidMessage;
}
auto res = boost::json::value_to<
tl::expected<DataSourceEventHandler::PatchData, JsonError>>(parsed);
auto res =
boost::json::value_to<tl::expected<PatchData, JsonError>>(parsed);
if (res.has_value()) {
handler_.Upsert(
context_, res.value().key,
launchdarkly::client_side::ItemDescriptor(res.value().flag));
return DataSourceEventHandler::MessageStatus::kMessageHandled;
handler_.Upsert(context_, res.value().key,
ItemDescriptor(res.value().flag));
return MessageStatus::kMessageHandled;
}
LD_LOG(logger_, LogLevel::kError) << kErrorPatchInvalid;
status_manager_.SetError(
DataSourceStatus::ErrorInfo::ErrorKind::kInvalidData,
kErrorPatchInvalid);
return DataSourceEventHandler::MessageStatus::kInvalidMessage;
return MessageStatus::kInvalidMessage;
}
if (type == "delete") {
boost::json::error_code error_code;
Expand All @@ -145,22 +144,22 @@ DataSourceEventHandler::MessageStatus DataSourceEventHandler::HandleMessage(
status_manager_.SetError(
DataSourceStatus::ErrorInfo::ErrorKind::kInvalidData,
kErrorParsingDelete);
return DataSourceEventHandler::MessageStatus::kInvalidMessage;
return MessageStatus::kInvalidMessage;
}
auto res = boost::json::value_to<
tl::expected<DataSourceEventHandler::DeleteData, JsonError>>(
auto res = boost::json::value_to<tl::expected<DeleteData, JsonError>>(
boost::json::parse(data));
if (res.has_value()) {
handler_.Upsert(context_, res.value().key,
ItemDescriptor(res.value().version));
return DataSourceEventHandler::MessageStatus::kMessageHandled;
handler_.Upsert(
context_, res.value().key,
ItemDescriptor(data_model::Tombstone(res.value().version)));
return MessageStatus::kMessageHandled;
}
LD_LOG(logger_, LogLevel::kError) << kErrorDeleteInvalid;
status_manager_.SetError(
DataSourceStatus::ErrorInfo::ErrorKind::kInvalidData,
kErrorDeleteInvalid);
return DataSourceEventHandler::MessageStatus::kInvalidMessage;
return MessageStatus::kInvalidMessage;
}
return DataSourceEventHandler::MessageStatus::kUnhandledVerb;
return MessageStatus::kUnhandledVerb;
}
} // namespace launchdarkly::client_side::data_sources
4 changes: 2 additions & 2 deletions libs/client-sdk/tests/data_source_event_handler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ TEST(StreamingDataHandlerTests, HandlesDeleteMessage) {

EXPECT_EQ(DataSourceEventHandler::MessageStatus::kMessageHandled, res);
EXPECT_EQ(1, test_handler.count_);
auto expected_put =
std::pair<std::string, ItemDescriptor>{"flagA", ItemDescriptor(1)};
auto expected_put = std::pair<std::string, ItemDescriptor>{
"flagA", ItemDescriptor(data_model::Tombstone(1))};
EXPECT_EQ(expected_put, test_handler.upsert_data_[0]);
}

Expand Down
3 changes: 2 additions & 1 deletion libs/client-sdk/tests/flag_store_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using launchdarkly::EvaluationResult;
using launchdarkly::Value;
using launchdarkly::client_side::ItemDescriptor;
using launchdarkly::client_side::flag_manager::FlagStore;
using Tombstone = launchdarkly::data_model::Tombstone;

TEST(FlagstoreTests, HandlesEmptyInit) {
FlagStore store;
Expand Down Expand Up @@ -108,7 +109,7 @@ TEST(FlagstoreTests, HandleDelete) {
EvaluationDetailInternal{Value("test"), std::nullopt,
std::nullopt}}}}}});

store.Upsert("flagA", ItemDescriptor{2});
store.Upsert("flagA", ItemDescriptor{Tombstone{2}});

EXPECT_FALSE(store.GetAll().empty());
EXPECT_FALSE(store.Get("flagA")->item.has_value());
Expand Down
Loading

0 comments on commit de58fa4

Please sign in to comment.