Update tests to use unnumbered ports

This commit is contained in:
Matthew Pomes 2024-08-10 12:18:33 -05:00 committed by Sergio Benitez
parent f803288f75
commit 81293224b8
1 changed files with 11 additions and 8 deletions

View File

@ -1,8 +1,8 @@
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
use figment::Figment; use rocket::figment::{providers::{Format as _, Toml}, Figment};
use rocket::{custom, fairing::AdHoc, Build, Orbit, Rocket, config::SecretKey}; use rocket::{custom, fairing::AdHoc, Build, Orbit, Rocket};
struct AsyncDropInAsync; struct AsyncDropInAsync;
@ -18,8 +18,13 @@ impl Drop for AsyncDropInAsync {
fn rocket() -> Rocket<Build> { fn rocket() -> Rocket<Build> {
let mut config = rocket::Config::default(); let mut config = rocket::Config::default();
config.secret_key = SecretKey::generate().unwrap(); #[cfg(feature = "secrets")]
let figment = Figment::from(config); { config.secret_key = rocket::config::SecretKey::generate().unwrap(); }
let figment = Figment::from(config).merge(Toml::string(r#"
[default]
address = "tcp:127.0.0.1:0"
port = 0
"#).nested());
custom(figment).manage(AsyncDropInAsync).attach(AdHoc::on_liftoff( custom(figment).manage(AsyncDropInAsync).attach(AdHoc::on_liftoff(
"Shutdown immediately", "Shutdown immediately",
|rocket: &Rocket<Orbit>| { |rocket: &Rocket<Orbit>| {
@ -42,12 +47,10 @@ mod launch {
} }
mod main { mod main {
use rocket::tokio::net::TcpListener;
#[rocket::main] #[rocket::main]
async fn main() { async fn main() {
super::rocket() super::rocket()
.try_launch_on(TcpListener::bind("localhost:8001")) .launch()
.await .await
.unwrap(); .unwrap();
} }
@ -59,7 +62,7 @@ mod main {
fn test_execute() { fn test_execute() {
rocket::execute(async { rocket::execute(async {
super::rocket() super::rocket()
.try_launch_on(TcpListener::bind("localhost:8002")) .launch()
.await .await
.unwrap(); .unwrap();
}); });