Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/config tests #18

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
config.toml
Cargo.lock
target
dev.log
logs
devlogs
config_*.toml
CONFIG_*.toml
.vscode/settings.json
.pre-commit-config.yaml
51 changes: 42 additions & 9 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
43 changes: 43 additions & 0 deletions test/config.toml
Original file line number Diff line number Diff line change
@@ -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 <https://butz.com/index.php/settings/user/security>
# 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