fix: resolve test compilation errors and doctest issues

- Add HotkeysConfig::default() to Config initializers in tests
- Wrap env::set_var/remove_var calls in unsafe blocks
- Fix doctest in App::new() (select_chat -> select_current_chat)
- Mark TdClient doctest as ignore (async code needs runtime)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Kilin
2026-02-01 00:24:52 +03:00
parent 0ae8a2fb88
commit ec3e6d2a2a
3 changed files with 24 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
// Integration tests for config flow
use tele_tui::config::{Config, ColorsConfig, GeneralConfig};
use tele_tui::config::{Config, ColorsConfig, GeneralConfig, HotkeysConfig};
/// Test: Дефолтные значения конфигурации
#[test]
@@ -32,6 +32,7 @@ fn test_config_custom_values() {
reaction_chosen: "green".to_string(),
reaction_other: "white".to_string(),
},
hotkeys: HotkeysConfig::default(),
};
assert_eq!(config.general.timezone, "+05:00");
@@ -114,6 +115,7 @@ fn test_config_toml_serialization() {
reaction_chosen: "green".to_string(),
reaction_other: "white".to_string(),
},
hotkeys: HotkeysConfig::default(),
};
// Сериализуем в TOML
@@ -190,8 +192,10 @@ mod credentials_tests {
#[test]
fn test_load_credentials_from_env() {
// Устанавливаем env переменные для теста
env::set_var("API_ID", "12345");
env::set_var("API_HASH", "test_hash_from_env");
unsafe {
env::set_var("API_ID", "12345");
env::set_var("API_HASH", "test_hash_from_env");
}
// Загружаем credentials
let result = Config::load_credentials();
@@ -208,8 +212,10 @@ mod credentials_tests {
}
// Очищаем env переменные после теста
env::remove_var("API_ID");
env::remove_var("API_HASH");
unsafe {
env::remove_var("API_ID");
env::remove_var("API_HASH");
}
}
/// Test: Проверка формата ошибки когда credentials не найдены
@@ -232,8 +238,10 @@ mod credentials_tests {
let original_api_id = env::var("API_ID").ok();
let original_api_hash = env::var("API_HASH").ok();
env::remove_var("API_ID");
env::remove_var("API_HASH");
unsafe {
env::remove_var("API_ID");
env::remove_var("API_HASH");
}
// Пытаемся загрузить credentials без файла и без env
let result = Config::load_credentials();
@@ -250,11 +258,13 @@ mod credentials_tests {
}
// Восстанавливаем env переменные
if let Some(api_id) = original_api_id {
env::set_var("API_ID", api_id);
}
if let Some(api_hash) = original_api_hash {
env::set_var("API_HASH", api_hash);
unsafe {
if let Some(api_id) = original_api_id {
env::set_var("API_ID", api_id);
}
if let Some(api_hash) = original_api_hash {
env::set_var("API_HASH", api_hash);
}
}
}
}