Skip to content
Open
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
5 changes: 5 additions & 0 deletions encoderfile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ name = "test_build_encoderfile"
path = "tests/integration/test_build.rs"
required-features = ["dev-utils"]

[[test]]
name = "test_config_does_not_exist"
path = "tests/integration/test_config_does_not_exist.rs"
required-features = ["dev-utils"]

[[test]]
name = "test_inspect_encoderfile"
path = "tests/integration/test_inspect.rs"
Expand Down
5 changes: 5 additions & 0 deletions encoderfile/src/build_cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ pub struct BuildConfig {
pub encoderfile: EncoderfileConfig,
}

pub const CONFIG_FILE_NOT_FOUND_MSG: &str = "Encoderfile config not found";

impl BuildConfig {
pub fn load(path: &PathBuf) -> Result<Self> {
if !path.try_exists().expect(CONFIG_FILE_NOT_FOUND_MSG) {
bail!(CONFIG_FILE_NOT_FOUND_MSG);
}
let config = Figment::new().merge(Yaml::file(path)).extract()?;

Ok(config)
Expand Down
30 changes: 30 additions & 0 deletions encoderfile/tests/integration/test_config_does_not_exist.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use anyhow::{Context, Result};
use encoderfile::build_cli::cli::GlobalArguments;
use encoderfile::build_cli::config::CONFIG_FILE_NOT_FOUND_MSG;
use std::path::Path;
use tempfile::tempdir;

#[tokio::test]
async fn test_config_does_not_exist() -> Result<()> {
let dir = tempdir()?;
let path = dir
.path()
.canonicalize()
.expect("Failed to canonicalize temp path")
.join("encoderfile_does_not_exist.yml");

let build_args = encoderfile::build_cli::cli::test_build_args(
path.as_path(),
Path::new("dummy_binary_path"),
);

let global_args = GlobalArguments::default();

let build_result = build_args
.run(&global_args)
.context("Failed to build encoderfile");
assert!(build_result.is_err());
build_result.expect_err(CONFIG_FILE_NOT_FOUND_MSG);

Ok(())
}