Skip to content

Commit a3ed204

Browse files
committed
Add testing for websocket notifications.
Signed-off-by: David Venhoek <david@tweedegolf.com>
1 parent 94dec41 commit a3ed204

5 files changed

Lines changed: 361 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ serde_with = { version = "3.17.0", features = ["macros"] }
2929
reqwest = { version = "0.13.2", default-features = false, features = ["http2", "charset", "rustls", "json", "query", "form"] }
3030
tokio = { version = "1.50.0", features = ["full", "test-util"] }
3131
tokio-test = "0.4.5"
32+
futures = "0.3.32"
3233
axum = { version = "0.8.8", features = ["macros"] }
3334
axum-extra = { version = "0.12.5", features = ["query", "typed-header"] }
35+
tokio-tungstenite = "0.29.0"
3436
tower = { version = "0.5.3", features = ["util"] }
3537

3638
tracing = "0.1.44"

openleadr-vtn/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ mdns-sd = { workspace = true, optional = true }
4949

5050
[dev-dependencies]
5151
tokio = { workspace = true, features = ["full", "test-util"] }
52+
futures.workspace = true
53+
tokio-tungstenite.workspace = true
5254
serial_test.workspace = true
5355
serde_html_form = "0.4.0"
5456
openleadr-client = { path = "../openleadr-client" }
5557

5658
[features]
57-
default = ["postgres", "compression-br", "compression-deflate", "compression-gzip", "compression-zstd"]
59+
default = ["postgres", "compression-br", "compression-deflate", "compression-gzip", "compression-zstd", "experimental-websockets"]
5860
live-db-test = ["postgres", "internal-oauth"]
5961
postgres = ["sqlx/postgres", "dep:dotenvy", "dep:argon2"]
6062
internal-oauth = []

openleadr-vtn/src/api/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ pub mod test {
115115
use reqwest::Method;
116116
use serde::de::DeserializeOwned;
117117
use sqlx::PgPool;
118-
use std::fmt::Display;
118+
use std::{
119+
fmt::Display,
120+
future::IntoFuture,
121+
net::{Ipv4Addr, SocketAddr},
122+
};
123+
use tokio::{net::TcpListener, task::JoinHandle};
119124
use tower::ServiceExt;
120125

121126
pub(crate) struct ApiTest {
@@ -142,6 +147,18 @@ pub mod test {
142147
Self { router, token }
143148
}
144149

150+
#[cfg(feature = "experimental-websockets")]
151+
pub(crate) async fn run(
152+
&self,
153+
) -> (String, SocketAddr, JoinHandle<Result<(), std::io::Error>>) {
154+
let listener = TcpListener::bind(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 0))
155+
.await
156+
.unwrap();
157+
let listen_addr = listener.local_addr().unwrap();
158+
let handle = tokio::spawn(axum::serve(listener, self.router.clone()).into_future());
159+
(self.token.clone(), listen_addr, handle)
160+
}
161+
145162
pub(crate) async fn request<T: DeserializeOwned>(
146163
&self,
147164
method: Method,

0 commit comments

Comments
 (0)