WIP making Operation and Precondition smaller
This commit is contained in:
@@ -12,7 +12,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.request_id().has_value());
|
||||
REQUIRE(request.request_id().value() == "test123");
|
||||
REQUIRE(request.leader_id() == "leader456");
|
||||
@@ -32,12 +32,12 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.preconditions().size() == 1);
|
||||
REQUIRE(request.preconditions()[0].type == Precondition::Type::PointRead);
|
||||
REQUIRE(request.preconditions()[0].version.has_value());
|
||||
REQUIRE(request.preconditions()[0].version.value() == 12340);
|
||||
REQUIRE(request.preconditions()[0].key == "test"); // "dGVzdA==" decoded
|
||||
REQUIRE(request.preconditions()[0].version == 12340);
|
||||
REQUIRE(request.preconditions()[0].begin == "test"); // "dGVzdA==" decoded
|
||||
REQUIRE(request.preconditions()[0].end == "");
|
||||
}
|
||||
|
||||
SUBCASE("With operations") {
|
||||
@@ -57,16 +57,16 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.operations().size() == 2);
|
||||
|
||||
REQUIRE(request.operations()[0].type == Operation::Type::Write);
|
||||
REQUIRE(request.operations()[0].key == "test");
|
||||
REQUIRE(request.operations()[0].value.has_value());
|
||||
REQUIRE(request.operations()[0].value.value() == "value");
|
||||
REQUIRE(request.operations()[0].param1 == "test");
|
||||
REQUIRE(request.operations()[0].param2 == "value");
|
||||
|
||||
REQUIRE(request.operations()[1].type == Operation::Type::Delete);
|
||||
REQUIRE(request.operations()[1].key == "test2");
|
||||
REQUIRE(request.operations()[1].param1 == "test2");
|
||||
REQUIRE(request.operations()[1].param2 == "");
|
||||
}
|
||||
|
||||
SUBCASE("Invalid JSON") {
|
||||
@@ -75,7 +75,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"read_version": "not_a_number"
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
}
|
||||
|
||||
SUBCASE("Missing required leader_id") {
|
||||
@@ -84,7 +84,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"leader_id": "leader456"
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"request_id": "test123"
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
REQUIRE_FALSE(request.request_id().has_value());
|
||||
REQUIRE(request.leader_id() == "leader456");
|
||||
@@ -147,7 +147,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(request.parse_json(json));
|
||||
REQUIRE_FALSE(request.parse_json(json.data(), json.size()));
|
||||
REQUIRE_FALSE(request.is_parse_complete());
|
||||
}
|
||||
}
|
||||
@@ -431,7 +431,7 @@ TEST_CASE("CommitRequest memory management") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(request.parse_json(json));
|
||||
REQUIRE(request.parse_json(json.data(), json.size()));
|
||||
|
||||
// Check that arena allocation worked
|
||||
REQUIRE(request.total_allocated() > 0);
|
||||
@@ -537,16 +537,18 @@ TEST_CASE("CommitRequest streaming parsing") {
|
||||
|
||||
// Verify precondition was parsed correctly
|
||||
REQUIRE(request.preconditions()[0].type == Precondition::Type::PointRead);
|
||||
REQUIRE(request.preconditions()[0].version.value() == 98764);
|
||||
REQUIRE(request.preconditions()[0].key == "testKey");
|
||||
REQUIRE(request.preconditions()[0].version == 98764);
|
||||
REQUIRE(request.preconditions()[0].begin == "testKey");
|
||||
REQUIRE(request.preconditions()[0].end == "");
|
||||
|
||||
// Verify operations were parsed correctly
|
||||
REQUIRE(request.operations()[0].type == Operation::Type::Write);
|
||||
REQUIRE(request.operations()[0].key == "testKey");
|
||||
REQUIRE(request.operations()[0].value.value() == "testValue");
|
||||
REQUIRE(request.operations()[0].param1 == "testKey");
|
||||
REQUIRE(request.operations()[0].param2 == "testValue");
|
||||
|
||||
REQUIRE(request.operations()[1].type == Operation::Type::Delete);
|
||||
REQUIRE(request.operations()[1].key == "deleteKey");
|
||||
REQUIRE(request.operations()[1].param1 == "deleteKey");
|
||||
REQUIRE(request.operations()[1].param2 == "");
|
||||
}
|
||||
|
||||
SUBCASE("Streaming parse error handling") {
|
||||
@@ -624,4 +626,4 @@ TEST_CASE("CommitRequest streaming parsing") {
|
||||
REQUIRE(status == CommitRequest::ParseStatus::Complete);
|
||||
REQUIRE_FALSE(request.is_parse_complete()); // Should fail validation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user