From 92a0ed1a7ab0db182820c2c20f57a64b9bd1fb7f Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Fri, 12 Apr 2024 02:32:20 +0000 Subject: 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 Reviewed-by: Allen Webb Auto-Submit: Tatsuyuki Ishi Tested-by: Tatsuyuki Ishi Commit-Queue: George Burgess Reviewed-by: Bastian Kersting --- rust-analyzer-chromiumos-wrapper/src/main.rs | 9 +++++---- 1 file 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 -- cgit v1.2.3