aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuyuki Ishi <ishitatsuyuki@google.com>2024-04-12 02:32:20 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-04-12 14:55:42 +0000
commit92a0ed1a7ab0db182820c2c20f57a64b9bd1fb7f (patch)
treef5c4af8c4ac0345224f7b1448f79c10af8a2ae60
parent6523933c1ac1f97652a6872ca0ed5b8c9ed74c3f (diff)
downloadtoolchain-utils-92a0ed1a7ab0db182820c2c20f57a64b9bd1fb7f.tar.gz
rust-analyzer-chromiumos-wrapper: Generate Content-Length for tests in the helper
Manually specifying the Content-Length makes it more tedious to modify the tests, so let the helper generate it instead. This simplifies the test payloads. BUG=b:333979840 TEST=cargo test Change-Id: I3e485dcaa74c6ca17f31cf8f6bad15911b592173 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/5446197 Reviewed-by: George Burgess <gbiv@chromium.org> Reviewed-by: Allen Webb <allenwebb@google.com> Auto-Submit: Tatsuyuki Ishi <ishitatsuyuki@google.com> Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com> Commit-Queue: George Burgess <gbiv@chromium.org> Reviewed-by: Bastian Kersting <bkersting@google.com>
-rw-r--r--rust-analyzer-chromiumos-wrapper/src/main.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/rust-analyzer-chromiumos-wrapper/src/main.rs b/rust-analyzer-chromiumos-wrapper/src/main.rs
index 43ca5a3d..f9f055e7 100644
--- a/rust-analyzer-chromiumos-wrapper/src/main.rs
+++ b/rust-analyzer-chromiumos-wrapper/src/main.rs
@@ -360,7 +360,8 @@ mod test {
m.insert(pattern, replacement);
m
};
- stream_with_replacement(&mut read.as_bytes(), &mut w, &replacement_map)?;
+ let input = format!("Content-Length: {}\r\n\r\n{}", read.as_bytes().len(), read);
+ stream_with_replacement(&mut input.as_bytes(), &mut w, &replacement_map)?;
// serde_json may not format the json output the same as we do, so we can't just compare
// as strings or slices.
@@ -387,7 +388,7 @@ mod test {
fn test_stream_with_replacement_1() -> Result<()> {
test_stream_with_replacement(
// read
- "Content-Length: 93\r\n\r\n{\"somekey\": {\"somepath\": \"XYZXYZabc\",\
+ "{\"somekey\": {\"somepath\": \"XYZXYZabc\",\
\"anotherpath\": \"somestring\"}, \"anotherkey\": \"XYZXYZdef\"}",
// pattern
"XYZXYZ",
@@ -403,7 +404,7 @@ mod test {
fn test_stream_with_replacement_2() -> Result<()> {
test_stream_with_replacement(
// read
- "Content-Length: 83\r\n\r\n{\"key0\": \"sometextABCDEF\",\
+ "{\"key0\": \"sometextABCDEF\",\
\"key1\": {\"key2\": 5, \"key3\": \"moreABCDEFtext\"}, \"key4\": 1}",
// pattern
"ABCDEF",
@@ -419,7 +420,7 @@ mod test {
fn test_stream_with_replacement_3() -> Result<()> {
test_stream_with_replacement(
// read
- "Content-Length: 55\r\n\r\n{\"path\": \"/my_folder/rust-analyzer-chromiumos-wrapper\"}",
+ "{\"path\": \"/my_folder/rust-analyzer-chromiumos-wrapper\"}",
// pattern
"",
// replacement