Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic if default config also doesn't exist #7

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ fn deserialize(content: &str) -> Result<Config, DigsError> {
}

pub fn get(path: &Path) -> Result<Config, DigsError> {
// path must be exists. unwrap is safe here.
let file_content = fs::read_to_string(path).unwrap();
let file_content = fs::read_to_string(path)?;
deserialize(&file_content)
}
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ pub enum DigsError {
// All cases from trust-dns
#[error("Error: {0:?}")]
ForeignError(#[from] ClientError),

// All cases of `std::io::Error`.
#[error(transparent)]
IOError(#[from] std::io::Error),
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn run() -> Result<()> {
// get config file
let config_path: PathBuf = match matches.value_of("config") {
Some(path) => utils::is_exist(path)?,
None => "digs.toml".into(),
None => utils::is_exist("digs.toml".into())?,
};
let config = config::get(&config_path)?;

Expand Down
9 changes: 9 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ fn help() {
.stdout(predicate::str::contains("digs \u{25cf} dig many at once"));
}

#[test]
fn default_config_not_found() {
let mut cmd = Command::cargo_bin("digs").unwrap();
cmd.arg("example.net").arg("-f").arg("file/doesnt/exist");
cmd.assert()
.failure()
.stderr(predicate::str::contains("No such file"));
}

#[test]
fn config_not_found() {
let mut cmd = Command::cargo_bin("digs").unwrap();
Expand Down