diff --git a/encoderfile/Cargo.toml b/encoderfile/Cargo.toml index 640b5587..04a044d9 100644 --- a/encoderfile/Cargo.toml +++ b/encoderfile/Cargo.toml @@ -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" diff --git a/encoderfile/src/build_cli/config.rs b/encoderfile/src/build_cli/config.rs index a004b68c..0268c844 100644 --- a/encoderfile/src/build_cli/config.rs +++ b/encoderfile/src/build_cli/config.rs @@ -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 { + 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) diff --git a/encoderfile/tests/integration/test_config_does_not_exist.rs b/encoderfile/tests/integration/test_config_does_not_exist.rs new file mode 100644 index 00000000..74fd7b9a --- /dev/null +++ b/encoderfile/tests/integration/test_config_does_not_exist.rs @@ -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(()) +}