Skip to content

Commit

Permalink
Fix config test
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik committed Jan 1, 2024
1 parent 893d522 commit 70db53d
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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()?;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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("<q>").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("<q>").unwrap_or_default())
// .unwrap(),
// &Action::Quit
// );
// Ok(())
}

#[test]
Expand Down

0 comments on commit 70db53d

Please sign in to comment.