Skip to content

Commit

Permalink
Test that loading a non existent configuration file returns an IO error
Browse files Browse the repository at this point in the history
  • Loading branch information
SRv6d committed Oct 25, 2024
1 parent d46d4dd commit bf565a9
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use reqwest::Url;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{
collections::{HashMap, HashSet},
fmt,
fmt, io,
ops::Deref,
path::{Path, PathBuf},
sync::Arc,
Expand Down Expand Up @@ -158,8 +158,10 @@ impl Configuration {
}

/// An error that can occur when interacting with a [`Configuration`].
#[derive(Debug, PartialEq, thiserror::Error)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("{0}")]
Io(#[from] io::Error),
#[error("{0}")]
SyntaxError(figment::Error),
#[error("missing sources {0}")]
Expand Down Expand Up @@ -289,6 +291,18 @@ mod tests {
});
}

#[rstest]
fn loading_non_existent_configuration_returns_io_error(config_path: PathBuf) {
figment::Jail::expect_with(|_| {
let err = Configuration::load(&config_path, None).unwrap_err();
if let Error::Io(_) = err {
Ok(())
} else {
Err("Did not return expected error".into())
}
});
}

/// Loading configuration missing sources returns an appropriate error.
#[rstest]
#[case(
Expand Down

0 comments on commit bf565a9

Please sign in to comment.