More validation of commit request
This commit is contained in:
@@ -77,6 +77,59 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
}
|
||||
|
||||
SUBCASE("Missing required leader_id") {
|
||||
std::string json = R"({
|
||||
"request_id": "test123",
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
SUBCASE("Missing required read_version") {
|
||||
std::string json = R"({
|
||||
"request_id": "test123",
|
||||
"leader_id": "leader456"
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
SUBCASE("Empty leader_id") {
|
||||
std::string json = R"({
|
||||
"request_id": "test123",
|
||||
"leader_id": "",
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
SUBCASE("Missing both leader_id and read_version") {
|
||||
std::string json = R"({
|
||||
"request_id": "test123"
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
SUBCASE("request_id is optional") {
|
||||
std::string json = R"({
|
||||
"leader_id": "leader456",
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
REQUIRE_FALSE(request.request_id().has_value());
|
||||
REQUIRE(request.leader_id() == "leader456");
|
||||
REQUIRE(request.read_version() == 12345);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("CommitRequest memory management") {
|
||||
@@ -254,4 +307,38 @@ TEST_CASE("CommitRequest streaming parsing") {
|
||||
REQUIRE(request.leader_id() == "test");
|
||||
REQUIRE(request.read_version() == 123);
|
||||
}
|
||||
|
||||
SUBCASE("Streaming parse missing required leader_id") {
|
||||
std::string json = R"({"request_id": "test", "read_version": 123})";
|
||||
|
||||
REQUIRE(request.begin_streaming_parse());
|
||||
|
||||
std::string mutable_json = json;
|
||||
CommitRequest::ParseStatus status =
|
||||
request.parse_chunk(mutable_json.data(), mutable_json.size());
|
||||
|
||||
if (status == CommitRequest::ParseStatus::Incomplete) {
|
||||
status = request.finish_streaming_parse();
|
||||
}
|
||||
|
||||
REQUIRE(status == CommitRequest::ParseStatus::Complete);
|
||||
REQUIRE_FALSE(request.is_parse_complete()); // Should fail validation
|
||||
}
|
||||
|
||||
SUBCASE("Streaming parse missing required read_version") {
|
||||
std::string json = R"({"request_id": "test", "leader_id": "leader123"})";
|
||||
|
||||
REQUIRE(request.begin_streaming_parse());
|
||||
|
||||
std::string mutable_json = json;
|
||||
CommitRequest::ParseStatus status =
|
||||
request.parse_chunk(mutable_json.data(), mutable_json.size());
|
||||
|
||||
if (status == CommitRequest::ParseStatus::Incomplete) {
|
||||
status = request.finish_streaming_parse();
|
||||
}
|
||||
|
||||
REQUIRE(status == CommitRequest::ParseStatus::Complete);
|
||||
REQUIRE_FALSE(request.is_parse_complete()); // Should fail validation
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user