diff --git a/.gitignore b/.gitignore index e524876..e81bf31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,4 @@ -config.toml Cargo.lock target -dev.log -logs -devlogs -config_*.toml -CONFIG_*.toml .vscode/settings.json .pre-commit-config.yaml diff --git a/src/config/mod.rs b/src/config/mod.rs index 8945397..2e1dede 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -198,28 +198,61 @@ impl Config { #[cfg(test)] mod tests { - // use super::*; + use super::*; + + // The ordering of these tests is important since we set the static CONFIG object! #[test] #[should_panic(expected = "config not initialized")] fn get_config_before_init() { - super::get(); + get(); } #[test] #[should_panic( expected = "Could not Create Config dir: Os { code: 13, kind: PermissionDenied, message: \"Permission denied\" }" )] fn init_with_faulty_path() { - super::init("/test"); + init("/bogus_test/path"); } + #[test] - fn init_with_no_path() { - super::init(""); + fn default_values() { + init("./test/"); + assert!(get().get_data_dir().ends_with(".local/share/sechat-rs")); + assert!(get() + .get_server_data_dir() + .ends_with(".local/share/sechat-rs/MyNCInstance")); + assert!(get() + .get_http_dump_dir() + .expect("Not Https Dump Dir found") + .ends_with(".local/share/sechat-rs")); + assert!(get().get_enable_mouse()); + assert!(get().get_enable_paste()); } #[test] - #[should_panic(expected = "Could not set global config!: failed to set config Config")] - fn init_config_twice() { - super::init(""); - super::init(""); + fn init_logging() { + let conf = Config::default(); + conf.config_logging(); + } + + #[test] + fn update_data() { + let mut conf = Config::default(); + conf.set_config_data(Data::default()); + conf.set_strategy( + choose_app_strategy(AppStrategyArgs { + top_level_domain: "org".to_string(), + author: "emlix".to_string(), + app_name: "sechat-rs".to_string(), + }) + .unwrap(), + ); + assert!(conf.get_data_dir().ends_with(".local/share/sechat-rs")); + assert!(conf + .get_server_data_dir() + .ends_with(".local/share/sechat-rs")); + assert!(conf.get_http_dump_dir().is_none()); + assert!(!conf.get_enable_mouse()); + assert!(!conf.get_enable_paste()); } } diff --git a/test/config.toml b/test/config.toml new file mode 100644 index 0000000..ed5cea4 --- /dev/null +++ b/test/config.toml @@ -0,0 +1,43 @@ +[general] +# `General.chat_server_name` is the name used for storage and displaying +# UPDATE THIS FIELD +chat_server_name = "MyNCInstance" + +# `General.url` is the base url of the NC instance. Do not append any further parts. +# UPDATE THIS FIELD +url = "https://butz.com/" + +# `General.user` is the username. Usually not a email address. +# UPDATE THIS FIELD +user = "dummy_user" + +# `General.app_pw` generated by NC. See +# UPDATE THIS FIELD +app_pw = "foobar-asdasd-asdsf" + +# `General.log_to_file` should a log file be written into the apps data dir? +log_to_file = true + +# `General.dump_failed_requests_to_file` should a log file be written into the apps data dir? +dump_failed_requests_to_file = true + +[notifications] +# `Notifications.timeout_ms` how long a notification shall be displayed. +timeout_ms = 5000 + +persistent = false + +silent = false + +[ui] +# The default room you want to see on startup. +# UPDATE THIS FIELD +default_room = "General" + +categories = [ "", ] + +categories_separator = "" + +use_mouse = true + +use_paste = true