From ae52676e332e72efebe29ed2e8c15ae3235b330b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 27 Sep 2025 15:49:46 +0000 Subject: [PATCH] Add back the default database path. Allow default server_name when testing. Default to smoke test vector when testing. Signed-off-by: Jason Volk --- Cargo.toml | 5 ++++- docker/Dockerfile.nix | 1 + src/core/args.rs | 12 ++++++++++++ src/core/config/mod.rs | 17 ++++++++++++++--- src/main/tests/smoke.rs | 20 ++++++++++++++++++++ tuwunel-example.toml | 13 ++++++------- 6 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 src/main/tests/smoke.rs diff --git a/Cargo.toml b/Cargo.toml index 75b3d683..b08a2f3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -272,7 +272,10 @@ features = ["std"] [workspace.dependencies.nix] version = "0.30" default-features = false -features = ["resource"] +features = [ + "resource", + "user", +] [workspace.dependencies.num-traits] version = "0.2" diff --git a/docker/Dockerfile.nix b/docker/Dockerfile.nix index f9beb623..f3e1feae 100644 --- a/docker/Dockerfile.nix +++ b/docker/Dockerfile.nix @@ -26,6 +26,7 @@ ARG sys_target WORKDIR /usr/src/tuwunel COPY --link --from=source /usr/src/tuwunel . +ENV TUWUNEL_DATABASE_PATH="/tmp/buildtest.db" RUN \ --mount=type=cache,dst=/nix,sharing=shared \ --mount=type=cache,dst=/root/.cache/nix,sharing=shared \ diff --git a/src/core/args.rs b/src/core/args.rs index fec7ce28..c929c97c 100644 --- a/src/core/args.rs +++ b/src/core/args.rs @@ -149,6 +149,18 @@ pub struct Args { pub gc_muzzy: Option, } +impl Args { + #[must_use] + pub fn default_test(name: &str) -> Self { + let mut args = Self::default(); + args.test.push(name.into()); + args.option + .push("server_name=\"localhost\"".into()); + + args + } +} + impl Default for Args { fn default() -> Self { Self::parse() } } diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 27798e0c..9037e3f1 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -76,14 +76,14 @@ pub struct Config { /// WIPE. /// /// example: "girlboss.ceo" + #[cfg_attr(test, serde(default = "default_server_name"))] pub server_name: OwnedServerName, /// This is the only directory where tuwunel will save its data, including /// media. Note: this was previously "/var/lib/matrix-conduit". /// - /// YOU NEED TO EDIT THIS. - /// - /// example: "/var/lib/tuwunel" + /// default: "/var/lib/tuwunel" + #[serde(default = "default_database_path")] pub database_path: PathBuf, /// Text which will be added to the end of the user's displayname upon @@ -1870,6 +1870,12 @@ pub struct Config { #[serde(default)] pub tokio_console: bool, + /// Arbitrary argument vector for integration testing. Functionality in the + /// server is altered or informed for the requirements of integration tests. + /// - "smoke" performs a shutdown after startup admin commands rather than + /// hanging on client handling. + /// + /// default: [] #[serde(default)] pub test: BTreeSet, @@ -2571,6 +2577,11 @@ impl Config { fn true_fn() -> bool { true } +#[cfg(test)] +fn default_server_name() -> OwnedServerName { ruma::owned_server_name!("localhost") } + +fn default_database_path() -> PathBuf { "/var/lib/tuwunel".to_owned().into() } + fn default_address() -> ListeningAddr { ListeningAddr { addrs: Right(vec![Ipv4Addr::LOCALHOST.into(), Ipv6Addr::LOCALHOST.into()]), diff --git a/src/main/tests/smoke.rs b/src/main/tests/smoke.rs new file mode 100644 index 00000000..b0bb47f0 --- /dev/null +++ b/src/main/tests/smoke.rs @@ -0,0 +1,20 @@ +#![cfg(test)] + +use tuwunel::Server; +use tuwunel_core::{Args, Result, runtime}; + +#[test] +fn dummy() {} + +#[test] +#[should_panic = "dummy"] +fn panic_dummy() { panic!("dummy") } + +#[test] +fn smoke() -> Result { + let args = Args::default_test("smoke"); + let runtime = runtime::new(Some(&args))?; + let server = Server::new(Some(&args), Some(runtime.handle()))?; + + tuwunel::exec(&server, runtime) +} diff --git a/tuwunel-example.toml b/tuwunel-example.toml index 39a7019c..fb051c5b 100644 --- a/tuwunel-example.toml +++ b/tuwunel-example.toml @@ -39,11 +39,7 @@ # This is the only directory where tuwunel will save its data, including # media. Note: this was previously "/var/lib/matrix-conduit". # -# YOU NEED TO EDIT THIS. -# -# example: "/var/lib/tuwunel" -# -#database_path = +#database_path = "/var/lib/tuwunel" # Text which will be added to the end of the user's displayname upon # registration with a space before the text. In Conduit, this was the @@ -1613,9 +1609,12 @@ # #tokio_console = false -# This item is undocumented. Please contribute documentation for it. +# Arbitrary argument vector for integration testing. Functionality in the +# server is altered or informed for the requirements of integration tests. +# - "smoke" performs a shutdown after startup admin commands rather than +# hanging on client handling. # -#test = false +#test = [] # Controls whether admin room notices like account registrations, password # changes, account deactivations, room directory publications, etc will be