From 4da65ffb94267fcbf1b9ab16d5ff61c656eef65e Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Wed, 11 Dec 2024 20:58:42 +0100 Subject: [PATCH] Some settings integration testing setup --- crates/gitbutler-settings/Cargo.toml | 7 +++++++ crates/gitbutler-settings/src/lib.rs | 3 ++- .../modify_default_true_to_false/settings.json | 5 +++++ crates/gitbutler-settings/tests/mod.rs | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 crates/gitbutler-settings/tests/fixtures/modify_default_true_to_false/settings.json create mode 100644 crates/gitbutler-settings/tests/mod.rs diff --git a/crates/gitbutler-settings/Cargo.toml b/crates/gitbutler-settings/Cargo.toml index d799bad8e5..8dfa14118c 100644 --- a/crates/gitbutler-settings/Cargo.toml +++ b/crates/gitbutler-settings/Cargo.toml @@ -13,3 +13,10 @@ rust-embed = "8.4.0" serde_json_lenient = "0.2.3" gitbutler-settings-util.path = "vendor/util" gitbutler-fs.workspace = true + +[[test]] +name = "settings" +path = "tests/mod.rs" + +[dev-dependencies] +gitbutler-settings.workspace = true diff --git a/crates/gitbutler-settings/src/lib.rs b/crates/gitbutler-settings/src/lib.rs index 3a409809cb..4a67f25bc2 100644 --- a/crates/gitbutler-settings/src/lib.rs +++ b/crates/gitbutler-settings/src/lib.rs @@ -4,4 +4,5 @@ pub use legacy::LegacySettings; mod app_settings; mod json; -mod persistence; +pub mod persistence; +pub use app_settings::AppSettings; diff --git a/crates/gitbutler-settings/tests/fixtures/modify_default_true_to_false/settings.json b/crates/gitbutler-settings/tests/fixtures/modify_default_true_to_false/settings.json new file mode 100644 index 0000000000..6df367defb --- /dev/null +++ b/crates/gitbutler-settings/tests/fixtures/modify_default_true_to_false/settings.json @@ -0,0 +1,5 @@ +{ + "telemetry": { + "appMetricsEnabled": false + } +} diff --git a/crates/gitbutler-settings/tests/mod.rs b/crates/gitbutler-settings/tests/mod.rs new file mode 100644 index 0000000000..c86345d457 --- /dev/null +++ b/crates/gitbutler-settings/tests/mod.rs @@ -0,0 +1,15 @@ +use gitbutler_settings::AppSettings; + +#[test] +#[allow(clippy::bool_assert_comparison)] +fn test_load_settings() { + let settings = AppSettings::load("tests/fixtures/modify_default_true_to_false").unwrap(); + assert_eq!(settings.telemetry.app_metrics_enabled, false); // modified + assert_eq!(settings.telemetry.app_error_reporting_enabled, true); // default + assert_eq!(settings.telemetry.app_non_anon_metrics_enabled, false); // default + assert_eq!(settings.telemetry.app_analytics_confirmed, false); // default + assert_eq!( + settings.github_oauth_app.oauth_client_id, + "cd51880daa675d9e6452" + ); // default +}