From 70db53d8af0e22c90a60e875823f41d5909bb923 Mon Sep 17 00:00:00 2001 From: Akiomi Kamakura Date: Mon, 1 Jan 2024 19:08:56 +0900 Subject: [PATCH] Fix config test --- src/config.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1f081422..a84b4e59 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, fmt, path::PathBuf, process::exit}; use color_eyre::eyre::Result; -use config::Value; +use config::{ConfigError, Value}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use derive_deref::{Deref, DerefMut}; use ratatui::style::{Color, Modifier, Style}; @@ -67,7 +67,9 @@ impl Config { } if !found_config { log::error!("No configuration file found"); - exit(1); + return Err(ConfigError::NotFound(String::from( + "No configuration file found", + ))); } let mut cfg: Self = builder.build()?.try_deserialize()?; @@ -89,6 +91,10 @@ impl Config { } } + if cfg.privatekey.is_empty() { + return Err(ConfigError::NotFound(String::from("No `privatekey` found"))); + } + if cfg.relays.is_empty() { cfg.relays = default_config.relays.clone(); } @@ -476,17 +482,19 @@ mod tests { } #[test] - fn test_config() -> Result<()> { - let c = Config::new()?; - assert_eq!( - c.keybindings - .get(&Mode::Home) - .unwrap() - .get(&parse_key_sequence("").unwrap_or_default()) - .unwrap(), - &Action::Quit - ); - Ok(()) + fn test_config() { + assert_eq!(Config::new().is_err(), true); + + // let c = Config::new()?; + // assert_eq!( + // c.keybindings + // .get(&Mode::Home) + // .unwrap() + // .get(&parse_key_sequence("").unwrap_or_default()) + // .unwrap(), + // &Action::Quit + // ); + // Ok(()) } #[test]