Skip to content

Commit

Permalink
Add error state tests for --custom-schemes flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyGolden committed Jul 12, 2024
1 parent 27d92f8 commit 36888ca
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/operations/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ pub fn list(data_path: &Path, is_custom: bool) -> Result<()> {
}
(false, false) => {
return Err(anyhow!(
"Scheme repo path does not exist: {}\nRun `{} install` and try again",
schemes_dir_path.display(),
"Schemes are missing, run install and then try again: `{} install`",
REPO_NAME
))
}
Expand Down
29 changes: 29 additions & 0 deletions tests/cli_info_subcommand_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ fn test_cli_info_subcommand_without_setup() -> Result<()> {
Ok(())
}

#[test]
fn test_cli_info_subcommand_without_setup_with_custom_schemes_flag() -> Result<()> {
// -------
// Arrange
// -------
let test_name = "test_info_list_subcommand_without_setup_with_custom_schemes_flag";
let (_, _, command_vec, cleanup) = setup(test_name, "list --custom-schemes")?;
let expected_output = format!(
"You don't have any local custom schemes at: data_path_{}/custom-schemes",
test_name
);

// ---
// Act
// ---
let (_, stderr) = utils::run_command(command_vec).unwrap();

// ------
// Assert
// ------
assert!(
stderr.contains(&expected_output),
"stdout does not contain the expected output"
);

cleanup()?;
Ok(())
}

#[test]
fn test_cli_info_subcommand_with_setup_invalid_scheme_name() -> Result<()> {
// -------
Expand Down
29 changes: 29 additions & 0 deletions tests/cli_list_subcommand_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ fn test_cli_list_subcommand_without_setup() -> Result<()> {
Ok(())
}

#[test]
fn test_cli_list_subcommand_without_setup_with_custom_schemes_flag() -> Result<()> {
// -------
// Arrange
// -------
let test_name = "test_cli_list_subcommand_without_setup_with_custom_schemes_flag";
let (_, _, command_vec, cleanup) = setup(test_name, "list --custom-schemes")?;
let expected_output = format!(
"You don't have any local custom schemes at: data_path_{}/custom-schemes",
test_name
);

// ---
// Act
// ---
let (_, stderr) = utils::run_command(command_vec).unwrap();

// ------
// Assert
// ------
assert!(
stderr.contains(&expected_output),
"stdout does not contain the expected output"
);

cleanup()?;
Ok(())
}

#[test]
fn test_cli_list_subcommand_with_setup() -> Result<()> {
// -------
Expand Down

0 comments on commit 36888ca

Please sign in to comment.