summaryrefslogtreecommitdiffstats
path: root/third_party/rust/warp/tests/tracing.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/warp/tests/tracing.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/warp/tests/tracing.rs')
-rw-r--r--third_party/rust/warp/tests/tracing.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/third_party/rust/warp/tests/tracing.rs b/third_party/rust/warp/tests/tracing.rs
new file mode 100644
index 0000000000..0ae88fbc38
--- /dev/null
+++ b/third_party/rust/warp/tests/tracing.rs
@@ -0,0 +1,48 @@
+use warp::Filter;
+
+#[tokio::test]
+async fn uses_tracing() {
+ // Setup a log subscriber (responsible to print to output)
+ let subscriber = tracing_subscriber::fmt::Subscriber::builder()
+ .with_env_filter("trace")
+ .without_time()
+ .finish();
+
+ // Set the previously created subscriber as the global subscriber
+ tracing::subscriber::set_global_default(subscriber).unwrap();
+ // Redirect normal log messages to the tracing subscriber
+ tracing_log::LogTracer::init().unwrap();
+
+ // Start a span with some metadata (fields)
+ let span = tracing::info_span!("app", domain = "www.example.org");
+ let _guard = span.enter();
+
+ log::info!("logged using log macro");
+
+ let ok = warp::any()
+ .map(|| {
+ tracing::info!("printed for every request");
+ })
+ .untuple_one()
+ .and(warp::path("aa"))
+ .map(|| {
+ tracing::info!("only printed when path '/aa' matches");
+ })
+ .untuple_one()
+ .map(warp::reply)
+ // Here we add the tracing logger which will ensure that all requests has a span with
+ // useful information about the request (method, url, version, remote_addr, etc.)
+ .with(warp::trace::request());
+
+ tracing::info!("logged using tracing macro");
+
+ // Send a request for /
+ let req = warp::test::request();
+ let resp = req.reply(&ok);
+ assert_eq!(resp.await.status(), 404);
+
+ // Send a request for /aa
+ let req = warp::test::request().path("/aa");
+ let resp = req.reply(&ok);
+ assert_eq!(resp.await.status(), 200);
+}