From 7628f0a0fb2ea684c521ad2fc9f840460266d840 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 26 Mar 2026 20:20:49 +0000 Subject: [PATCH 1/2] Ensure rusftfmt executed on all *.rs Signed-off-by: Takeshi Yoneda --- .../bootstrap/wasm/test_data/logging_rust.rs | 54 +-- .../common/wasm/test_data/test_rust.rs | 19 +- test/extensions/dynamic_modules/BUILD | 12 - .../test_data/rust/test_data.bzl | 10 +- .../http/wasm/test_data/async_call_rust.rs | 134 +++--- .../filters/http/wasm/test_data/body_rust.rs | 426 +++++++++--------- .../http/wasm/test_data/close_stream_rust.rs | 16 +- .../http/wasm/test_data/grpc_call_rust.rs | 120 ++--- .../http/wasm/test_data/grpc_stream_rust.rs | 122 ++--- .../http/wasm/test_data/headers_rust.rs | 116 ++--- .../http/wasm/test_data/metadata_rust.rs | 122 ++--- .../filters/http/wasm/test_data/panic_rust.rs | 36 +- .../http/wasm/test_data/resume_call_rust.rs | 41 +- .../http/wasm/test_data/shared_data_rust.rs | 63 +-- .../http/wasm/test_data/shared_queue_rust.rs | 109 ++--- .../wasm/test_data/close_stream_rust.rs | 16 +- .../network/wasm/test_data/logging_rust.rs | 84 ++-- .../network/wasm/test_data/panic_rust.rs | 18 +- .../wasm/test_data/resume_call_rust.rs | 68 +-- tools/code_format/check_format.py | 23 + 20 files changed, 811 insertions(+), 798 deletions(-) diff --git a/test/extensions/bootstrap/wasm/test_data/logging_rust.rs b/test/extensions/bootstrap/wasm/test_data/logging_rust.rs index 31c85a78293f9..3c89f51f7a189 100644 --- a/test/extensions/bootstrap/wasm/test_data/logging_rust.rs +++ b/test/extensions/bootstrap/wasm/test_data/logging_rust.rs @@ -10,41 +10,41 @@ proxy_wasm::main! {{ struct TestRoot; impl RootContext for TestRoot { - fn on_vm_start(&mut self, _: usize) -> bool { - true - } + fn on_vm_start(&mut self, _: usize) -> bool { + true + } - fn on_configure(&mut self, _: usize) -> bool { - trace!("ON_CONFIGURE: {}", std::env::var("ON_CONFIGURE").unwrap()); - trace!("test trace logging"); - debug!("test debug logging"); - error!("test error logging"); - if let Some(value) = self.get_plugin_configuration() { - warn!("warn {}", String::from_utf8(value).unwrap()); - } - true + fn on_configure(&mut self, _: usize) -> bool { + trace!("ON_CONFIGURE: {}", std::env::var("ON_CONFIGURE").unwrap()); + trace!("test trace logging"); + debug!("test debug logging"); + error!("test error logging"); + if let Some(value) = self.get_plugin_configuration() { + warn!("warn {}", String::from_utf8(value).unwrap()); } + true + } - fn on_tick(&mut self) { - trace!("ON_TICK: {}", std::env::var("ON_TICK").unwrap()); - if let Some(value) = self.get_property(vec!["plugin_root_id"]) { - info!("test tick logging{}", String::from_utf8(value).unwrap()); - } else { - info!("test tick logging"); - } - self.done(); + fn on_tick(&mut self) { + trace!("ON_TICK: {}", std::env::var("ON_TICK").unwrap()); + if let Some(value) = self.get_property(vec!["plugin_root_id"]) { + info!("test tick logging{}", String::from_utf8(value).unwrap()); + } else { + info!("test tick logging"); } + self.done(); + } } impl Context for TestRoot { - fn on_done(&mut self) -> bool { - info!("onDone logging"); - false - } + fn on_done(&mut self) -> bool { + info!("onDone logging"); + false + } } impl Drop for TestRoot { - fn drop(&mut self) { - info!("onDelete logging"); - } + fn drop(&mut self) { + info!("onDelete logging"); + } } diff --git a/test/extensions/common/wasm/test_data/test_rust.rs b/test/extensions/common/wasm/test_data/test_rust.rs index 7509a6913d31f..c4f0d8f193e97 100644 --- a/test/extensions/common/wasm/test_data/test_rust.rs +++ b/test/extensions/common/wasm/test_data/test_rust.rs @@ -2,36 +2,37 @@ // See: https://github.com/envoyproxy/envoy/issues/9733 // // Build using: -// $ rustc -C lto -C opt-level=3 -C panic=abort -C link-arg=-S -C link-arg=-zstack-size=32768 --crate-type cdylib --target wasm32-unknown-unknown test_rust.rs -// $ ../../../../../bazel-bin/test/tools/wee8_compile/wee8_compile_tool test_rust.wasm test_rust.wasm +// $ rustc -C lto -C opt-level=3 -C panic=abort -C link-arg=-S -C link-arg=-zstack-size=32768 +// --crate-type cdylib --target wasm32-unknown-unknown test_rust.rs $ ../../../../../bazel-bin/test/ +// tools/wee8_compile/wee8_compile_tool test_rust.wasm test_rust.wasm // Import functions exported from the host environment. extern "C" { - fn pong(value: u32); - fn random() -> u32; + fn pong(value: u32); + fn random() -> u32; } #[no_mangle] extern "C" fn ping(value: u32) { - unsafe { pong(value) } + unsafe { pong(value) } } #[no_mangle] extern "C" fn lucky(number: u32) -> bool { - unsafe { number == random() } + unsafe { number == random() } } #[no_mangle] extern "C" fn sum(a: u32, b: u32, c: u32) -> u32 { - a + b + c + a + b + c } #[no_mangle] extern "C" fn div(a: u32, b: u32) -> u32 { - a / b + a / b } #[no_mangle] extern "C" fn abort() { - panic!("abort") + panic!("abort") } diff --git a/test/extensions/dynamic_modules/BUILD b/test/extensions/dynamic_modules/BUILD index 8466b45cc7c97..dd67d9854dadf 100644 --- a/test/extensions/dynamic_modules/BUILD +++ b/test/extensions/dynamic_modules/BUILD @@ -3,7 +3,6 @@ load( "rust_clippy", "rust_doc_test", "rust_test", - "rustfmt_test", ) load( "//bazel:envoy_build_system.bzl", @@ -90,17 +89,6 @@ rust_doc_test( ], ) -# As per the discussion in https://github.com/envoyproxy/envoy/pull/35627, -# we set the rust_fmt and clippy target here instead of the part of //tools/code_format target for now. -rustfmt_test( - name = "rust_sdk_fmt", - tags = ["nocoverage"], - targets = [ - "//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk", - "//source/extensions/dynamic_modules/sdk/rust:build_script_", - ], -) - rust_clippy( name = "rust_sdk_clippy", tags = ["nocoverage"], diff --git a/test/extensions/dynamic_modules/test_data/rust/test_data.bzl b/test/extensions/dynamic_modules/test_data/rust/test_data.bzl index 5b4e84cb8d0c8..f58dd8a3df8ac 100644 --- a/test/extensions/dynamic_modules/test_data/rust/test_data.bzl +++ b/test/extensions/dynamic_modules/test_data/rust/test_data.bzl @@ -1,5 +1,5 @@ load("@bazel_skylib//rules:copy_file.bzl", "copy_file") -load("@rules_rust//rust:defs.bzl", "rust_clippy", "rust_shared_library", "rust_static_library", "rust_test", "rustfmt_test") +load("@rules_rust//rust:defs.bzl", "rust_clippy", "rust_shared_library", "rust_static_library", "rust_test") load("//source/extensions/dynamic_modules:dynamic_modules.bzl", "envoy_dynamic_module_prefix_symbols") def test_program(name): @@ -39,14 +39,6 @@ def test_program(name): archive = ":" + _static_lib_name, ) - # As per the discussion in https://github.com/envoyproxy/envoy/pull/35627, - # we set the rust_fmt and clippy target here instead of the part of //tools/code_format target for now. - rustfmt_test( - name = "fmt_" + name, - tags = ["nocoverage"], - targets = [":" + _name], - testonly = True, - ) rust_clippy( name = "clippy_" + name, tags = ["nocoverage"], diff --git a/test/extensions/filters/http/wasm/test_data/async_call_rust.rs b/test/extensions/filters/http/wasm/test_data/async_call_rust.rs index 7ce78f64931ee..59f267d289096 100644 --- a/test/extensions/filters/http/wasm/test_data/async_call_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/async_call_rust.rs @@ -11,77 +11,81 @@ proxy_wasm::main! {{ struct TestStream; impl HttpContext for TestStream { - fn on_http_request_headers(&mut self, _: usize, end_of_stream: bool) -> Action { - if end_of_stream { - self.dispatch_http_call( - "cluster", - vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], - Some(b"hello world"), - vec![("trail", "cow")], - Duration::from_secs(1), - ) - .unwrap_err(); - Action::Continue - } else { - // bogus cluster name - self.dispatch_http_call( - "bogus cluster", - vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], - Some(b"hello world"), - vec![("trail", "cow")], - Duration::from_secs(1), - ) - .unwrap_err(); + fn on_http_request_headers(&mut self, _: usize, end_of_stream: bool) -> Action { + if end_of_stream { + self + .dispatch_http_call( + "cluster", + vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], + Some(b"hello world"), + vec![("trail", "cow")], + Duration::from_secs(1), + ) + .unwrap_err(); + Action::Continue + } else { + // bogus cluster name + self + .dispatch_http_call( + "bogus cluster", + vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], + Some(b"hello world"), + vec![("trail", "cow")], + Duration::from_secs(1), + ) + .unwrap_err(); - // bogus duration - self.dispatch_http_call( - "cluster", - vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], - Some(b"hello world"), - vec![("trail", "cow")], - Duration::new(u64::MAX, 0), - ) - .unwrap_err(); + // bogus duration + self + .dispatch_http_call( + "cluster", + vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], + Some(b"hello world"), + vec![("trail", "cow")], + Duration::new(u64::MAX, 0), + ) + .unwrap_err(); - // missing :path - self.dispatch_http_call( - "cluster", - vec![(":method", "POST"), (":authority", "foo")], - Some(b"hello world"), - vec![("trail", "cow")], - Duration::from_secs(1), - ) - .unwrap_err(); + // missing :path + self + .dispatch_http_call( + "cluster", + vec![(":method", "POST"), (":authority", "foo")], + Some(b"hello world"), + vec![("trail", "cow")], + Duration::from_secs(1), + ) + .unwrap_err(); - match self.dispatch_http_call( - "cluster", - vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], - Some(b"hello world"), - vec![("trail", "cow")], - Duration::from_secs(5), - ) { - Ok(_) => info!("onRequestHeaders"), - Err(_) => info!("async_call rejected"), - }; - Action::Pause - } + match self.dispatch_http_call( + "cluster", + vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], + Some(b"hello world"), + vec![("trail", "cow")], + Duration::from_secs(5), + ) { + Ok(_) => info!("onRequestHeaders"), + Err(_) => info!("async_call rejected"), + }; + Action::Pause } + } } impl Context for TestStream { - fn on_http_call_response(&mut self, _: u32, _: usize, body_size: usize, _: usize) { - if body_size == 0 { - info!("async_call failed"); - return; - } - for (name, value) in &self.get_http_call_response_headers() { - info!("{} -> {}", name, value); - } - if let Some(body) = self.get_http_call_response_body(0, body_size) { - debug!("{}", String::from_utf8(body).unwrap()); - } - for (name, value) in &self.get_http_call_response_trailers() { - warn!("{} -> {}", name, value); - } + fn on_http_call_response(&mut self, _: u32, _: usize, body_size: usize, _: usize) { + if body_size == 0 { + info!("async_call failed"); + return; } + for (name, value) in &self.get_http_call_response_headers() { + info!("{} -> {}", name, value); + } + if let Some(body) = self.get_http_call_response_body(0, body_size) { + debug!("{}", String::from_utf8(body).unwrap()); + } + for (name, value) in &self.get_http_call_response_trailers() { + warn!("{} -> {}", name, value); + } + } } diff --git a/test/extensions/filters/http/wasm/test_data/body_rust.rs b/test/extensions/filters/http/wasm/test_data/body_rust.rs index d141179ec29c8..f7fbc8c7cdc51 100644 --- a/test/extensions/filters/http/wasm/test_data/body_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/body_rust.rs @@ -13,232 +13,232 @@ proxy_wasm::main! {{ }} struct TestStream { - test: Option, - body_chunks: usize, + test: Option, + body_chunks: usize, } impl TestStream { - fn log_body(&mut self, body: Option) { - error!( - "onBody {}", - body.map_or(String::from(""), |b| String::from_utf8(b).unwrap()) - ); - } + fn log_body(&mut self, body: Option) { + error!( + "onBody {}", + body.map_or(String::from(""), |b| String::from_utf8(b).unwrap()) + ); + } } impl HttpContext for TestStream { - fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - self.test = self.get_http_request_header("x-test-operation"); - self.body_chunks = 0; - Action::Continue - } + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + self.test = self.get_http_request_header("x-test-operation"); + self.body_chunks = 0; + Action::Continue + } - fn on_http_request_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { - match self.test.as_deref() { - Some("ReadBody") => { - self.log_body(self.get_http_request_body(0, 0xffffffff)); - Action::Continue - } - Some("PrependAndAppendToBody") => { - self.set_http_request_body(0, 0, b"prepend."); - self.set_http_request_body(0xffffffff, 0, b".append"); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - Action::Continue - } - Some("ReplaceBody") => { - self.set_http_request_body(0, 0xffffffff, b"replace"); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - Action::Continue - } - Some("PartialReplaceBody") => { - self.set_http_request_body(0, 1, b"partial.replace."); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - Action::Continue - } - Some("RemoveBody") => { - self.set_http_request_body(0, 0xffffffff, b""); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - Action::Continue - } - Some("PartialRemoveBody") => { - self.set_http_request_body(0, 1, b""); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - Action::Continue - } - Some("BufferBody") => { - self.log_body(self.get_http_request_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("PrependAndAppendToBufferedBody") => { - self.set_http_request_body(0, 0, b"prepend."); - self.set_http_request_body(0xffffffff, 0, b".append"); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("ReplaceBufferedBody") => { - self.set_http_request_body(0, 0xffffffff, b"replace"); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("PartialReplaceBufferedBody") => { - self.set_http_request_body(0, 1, b"partial.replace."); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("RemoveBufferedBody") => { - self.set_http_request_body(0, 0xffffffff, b""); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("PartialRemoveBufferedBody") => { - self.set_http_request_body(0, 1, b""); - self.log_body(self.get_http_request_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("BufferTwoBodies") => { - if let Some(body) = self.get_http_request_body(0, body_size) { - error!("onBody {}", String::from_utf8(body).unwrap()); - } - self.body_chunks += 1; - if end_of_stream || self.body_chunks > 2 { - Action::Continue - } else { - Action::Pause - } - } - _ => Action::Continue, + fn on_http_request_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { + match self.test.as_deref() { + Some("ReadBody") => { + self.log_body(self.get_http_request_body(0, 0xffffffff)); + Action::Continue + }, + Some("PrependAndAppendToBody") => { + self.set_http_request_body(0, 0, b"prepend."); + self.set_http_request_body(0xffffffff, 0, b".append"); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + Action::Continue + }, + Some("ReplaceBody") => { + self.set_http_request_body(0, 0xffffffff, b"replace"); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + Action::Continue + }, + Some("PartialReplaceBody") => { + self.set_http_request_body(0, 1, b"partial.replace."); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + Action::Continue + }, + Some("RemoveBody") => { + self.set_http_request_body(0, 0xffffffff, b""); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + Action::Continue + }, + Some("PartialRemoveBody") => { + self.set_http_request_body(0, 1, b""); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + Action::Continue + }, + Some("BufferBody") => { + self.log_body(self.get_http_request_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("PrependAndAppendToBufferedBody") => { + self.set_http_request_body(0, 0, b"prepend."); + self.set_http_request_body(0xffffffff, 0, b".append"); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("ReplaceBufferedBody") => { + self.set_http_request_body(0, 0xffffffff, b"replace"); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("PartialReplaceBufferedBody") => { + self.set_http_request_body(0, 1, b"partial.replace."); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("RemoveBufferedBody") => { + self.set_http_request_body(0, 0xffffffff, b""); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("PartialRemoveBufferedBody") => { + self.set_http_request_body(0, 1, b""); + self.log_body(self.get_http_request_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("BufferTwoBodies") => { + if let Some(body) = self.get_http_request_body(0, body_size) { + error!("onBody {}", String::from_utf8(body).unwrap()); + } + self.body_chunks += 1; + if end_of_stream || self.body_chunks > 2 { + Action::Continue + } else { + Action::Pause } + }, + _ => Action::Continue, } + } - fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { - self.test = self.get_http_response_header("x-test-operation"); - Action::Continue - } + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { + self.test = self.get_http_response_header("x-test-operation"); + Action::Continue + } - fn on_http_response_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { - match self.test.as_deref() { - Some("ReadBody") => { - self.log_body(self.get_http_response_body(0, 0xffffffff)); - Action::Continue - } - Some("PrependAndAppendToBody") => { - self.set_http_response_body(0, 0, b"prepend."); - self.set_http_response_body(0xffffffff, 0, b".append"); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - Action::Continue - } - Some("ReplaceBody") => { - self.set_http_response_body(0, 0xffffffff, b"replace"); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - Action::Continue - } - Some("PartialReplaceBody") => { - self.set_http_response_body(0, 1, b"partial.replace."); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - Action::Continue - } - Some("RemoveBody") => { - self.set_http_response_body(0, 0xffffffff, b""); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - Action::Continue - } - Some("PartialRemoveBody") => { - self.set_http_response_body(0, 1, b""); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - Action::Continue - } - Some("BufferBody") => { - self.log_body(self.get_http_response_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("PrependAndAppendToBufferedBody") => { - self.set_http_response_body(0, 0, b"prepend."); - self.set_http_response_body(0xffffffff, 0, b".append"); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("ReplaceBufferedBody") => { - self.set_http_response_body(0, 0xffffffff, b"replace"); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("PartialReplaceBufferedBody") => { - self.set_http_response_body(0, 1, b"partial.replace."); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("RemoveBufferedBody") => { - self.set_http_response_body(0, 0xffffffff, b""); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("PartialRemoveBufferedBody") => { - self.set_http_response_body(0, 1, b""); - self.log_body(self.get_http_response_body(0, 0xffffffff)); - if end_of_stream { - Action::Continue - } else { - Action::Pause - } - } - Some("BufferTwoBodies") => { - if let Some(body) = self.get_http_response_body(0, body_size) { - error!("onBody {}", String::from_utf8(body).unwrap()); - } - self.body_chunks += 1; - if end_of_stream || self.body_chunks > 2 { - Action::Continue - } else { - Action::Pause - } - } - _ => Action::Continue, + fn on_http_response_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { + match self.test.as_deref() { + Some("ReadBody") => { + self.log_body(self.get_http_response_body(0, 0xffffffff)); + Action::Continue + }, + Some("PrependAndAppendToBody") => { + self.set_http_response_body(0, 0, b"prepend."); + self.set_http_response_body(0xffffffff, 0, b".append"); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + Action::Continue + }, + Some("ReplaceBody") => { + self.set_http_response_body(0, 0xffffffff, b"replace"); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + Action::Continue + }, + Some("PartialReplaceBody") => { + self.set_http_response_body(0, 1, b"partial.replace."); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + Action::Continue + }, + Some("RemoveBody") => { + self.set_http_response_body(0, 0xffffffff, b""); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + Action::Continue + }, + Some("PartialRemoveBody") => { + self.set_http_response_body(0, 1, b""); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + Action::Continue + }, + Some("BufferBody") => { + self.log_body(self.get_http_response_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("PrependAndAppendToBufferedBody") => { + self.set_http_response_body(0, 0, b"prepend."); + self.set_http_response_body(0xffffffff, 0, b".append"); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("ReplaceBufferedBody") => { + self.set_http_response_body(0, 0xffffffff, b"replace"); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("PartialReplaceBufferedBody") => { + self.set_http_response_body(0, 1, b"partial.replace."); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("RemoveBufferedBody") => { + self.set_http_response_body(0, 0xffffffff, b""); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("PartialRemoveBufferedBody") => { + self.set_http_response_body(0, 1, b""); + self.log_body(self.get_http_response_body(0, 0xffffffff)); + if end_of_stream { + Action::Continue + } else { + Action::Pause + } + }, + Some("BufferTwoBodies") => { + if let Some(body) = self.get_http_response_body(0, body_size) { + error!("onBody {}", String::from_utf8(body).unwrap()); + } + self.body_chunks += 1; + if end_of_stream || self.body_chunks > 2 { + Action::Continue + } else { + Action::Pause } + }, + _ => Action::Continue, } + } } impl Context for TestStream {} diff --git a/test/extensions/filters/http/wasm/test_data/close_stream_rust.rs b/test/extensions/filters/http/wasm/test_data/close_stream_rust.rs index 2798d12be001c..707d89267774a 100644 --- a/test/extensions/filters/http/wasm/test_data/close_stream_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/close_stream_rust.rs @@ -10,13 +10,13 @@ struct TestStream; impl Context for TestStream {} impl HttpContext for TestStream { - fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - self.reset_http_request(); - Action::Continue - } + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + self.reset_http_request(); + Action::Continue + } - fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { - self.reset_http_response(); - Action::Continue - } + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { + self.reset_http_response(); + Action::Continue + } } diff --git a/test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs b/test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs index b0cd51fa318a1..c5bd97ee3a59b 100644 --- a/test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs @@ -20,13 +20,13 @@ proxy_wasm::main! {{ struct TestGrpcCallRoot; impl RootContext for TestGrpcCallRoot { - fn on_queue_ready(&mut self, _: u32) { - CALLOUT_ID.with(|saved_id| { - if let Some(callout_id) = saved_id.get() { - self.cancel_grpc_call(callout_id); - } - }); - } + fn on_queue_ready(&mut self, _: u32) { + CALLOUT_ID.with(|saved_id| { + if let Some(callout_id) = saved_id.get() { + self.cancel_grpc_call(callout_id); + } + }); + } } impl Context for TestGrpcCallRoot {} @@ -34,64 +34,64 @@ impl Context for TestGrpcCallRoot {} struct TestGrpcCall; impl HttpContext for TestGrpcCall { - fn on_http_request_headers(&mut self, _: usize, end_of_stream: bool) -> Action { - let mut value = Value::new(); - value.set_string_value(String::from("request")); - let message = value.write_to_bytes().unwrap(); + fn on_http_request_headers(&mut self, _: usize, end_of_stream: bool) -> Action { + let mut value = Value::new(); + value.set_string_value(String::from("request")); + let message = value.write_to_bytes().unwrap(); - match self.dispatch_grpc_call( - "bogus grpc_service", - "service", - "method", - vec![("source", b"grpc_call")], - Some(&message), - Duration::from_secs(1), - ) { - Ok(_) => error!("bogus grpc_service succeeded"), - Err(_) => error!("bogus grpc_service rejected"), - }; + match self.dispatch_grpc_call( + "bogus grpc_service", + "service", + "method", + vec![("source", b"grpc_call")], + Some(&message), + Duration::from_secs(1), + ) { + Ok(_) => error!("bogus grpc_service succeeded"), + Err(_) => error!("bogus grpc_service rejected"), + }; - if end_of_stream { - match self.dispatch_grpc_call( - "cluster", - "service", - "method", - vec![("source", b"grpc_call")], - Some(&message), - Duration::from_secs(1), - ) { - Err(Status::InternalFailure) => error!("expected failure occurred"), - _ => error!("unexpected cluster call result"), - }; - Action::Continue - } else { - match self.dispatch_grpc_call( - "cluster", - "service", - "method", - vec![("source", b"grpc_call")], - Some(&message), - Duration::from_secs(1), - ) { - Ok(callout_id) => { - CALLOUT_ID.with(|saved_id| saved_id.set(Some(callout_id))); - error!("cluster call succeeded") - } - Err(_) => error!("cluster call rejected"), - }; - Action::Pause - } + if end_of_stream { + match self.dispatch_grpc_call( + "cluster", + "service", + "method", + vec![("source", b"grpc_call")], + Some(&message), + Duration::from_secs(1), + ) { + Err(Status::InternalFailure) => error!("expected failure occurred"), + _ => error!("unexpected cluster call result"), + }; + Action::Continue + } else { + match self.dispatch_grpc_call( + "cluster", + "service", + "method", + vec![("source", b"grpc_call")], + Some(&message), + Duration::from_secs(1), + ) { + Ok(callout_id) => { + CALLOUT_ID.with(|saved_id| saved_id.set(Some(callout_id))); + error!("cluster call succeeded") + }, + Err(_) => error!("cluster call rejected"), + }; + Action::Pause } + } } impl Context for TestGrpcCall { - fn on_grpc_call_response(&mut self, _: u32, status_code: u32, response_size: usize) { - if status_code != 0 { - let (_, message) = self.get_grpc_status(); - debug!("failure {}", &message.as_deref().unwrap_or("")); - } else if let Some(response_bytes) = self.get_grpc_call_response_body(0, response_size) { - let value = Value::parse_from_bytes(&response_bytes).unwrap(); - debug!("{}", value.get_string_value()); - } + fn on_grpc_call_response(&mut self, _: u32, status_code: u32, response_size: usize) { + if status_code != 0 { + let (_, message) = self.get_grpc_status(); + debug!("failure {}", &message.as_deref().unwrap_or("")); + } else if let Some(response_bytes) = self.get_grpc_call_response_body(0, response_size) { + let value = Value::parse_from_bytes(&response_bytes).unwrap(); + debug!("{}", value.get_string_value()); } + } } diff --git a/test/extensions/filters/http/wasm/test_data/grpc_stream_rust.rs b/test/extensions/filters/http/wasm/test_data/grpc_stream_rust.rs index 059f80bd3618b..5414f8c5dffe1 100644 --- a/test/extensions/filters/http/wasm/test_data/grpc_stream_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/grpc_stream_rust.rs @@ -12,76 +12,76 @@ proxy_wasm::main! {{ struct TestGrpcStream; impl HttpContext for TestGrpcStream { - fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - match self.open_grpc_stream( - "bogus service string", - "service", - "method", - vec![("source", b"grpc_stream")], - ) { - Err(Status::ParseFailure) => error!("expected bogus service parse failure"), - Ok(_) => error!("unexpected bogus service string OK"), - Err(_) => error!("unexpected bogus service string error"), - }; + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + match self.open_grpc_stream( + "bogus service string", + "service", + "method", + vec![("source", b"grpc_stream")], + ) { + Err(Status::ParseFailure) => error!("expected bogus service parse failure"), + Ok(_) => error!("unexpected bogus service string OK"), + Err(_) => error!("unexpected bogus service string error"), + }; - match self.open_grpc_stream( - "cluster", - "service", - "bad method", - vec![("source", b"grpc_stream")], - ) { - Err(Status::InternalFailure) => error!("expected bogus method call failure"), - Ok(_) => error!("unexpected bogus method call OK"), - Err(_) => error!("unexpected bogus method call error"), - }; + match self.open_grpc_stream( + "cluster", + "service", + "bad method", + vec![("source", b"grpc_stream")], + ) { + Err(Status::InternalFailure) => error!("expected bogus method call failure"), + Ok(_) => error!("unexpected bogus method call OK"), + Err(_) => error!("unexpected bogus method call error"), + }; - match self.open_grpc_stream( - "cluster", - "service", - "method", - vec![("source", b"grpc_stream")], - ) { - Ok(_) => error!("cluster call succeeded"), - Err(_) => error!("cluster call rejected"), - }; + match self.open_grpc_stream( + "cluster", + "service", + "method", + vec![("source", b"grpc_stream")], + ) { + Ok(_) => error!("cluster call succeeded"), + Err(_) => error!("cluster call rejected"), + }; - Action::Pause - } + Action::Pause + } } impl Context for TestGrpcStream { - fn on_grpc_stream_initial_metadata(&mut self, callout_id: u32, _: u32) { - if self.get_grpc_stream_initial_metadata_value("test") == Some(b"reset".to_vec()) { - self.cancel_grpc_stream(callout_id); - } + fn on_grpc_stream_initial_metadata(&mut self, callout_id: u32, _: u32) { + if self.get_grpc_stream_initial_metadata_value("test") == Some(b"reset".to_vec()) { + self.cancel_grpc_stream(callout_id); } + } - fn on_grpc_stream_message(&mut self, callout_id: u32, message_size: usize) { - if let Some(message_bytes) = self.get_grpc_call_response_body(0, message_size) { - let response = Value::parse_from_bytes(&message_bytes).unwrap(); - let string = response.get_string_value(); - if string == String::from("close") { - self.close_grpc_stream(callout_id); - } else { - let value = Value::new(); - let message = value.write_to_bytes().unwrap(); - self.send_grpc_stream_message(callout_id, Some(&message), false); - } - debug!("response {}", string); - } + fn on_grpc_stream_message(&mut self, callout_id: u32, message_size: usize) { + if let Some(message_bytes) = self.get_grpc_call_response_body(0, message_size) { + let response = Value::parse_from_bytes(&message_bytes).unwrap(); + let string = response.get_string_value(); + if string == String::from("close") { + self.close_grpc_stream(callout_id); + } else { + let value = Value::new(); + let message = value.write_to_bytes().unwrap(); + self.send_grpc_stream_message(callout_id, Some(&message), false); + } + debug!("response {}", string); } + } - fn on_grpc_stream_trailing_metadata(&mut self, _: u32, _: u32) { - let _ = self.get_grpc_stream_trailing_metadata_value("foo"); - } + fn on_grpc_stream_trailing_metadata(&mut self, _: u32, _: u32) { + let _ = self.get_grpc_stream_trailing_metadata_value("foo"); + } - fn on_grpc_stream_close(&mut self, callout_id: u32, _: u32) { - let (_, message) = self.get_grpc_status(); - debug!("close {}", &message.as_deref().unwrap_or("")); - match message.as_deref() { - Some("close") => self.close_grpc_stream(callout_id), - Some("ok") => (), - _ => self.cancel_grpc_stream(callout_id), - }; - } + fn on_grpc_stream_close(&mut self, callout_id: u32, _: u32) { + let (_, message) = self.get_grpc_status(); + debug!("close {}", &message.as_deref().unwrap_or("")); + match message.as_deref() { + Some("close") => self.close_grpc_stream(callout_id), + Some("ok") => (), + _ => self.cancel_grpc_stream(callout_id), + }; + } } diff --git a/test/extensions/filters/http/wasm/test_data/headers_rust.rs b/test/extensions/filters/http/wasm/test_data/headers_rust.rs index 7727c23603698..0c18274151e86 100644 --- a/test/extensions/filters/http/wasm/test_data/headers_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/headers_rust.rs @@ -10,76 +10,76 @@ proxy_wasm::main! {{ }} struct TestStream { - context_id: u32, + context_id: u32, } impl HttpContext for TestStream { - fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - let mut msg = String::new(); - if let Ok(value) = std::env::var("ENVOY_HTTP_WASM_TEST_HEADERS_HOST_ENV") { - msg.push_str("ENVOY_HTTP_WASM_TEST_HEADERS_HOST_ENV: "); - msg.push_str(&value); - } - if let Ok(value) = std::env::var("ENVOY_HTTP_WASM_TEST_HEADERS_KEY_VALUE_ENV") { - msg.push_str("\nENVOY_HTTP_WASM_TEST_HEADERS_KEY_VALUE_ENV: "); - msg.push_str(&value); - } - if !msg.is_empty() { - trace!("{}", msg); - } - debug!("onRequestHeaders {} headers", self.context_id); - if let Some(path) = self.get_http_request_header(":path") { - info!("header path {}", path); - } - let action = match self.get_http_request_header("server").as_deref() { - Some("envoy-wasm-pause") => Action::Pause, - _ => Action::Continue, - }; - self.set_http_request_header("newheader", Some("newheadervalue")); - self.set_http_request_header("server", Some("envoy-wasm")); - action + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + let mut msg = String::new(); + if let Ok(value) = std::env::var("ENVOY_HTTP_WASM_TEST_HEADERS_HOST_ENV") { + msg.push_str("ENVOY_HTTP_WASM_TEST_HEADERS_HOST_ENV: "); + msg.push_str(&value); } - - fn on_http_request_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { - if let Some(body) = self.get_http_request_body(0, body_size) { - error!("onBody {}", String::from_utf8(body).unwrap()); - } - if end_of_stream { - self.add_http_request_trailer("newtrailer", "request"); - } - Action::Continue + if let Ok(value) = std::env::var("ENVOY_HTTP_WASM_TEST_HEADERS_KEY_VALUE_ENV") { + msg.push_str("\nENVOY_HTTP_WASM_TEST_HEADERS_KEY_VALUE_ENV: "); + msg.push_str(&value); } - - fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { - self.set_http_response_header("test-status", Some("OK")); - Action::Continue + if !msg.is_empty() { + trace!("{}", msg); } - - fn on_http_response_body(&mut self, _: usize, end_of_stream: bool) -> Action { - if end_of_stream { - self.add_http_response_trailer("newtrailer", "response"); - } - Action::Continue + debug!("onRequestHeaders {} headers", self.context_id); + if let Some(path) = self.get_http_request_header(":path") { + info!("header path {}", path); } + let action = match self.get_http_request_header("server").as_deref() { + Some("envoy-wasm-pause") => Action::Pause, + _ => Action::Continue, + }; + self.set_http_request_header("newheader", Some("newheadervalue")); + self.set_http_request_header("server", Some("envoy-wasm")); + action + } - fn on_http_response_trailers(&mut self, _: usize) -> Action { - Action::Pause + fn on_http_request_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { + if let Some(body) = self.get_http_request_body(0, body_size) { + error!("onBody {}", String::from_utf8(body).unwrap()); + } + if end_of_stream { + self.add_http_request_trailer("newtrailer", "request"); } + Action::Continue + } - fn on_log(&mut self) { - let path = self - .get_http_request_header(":path") - .unwrap_or(String::from("")); - let status = self - .get_http_response_header(":status") - .unwrap_or(String::from("")); - warn!("onLog {} {} {}", self.context_id, path, status); + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { + self.set_http_response_header("test-status", Some("OK")); + Action::Continue + } + + fn on_http_response_body(&mut self, _: usize, end_of_stream: bool) -> Action { + if end_of_stream { + self.add_http_response_trailer("newtrailer", "response"); } + Action::Continue + } + + fn on_http_response_trailers(&mut self, _: usize) -> Action { + Action::Pause + } + + fn on_log(&mut self) { + let path = self + .get_http_request_header(":path") + .unwrap_or(String::from("")); + let status = self + .get_http_response_header(":status") + .unwrap_or(String::from("")); + warn!("onLog {} {} {}", self.context_id, path, status); + } } impl Context for TestStream { - fn on_done(&mut self) -> bool { - warn!("onDone {}", self.context_id); - true - } + fn on_done(&mut self) -> bool { + warn!("onDone {}", self.context_id); + true + } } diff --git a/test/extensions/filters/http/wasm/test_data/metadata_rust.rs b/test/extensions/filters/http/wasm/test_data/metadata_rust.rs index 597ded5f4a8ed..cb6383674adda 100644 --- a/test/extensions/filters/http/wasm/test_data/metadata_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/metadata_rust.rs @@ -14,13 +14,13 @@ struct TestRoot; impl Context for TestRoot {} impl RootContext for TestRoot { - fn on_tick(&mut self) { - if let Some(value) = self.get_property(vec!["xds", "node", "metadata", "wasm_node_get_key"]) { - debug!("onTick {}", String::from_utf8(value).unwrap()); - } else { - debug!("missing node metadata"); - } + fn on_tick(&mut self) { + if let Some(value) = self.get_property(vec!["xds", "node", "metadata", "wasm_node_get_key"]) { + debug!("onTick {}", String::from_utf8(value).unwrap()); + } else { + debug!("missing node metadata"); } + } } struct TestStream; @@ -28,65 +28,65 @@ struct TestStream; impl Context for TestStream {} impl HttpContext for TestStream { - fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - if self - .get_property(vec!["xds", "node", "metadata", "wasm_node_get_key"]) - .is_none() - { - debug!("missing node metadata"); - } + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + if self + .get_property(vec!["xds", "node", "metadata", "wasm_node_get_key"]) + .is_none() + { + debug!("missing node metadata"); + } - self.set_property( - vec!["wasm_request_set_key"], - Some(b"wasm_request_set_value"), - ); + self.set_property( + vec!["wasm_request_set_key"], + Some(b"wasm_request_set_value"), + ); - if let Some(path) = self.get_http_request_header(":path") { - info!("header path {}", path); - } - self.set_http_request_header("newheader", Some("newheadervalue")); - self.set_http_request_header("server", Some("envoy-wasm")); + if let Some(path) = self.get_http_request_header(":path") { + info!("header path {}", path); + } + self.set_http_request_header("newheader", Some("newheadervalue")); + self.set_http_request_header("server", Some("envoy-wasm")); - if let Some(value) = self.get_property(vec!["request", "duration"]) { - info!( - "duration is {}", - u64::from_le_bytes(<[u8; 8]>::try_from(&value[0..8]).unwrap()) - ); - } else { - error!("failed to get request duration"); - } - Action::Continue + if let Some(value) = self.get_property(vec!["request", "duration"]) { + info!( + "duration is {}", + u64::from_le_bytes(<[u8; 8]>::try_from(&value[0 .. 8]).unwrap()) + ); + } else { + error!("failed to get request duration"); } + Action::Continue + } - fn on_http_request_body(&mut self, _: usize, _: bool) -> Action { - if let Some(value) = self.get_property(vec!["xds", "node", "metadata", "wasm_node_get_key"]) { - error!("onBody {}", String::from_utf8(value).unwrap()); - } else { - debug!("missing node metadata"); - } - let key1 = self.get_property(vec![ - "metadata", - "filter_metadata", - "envoy.filters.http.wasm", - "wasm_request_get_key", - ]); - if key1.is_none() { - debug!("missing request metadata"); - } - let key2 = self.get_property(vec![ - "metadata", - "filter_metadata", - "envoy.filters.http.wasm", - "wasm_request_get_key", - ]); - if key2.is_none() { - debug!("missing request metadata"); - } - trace!( - "Struct {} {}", - String::from_utf8(key1.unwrap()).unwrap(), - String::from_utf8(key2.unwrap()).unwrap() - ); - Action::Continue + fn on_http_request_body(&mut self, _: usize, _: bool) -> Action { + if let Some(value) = self.get_property(vec!["xds", "node", "metadata", "wasm_node_get_key"]) { + error!("onBody {}", String::from_utf8(value).unwrap()); + } else { + debug!("missing node metadata"); + } + let key1 = self.get_property(vec![ + "metadata", + "filter_metadata", + "envoy.filters.http.wasm", + "wasm_request_get_key", + ]); + if key1.is_none() { + debug!("missing request metadata"); + } + let key2 = self.get_property(vec![ + "metadata", + "filter_metadata", + "envoy.filters.http.wasm", + "wasm_request_get_key", + ]); + if key2.is_none() { + debug!("missing request metadata"); } + trace!( + "Struct {} {}", + String::from_utf8(key1.unwrap()).unwrap(), + String::from_utf8(key2.unwrap()).unwrap() + ); + Action::Continue + } } diff --git a/test/extensions/filters/http/wasm/test_data/panic_rust.rs b/test/extensions/filters/http/wasm/test_data/panic_rust.rs index 4b6b9b8efdf22..3a98facd7596a 100644 --- a/test/extensions/filters/http/wasm/test_data/panic_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/panic_rust.rs @@ -10,27 +10,27 @@ struct TestStream; impl Context for TestStream {} impl HttpContext for TestStream { - fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - panic!(""); - } + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + panic!(""); + } - fn on_http_request_body(&mut self, _: usize, _: bool) -> Action { - panic!(""); - } + fn on_http_request_body(&mut self, _: usize, _: bool) -> Action { + panic!(""); + } - fn on_http_request_trailers(&mut self, _: usize) -> Action { - panic!(""); - } + fn on_http_request_trailers(&mut self, _: usize) -> Action { + panic!(""); + } - fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { - panic!(""); - } + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { + panic!(""); + } - fn on_http_response_body(&mut self, _: usize, _: bool) -> Action { - panic!(""); - } + fn on_http_response_body(&mut self, _: usize, _: bool) -> Action { + panic!(""); + } - fn on_http_response_trailers(&mut self, _: usize) -> Action { - panic!(""); - } + fn on_http_response_trailers(&mut self, _: usize) -> Action { + panic!(""); + } } diff --git a/test/extensions/filters/http/wasm/test_data/resume_call_rust.rs b/test/extensions/filters/http/wasm/test_data/resume_call_rust.rs index e99351993e6cd..9e7fc0ef891f2 100644 --- a/test/extensions/filters/http/wasm/test_data/resume_call_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/resume_call_rust.rs @@ -11,28 +11,29 @@ proxy_wasm::main! {{ struct TestStream; impl HttpContext for TestStream { - fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - self.dispatch_http_call( - "cluster", - vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], - Some(b"resume"), - vec![], - Duration::from_secs(1), - ) - .unwrap(); - info!("onRequestHeaders"); - Action::Pause - } + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + self + .dispatch_http_call( + "cluster", + vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], + Some(b"resume"), + vec![], + Duration::from_secs(1), + ) + .unwrap(); + info!("onRequestHeaders"); + Action::Pause + } - fn on_http_request_body(&mut self, _: usize, _: bool) -> Action { - info!("onRequestBody"); - Action::Continue - } + fn on_http_request_body(&mut self, _: usize, _: bool) -> Action { + info!("onRequestBody"); + Action::Continue + } } impl Context for TestStream { - fn on_http_call_response(&mut self, _: u32, _: usize, _: usize, _: usize) { - info!("continueRequest"); - self.resume_http_request(); - } + fn on_http_call_response(&mut self, _: u32, _: usize, _: usize, _: usize) { + info!("continueRequest"); + self.resume_http_request(); + } } diff --git a/test/extensions/filters/http/wasm/test_data/shared_data_rust.rs b/test/extensions/filters/http/wasm/test_data/shared_data_rust.rs index aefd353d23634..968b4eacf9be3 100644 --- a/test/extensions/filters/http/wasm/test_data/shared_data_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/shared_data_rust.rs @@ -12,37 +12,40 @@ struct TestRoot; impl Context for TestRoot {} impl RootContext for TestRoot { - fn on_tick(&mut self) { - if self.get_shared_data("shared_data_key_bad") == (None, None) { - debug!("get of bad key not found"); - } - self.set_shared_data("shared_data_key1", Some(b"shared_data_value0"), None) - .unwrap(); - self.set_shared_data("shared_data_key1", Some(b"shared_data_value1"), None) - .unwrap(); - self.set_shared_data("shared_data_key2", Some(b"shared_data_value2"), None) - .unwrap(); - if let (_, Some(cas)) = self.get_shared_data("shared_data_key2") { - match self.set_shared_data( - "shared_data_key2", - Some(b"shared_data_value3"), - Some(cas + 1), - ) { - Err(Status::CasMismatch) => info!("set CasMismatch"), - _ => panic!(), - }; - } + fn on_tick(&mut self) { + if self.get_shared_data("shared_data_key_bad") == (None, None) { + debug!("get of bad key not found"); } + self + .set_shared_data("shared_data_key1", Some(b"shared_data_value0"), None) + .unwrap(); + self + .set_shared_data("shared_data_key1", Some(b"shared_data_value1"), None) + .unwrap(); + self + .set_shared_data("shared_data_key2", Some(b"shared_data_value2"), None) + .unwrap(); + if let (_, Some(cas)) = self.get_shared_data("shared_data_key2") { + match self.set_shared_data( + "shared_data_key2", + Some(b"shared_data_value3"), + Some(cas + 1), + ) { + Err(Status::CasMismatch) => info!("set CasMismatch"), + _ => panic!(), + }; + } + } - fn on_queue_ready(&mut self, _: u32) { - if self.get_shared_data("shared_data_key_bad") == (None, None) { - debug!("second get of bad key not found"); - } - if let (Some(value), _) = self.get_shared_data("shared_data_key1") { - debug!("get 1 {}", String::from_utf8(value).unwrap()); - } - if let (Some(value), _) = self.get_shared_data("shared_data_key2") { - warn!("get 2 {}", String::from_utf8(value).unwrap()); - } + fn on_queue_ready(&mut self, _: u32) { + if self.get_shared_data("shared_data_key_bad") == (None, None) { + debug!("second get of bad key not found"); + } + if let (Some(value), _) = self.get_shared_data("shared_data_key1") { + debug!("get 1 {}", String::from_utf8(value).unwrap()); + } + if let (Some(value), _) = self.get_shared_data("shared_data_key2") { + warn!("get 2 {}", String::from_utf8(value).unwrap()); } + } } diff --git a/test/extensions/filters/http/wasm/test_data/shared_queue_rust.rs b/test/extensions/filters/http/wasm/test_data/shared_queue_rust.rs index 30969d91cd29b..81ff481a48e5c 100644 --- a/test/extensions/filters/http/wasm/test_data/shared_queue_rust.rs +++ b/test/extensions/filters/http/wasm/test_data/shared_queue_rust.rs @@ -10,76 +10,77 @@ proxy_wasm::main! {{ }} struct TestRoot { - queue_id: Option, + queue_id: Option, } impl Context for TestRoot {} impl RootContext for TestRoot { - fn on_vm_start(&mut self, _: usize) -> bool { - self.queue_id = Some(self.register_shared_queue("my_shared_queue")); - true - } + fn on_vm_start(&mut self, _: usize) -> bool { + self.queue_id = Some(self.register_shared_queue("my_shared_queue")); + true + } - fn on_queue_ready(&mut self, queue_id: u32) { - if Some(queue_id) == self.queue_id { - info!("onQueueReady"); - match self.dequeue_shared_queue(9999999 /* bad queue_id */) { - Err(Status::NotFound) => warn!("onQueueReady bad token not found"), - _ => (), - } - if let Some(value) = self.dequeue_shared_queue(queue_id).unwrap() { - debug!("data {} Ok", String::from_utf8(value).unwrap()); - } - if self.dequeue_shared_queue(queue_id).unwrap().is_none() { - warn!("onQueueReady extra data not found"); - } - } + fn on_queue_ready(&mut self, queue_id: u32) { + if Some(queue_id) == self.queue_id { + info!("onQueueReady"); + match self.dequeue_shared_queue(9999999 /* bad queue_id */) { + Err(Status::NotFound) => warn!("onQueueReady bad token not found"), + _ => (), + } + if let Some(value) = self.dequeue_shared_queue(queue_id).unwrap() { + debug!("data {} Ok", String::from_utf8(value).unwrap()); + } + if self.dequeue_shared_queue(queue_id).unwrap().is_none() { + warn!("onQueueReady extra data not found"); + } } + } - fn get_type(&self) -> Option { - Some(ContextType::HttpContext) - } + fn get_type(&self) -> Option { + Some(ContextType::HttpContext) + } - fn create_http_context(&self, _: u32) -> Option> { - Some(Box::new(TestStream { - queue_id: self.queue_id, - })) - } + fn create_http_context(&self, _: u32) -> Option> { + Some(Box::new(TestStream { + queue_id: self.queue_id, + })) + } } struct TestStream { - queue_id: Option, + queue_id: Option, } impl Context for TestStream {} impl HttpContext for TestStream { - fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - if self.resolve_shared_queue("", "bad_shared_queue").is_none() { - warn!("onRequestHeaders not found self/bad_shared_queue"); - } - if self - .resolve_shared_queue("vm_id", "bad_shared_queue") - .is_none() - { - warn!("onRequestHeaders not found vm_id/bad_shared_queue"); - } - if self - .resolve_shared_queue("bad_vm_id", "bad_shared_queue") - .is_none() - { - warn!("onRequestHeaders not found bad_vm_id/bad_shared_queue"); - } - if Some(self.resolve_shared_queue("", "my_shared_queue")) == Some(self.queue_id) { - warn!("onRequestHeaders found self/my_shared_queue"); - } - if Some(self.resolve_shared_queue("vm_id", "my_shared_queue")) == Some(self.queue_id) { - warn!("onRequestHeaders found vm_id/my_shared_queue"); - } - self.enqueue_shared_queue(self.queue_id.unwrap(), Some(b"data1")) - .unwrap(); - warn!("onRequestHeaders enqueue Ok"); - Action::Continue + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + if self.resolve_shared_queue("", "bad_shared_queue").is_none() { + warn!("onRequestHeaders not found self/bad_shared_queue"); + } + if self + .resolve_shared_queue("vm_id", "bad_shared_queue") + .is_none() + { + warn!("onRequestHeaders not found vm_id/bad_shared_queue"); + } + if self + .resolve_shared_queue("bad_vm_id", "bad_shared_queue") + .is_none() + { + warn!("onRequestHeaders not found bad_vm_id/bad_shared_queue"); + } + if Some(self.resolve_shared_queue("", "my_shared_queue")) == Some(self.queue_id) { + warn!("onRequestHeaders found self/my_shared_queue"); + } + if Some(self.resolve_shared_queue("vm_id", "my_shared_queue")) == Some(self.queue_id) { + warn!("onRequestHeaders found vm_id/my_shared_queue"); } + self + .enqueue_shared_queue(self.queue_id.unwrap(), Some(b"data1")) + .unwrap(); + warn!("onRequestHeaders enqueue Ok"); + Action::Continue + } } diff --git a/test/extensions/filters/network/wasm/test_data/close_stream_rust.rs b/test/extensions/filters/network/wasm/test_data/close_stream_rust.rs index b94db386e3be1..01cd0cd63e233 100644 --- a/test/extensions/filters/network/wasm/test_data/close_stream_rust.rs +++ b/test/extensions/filters/network/wasm/test_data/close_stream_rust.rs @@ -10,13 +10,13 @@ struct TestStream; impl Context for TestStream {} impl StreamContext for TestStream { - fn on_downstream_data(&mut self, _: usize, _: bool) -> Action { - self.close_downstream(); - Action::Continue - } + fn on_downstream_data(&mut self, _: usize, _: bool) -> Action { + self.close_downstream(); + Action::Continue + } - fn on_upstream_data(&mut self, _: usize, _: bool) -> Action { - self.close_upstream(); - Action::Continue - } + fn on_upstream_data(&mut self, _: usize, _: bool) -> Action { + self.close_upstream(); + Action::Continue + } } diff --git a/test/extensions/filters/network/wasm/test_data/logging_rust.rs b/test/extensions/filters/network/wasm/test_data/logging_rust.rs index beb04cfd863bd..d5935440b9162 100644 --- a/test/extensions/filters/network/wasm/test_data/logging_rust.rs +++ b/test/extensions/filters/network/wasm/test_data/logging_rust.rs @@ -10,57 +10,57 @@ proxy_wasm::main! {{ }} struct TestStream { - context_id: u32, + context_id: u32, } impl Context for TestStream {} impl StreamContext for TestStream { - fn on_new_connection(&mut self) -> Action { - trace!("onNewConnection {}", self.context_id); - Action::Continue - } + fn on_new_connection(&mut self) -> Action { + trace!("onNewConnection {}", self.context_id); + Action::Continue + } - fn on_downstream_data(&mut self, data_size: usize, end_of_stream: bool) -> Action { - if let Some(data) = self.get_downstream_data(0, data_size) { - trace!( - "onDownstreamData {} len={} end_stream={}\n{}", - self.context_id, - data_size, - end_of_stream as u32, - String::from_utf8(data).unwrap() - ); - } - self.set_downstream_data(0, data_size, b"write"); - Action::Continue + fn on_downstream_data(&mut self, data_size: usize, end_of_stream: bool) -> Action { + if let Some(data) = self.get_downstream_data(0, data_size) { + trace!( + "onDownstreamData {} len={} end_stream={}\n{}", + self.context_id, + data_size, + end_of_stream as u32, + String::from_utf8(data).unwrap() + ); } + self.set_downstream_data(0, data_size, b"write"); + Action::Continue + } - fn on_upstream_data(&mut self, data_size: usize, end_of_stream: bool) -> Action { - if let Some(data) = self.get_upstream_data(0, data_size) { - trace!( - "onUpstreamData {} len={} end_stream={}\n{}", - self.context_id, - data_size, - end_of_stream as u32, - String::from_utf8(data).unwrap() - ); - } - Action::Continue + fn on_upstream_data(&mut self, data_size: usize, end_of_stream: bool) -> Action { + if let Some(data) = self.get_upstream_data(0, data_size) { + trace!( + "onUpstreamData {} len={} end_stream={}\n{}", + self.context_id, + data_size, + end_of_stream as u32, + String::from_utf8(data).unwrap() + ); } + Action::Continue + } - fn on_downstream_close(&mut self, peer_type: PeerType) { - trace!( - "onDownstreamConnectionClose {} {}", - self.context_id, - peer_type as u32, - ); - } + fn on_downstream_close(&mut self, peer_type: PeerType) { + trace!( + "onDownstreamConnectionClose {} {}", + self.context_id, + peer_type as u32, + ); + } - fn on_upstream_close(&mut self, peer_type: PeerType) { - trace!( - "onUpstreamConnectionClose {} {}", - self.context_id, - peer_type as u32, - ); - } + fn on_upstream_close(&mut self, peer_type: PeerType) { + trace!( + "onUpstreamConnectionClose {} {}", + self.context_id, + peer_type as u32, + ); + } } diff --git a/test/extensions/filters/network/wasm/test_data/panic_rust.rs b/test/extensions/filters/network/wasm/test_data/panic_rust.rs index aaa1fbb684807..4c9cc19544891 100644 --- a/test/extensions/filters/network/wasm/test_data/panic_rust.rs +++ b/test/extensions/filters/network/wasm/test_data/panic_rust.rs @@ -10,15 +10,15 @@ struct TestStream; impl Context for TestStream {} impl StreamContext for TestStream { - fn on_new_connection(&mut self) -> Action { - panic!(""); - } + fn on_new_connection(&mut self) -> Action { + panic!(""); + } - fn on_downstream_data(&mut self, _: usize, _: bool) -> Action { - panic!(""); - } + fn on_downstream_data(&mut self, _: usize, _: bool) -> Action { + panic!(""); + } - fn on_upstream_data(&mut self, _: usize, _: bool) -> Action { - panic!(""); - } + fn on_upstream_data(&mut self, _: usize, _: bool) -> Action { + panic!(""); + } } diff --git a/test/extensions/filters/network/wasm/test_data/resume_call_rust.rs b/test/extensions/filters/network/wasm/test_data/resume_call_rust.rs index 5423885a5f228..a5336553d4c24 100644 --- a/test/extensions/filters/network/wasm/test_data/resume_call_rust.rs +++ b/test/extensions/filters/network/wasm/test_data/resume_call_rust.rs @@ -15,46 +15,46 @@ proxy_wasm::main! {{ }} struct TestStream { - context_id: u32, - downstream_callout: Option, - upstream_callout: Option, + context_id: u32, + downstream_callout: Option, + upstream_callout: Option, } impl StreamContext for TestStream { - fn on_downstream_data(&mut self, _: usize, _: bool) -> Action { - self.downstream_callout = self - .dispatch_http_call( - "cluster", - vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], - Some(b"resume"), - vec![], - Duration::from_secs(1), - ) - .ok(); - trace!("onDownstreamData {}", self.context_id); - Action::Pause - } + fn on_downstream_data(&mut self, _: usize, _: bool) -> Action { + self.downstream_callout = self + .dispatch_http_call( + "cluster", + vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], + Some(b"resume"), + vec![], + Duration::from_secs(1), + ) + .ok(); + trace!("onDownstreamData {}", self.context_id); + Action::Pause + } - fn on_upstream_data(&mut self, _: usize, _: bool) -> Action { - self.upstream_callout = self - .dispatch_http_call( - "cluster", - vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], - Some(b"resume"), - vec![], - Duration::from_secs(1), - ) - .ok(); - trace!("onUpstreamData {}", self.context_id); - Action::Pause - } + fn on_upstream_data(&mut self, _: usize, _: bool) -> Action { + self.upstream_callout = self + .dispatch_http_call( + "cluster", + vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], + Some(b"resume"), + vec![], + Duration::from_secs(1), + ) + .ok(); + trace!("onUpstreamData {}", self.context_id); + Action::Pause + } } impl Context for TestStream { - fn on_http_call_response(&mut self, callout_id: u32, _: usize, _: usize, _: usize) { - if Some(callout_id) == self.downstream_callout { - self.resume_downstream(); - info!("continueDownstream"); - } + fn on_http_call_response(&mut self, callout_id: u32, _: usize, _: usize, _: usize) { + if Some(callout_id) == self.downstream_callout { + self.resume_downstream(); + info!("continueDownstream"); } + } } diff --git a/tools/code_format/check_format.py b/tools/code_format/check_format.py index a7855dfc92957..065467990ad82 100755 --- a/tools/code_format/check_format.py +++ b/tools/code_format/check_format.py @@ -1050,6 +1050,7 @@ def run_checks(self): self.config.buildifier_path self.config.buildozer_path self.check_visibility() + self.run_rustfmt() # We first run formatting on non-BUILD files, since the BUILD file format # requires analysis of srcs/hdrs in the BUILD file, and we don't want these # to be rewritten by other multiprocessing pooled processes. @@ -1092,6 +1093,28 @@ def check_visibility(self): except subprocess.CalledProcessError as e: if (e.returncode != 0 and e.returncode != 1): self.error_messages.append("Failed to check visibility with command %s" % command) + + def run_rustfmt(self): + # Run bazel + command = "bazel run @rules_rust//:rustfmt" + try: + subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT).strip() + except subprocess.CalledProcessError as e: + self.error_messages.append( + f"ERROR: something went wrong while executing: {e.cmd}\n{e.output.decode()}") + return + if self.args.operation_type == "check": + try: + diff = subprocess.check_output( + "git diff --name-only -- '*.rs'", shell=True, + stderr=subprocess.STDOUT).strip().decode() + if diff: + self.error_messages.append( + f"ERROR: rustfmt diff detected. Please run 'bazel run @rules_rust//:rustfmt':\n{diff}" + ) + except subprocess.CalledProcessError as e: + self.error_messages.append( + f"ERROR: git diff failed: {e.output.decode()}") def included_for_memcpy(self, file_path): return file_path in self.config.paths["memcpy"]["include"] From c96b0b10ef726a08b2e23c82d5b4a576dfedbefd Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 26 Mar 2026 21:18:06 +0000 Subject: [PATCH 2/2] trailing space Signed-off-by: Takeshi Yoneda --- tools/code_format/check_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/code_format/check_format.py b/tools/code_format/check_format.py index 065467990ad82..6151552643be6 100755 --- a/tools/code_format/check_format.py +++ b/tools/code_format/check_format.py @@ -1093,7 +1093,7 @@ def check_visibility(self): except subprocess.CalledProcessError as e: if (e.returncode != 0 and e.returncode != 1): self.error_messages.append("Failed to check visibility with command %s" % command) - + def run_rustfmt(self): # Run bazel command = "bazel run @rules_rust//:rustfmt"