[tests] Fix minor test errors

- Fix command line arguments
- Adapt error messages for rust implementations
This commit is contained in:
Ming-Hung Tsai 2021-06-21 15:44:56 +08:00
parent 2bd3c17578
commit fba2adbe56
7 changed files with 29 additions and 12 deletions

View File

@ -25,14 +25,12 @@ fn main() {
.arg(
Arg::with_name("SB_ONLY")
.help("Only check the superblock.")
.long("super-block-only")
.value_name("SB_ONLY"),
.long("super-block-only"),
)
.arg(
Arg::with_name("SKIP_MAPPINGS")
.help("Don't check the mapping tree")
.long("skip-mappings")
.value_name("SKIP_MAPPINGS"),
.long("skip-mappings"),
)
.arg(
Arg::with_name("AUTO_REPAIR")
@ -47,7 +45,7 @@ fn main() {
.arg(
Arg::with_name("CLEAR_NEEDS_CHECK")
.help("Clears the 'needs_check' flag in the superblock")
.long("clear-needs-check"),
.long("clear-needs-check-flag"),
)
.arg(
Arg::with_name("OVERRIDE_MAPPING_ROOT")

View File

@ -42,7 +42,7 @@ fn accepts_help() -> Result<()> {
#[test]
fn missing_metadata() -> Result<()> {
let stderr = run_fail(cache_check!())?;
assert!(stderr.contains("No input file provided"));
assert!(stderr.contains(msg::MISSING_INPUT_ARG));
Ok(())
}
@ -66,7 +66,7 @@ fn unreadable_metadata() -> Result<()> {
let md = mk_valid_md(&mut td)?;
cmd!("chmod", "-r", &md).run()?;
let stderr = run_fail(cache_check!(&md))?;
assert!(stderr.contains("syscall 'open' failed: Permission denied"));
assert!(stderr.contains("Permission denied"));
Ok(())
}

View File

@ -18,6 +18,22 @@ use test_dir::TestDir;
//------------------------------------------
#[cfg(not(feature = "rust_tests"))]
pub mod msg {
pub const FILE_NOT_FOUND: &str = "Couldn't stat file";
pub const MISSING_INPUT_ARG: &str = "No input file provided";
pub const MISSING_OUTPUT_ARG: &str = "No output file provided";
}
#[cfg(feature = "rust_tests")]
pub mod msg {
pub const FILE_NOT_FOUND: &str = "Couldn't find input file";
pub const MISSING_INPUT_ARG: &str = "The following required arguments were not provided";
pub const MISSING_OUTPUT_ARG: &str = "The following required arguments were not provided";
}
//------------------------------------------
#[macro_export]
macro_rules! path_to_cpp {
($name: literal) => {

View File

@ -65,6 +65,7 @@ fn snap2_unspecified() -> Result<()> {
#[test]
fn dev_unspecified() -> Result<()> {
let stderr = run_fail(thin_delta!("--snap1", "45", "--snap2", "46"))?;
assert!(stderr.contains("No input device provided"));
// TODO: replace with msg::MISSING_INPUT_ARG once the rust version is ready
assert!(stderr.contains("No input file provided"));
Ok(())
}

View File

@ -53,6 +53,7 @@ fn missing_input_file() -> Result<()> {
let md = mk_zeroed_md(&mut td)?;
let stderr = run_fail(thin_repair!("-i", "no-such-file", "-o", &md))?;
assert!(superblock_all_zeroes(&md)?);
// TODO: replace with msg::FILE_NOT_FOUND once the rust version is ready
assert!(stderr.contains("Couldn't stat file"));
Ok(())
}
@ -72,6 +73,7 @@ fn missing_output_file() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let stderr = run_fail(thin_repair!("-i", &md))?;
// TODO: replace with msg::MISSING_OUTPUT_ARG once the rust version is ready
assert!(stderr.contains("No output file provided."));
Ok(())
}

View File

@ -44,7 +44,7 @@ fn no_input_file() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let stderr = run_fail(thin_restore!("-o", &md))?;
assert!(stderr.contains("No input file provided."));
assert!(stderr.contains(msg::MISSING_INPUT_ARG));
Ok(())
}
@ -54,7 +54,7 @@ fn missing_input_file() -> Result<()> {
let md = mk_zeroed_md(&mut td)?;
let stderr = run_fail(thin_restore!("-i", "no-such-file", "-o", &md))?;
assert!(superblock_all_zeroes(&md)?);
assert!(stderr.contains("Couldn't stat file"));
assert!(stderr.contains(msg::FILE_NOT_FOUND));
Ok(())
}
@ -73,7 +73,7 @@ fn no_output_file() -> Result<()> {
let mut td = TestDir::new()?;
let xml = mk_valid_xml(&mut td)?;
let stderr = run_fail(thin_restore!("-i", &xml))?;
assert!(stderr.contains("No output file provided."));
assert!(stderr.contains(msg::MISSING_OUTPUT_ARG));
Ok(())
}

View File

@ -687,7 +687,7 @@ thin_delta_cmd::run(int argc, char **argv)
}
if (argc == optind)
die("No input device provided.");
die("No input file provided.");
else
fs.dev = argv[optind];