thin-provisioning-tools/tests/cache_check.rs

158 lines
3.8 KiB
Rust
Raw Normal View History

use anyhow::Result;
mod common;
use common::cache::*;
use common::common_args::*;
use common::fixture::*;
use common::input_arg::*;
use common::process::*;
use common::program::*;
use common::target::*;
use common::test_dir::*;
//------------------------------------------
const USAGE: &str = "cache_check 0.9.0
USAGE:
cache_check [FLAGS] <INPUT>
FLAGS:
--auto-repair Auto repair trivial issues.
--ignore-non-fatal-errors Only return a non-zero exit code if a fatal error is found.
-q, --quiet Suppress output messages, return only exit code.
--super-block-only Only check the superblock.
--skip-discards Don't check the discard bitset
--skip-hints Don't check the hint array
-h, --help Prints help information
-V, --version Prints version information
ARGS:
<INPUT> Specify the input device to check";
//------------------------------------------
struct CacheCheck;
impl<'a> Program<'a> for CacheCheck {
fn name() -> &'a str {
"cache_check"
}
fn cmd<I>(args: I) -> Command
where
I: IntoIterator,
I::Item: Into<std::ffi::OsString>,
{
cache_check_cmd(args)
}
fn usage() -> &'a str {
USAGE
}
fn arg_type() -> ArgType {
ArgType::InputArg
}
fn bad_option_hint(option: &str) -> String {
msg::bad_option_hint(option)
}
}
impl<'a> InputProgram<'a> for CacheCheck {
fn mk_valid_input(td: &mut TestDir) -> Result<std::path::PathBuf> {
mk_valid_md(td)
}
fn file_not_found() -> &'a str {
msg::FILE_NOT_FOUND
}
fn missing_input_arg() -> &'a str {
msg::MISSING_INPUT_ARG
}
fn corrupted_input() -> &'a str {
msg::BAD_SUPERBLOCK
}
}
2021-08-30 21:49:44 +05:30
impl<'a> MetadataReader<'a> for CacheCheck {}
//------------------------------------------
test_accepts_help!(CacheCheck);
test_accepts_version!(CacheCheck);
test_rejects_bad_option!(CacheCheck);
test_missing_input_arg!(CacheCheck);
test_input_file_not_found!(CacheCheck);
test_input_cannot_be_a_directory!(CacheCheck);
test_unreadable_input_file!(CacheCheck);
test_help_message_for_tiny_input_file!(CacheCheck);
test_spot_xml_data!(CacheCheck);
test_corrupted_input_data!(CacheCheck);
//------------------------------------------
#[test]
fn failing_q() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let output = run_fail_raw(cache_check_cmd(args!["-q", &md]))?;
assert_eq!(output.stdout.len(), 0);
eprintln!(
"stderr = '{}'",
std::str::from_utf8(&output.stderr).unwrap()
);
assert_eq!(output.stderr.len(), 0);
Ok(())
}
2021-05-04 13:40:20 +05:30
#[test]
fn failing_quiet() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let output = run_fail_raw(cache_check_cmd(args!["--quiet", &md]))?;
assert_eq!(output.stdout.len(), 0);
assert_eq!(output.stderr.len(), 0);
Ok(())
}
2021-09-10 13:53:53 +05:30
#[test]
fn valid_metadata_passes() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
run_ok(cache_check_cmd(args![&md]))?;
2021-09-10 13:53:53 +05:30
Ok(())
}
// FIXME: put back in, I don't want to add the --debug- arg to the
// tool again, so we should have a little library function for tweaking
// metadata version.
/*
2021-09-10 13:53:53 +05:30
#[test]
fn bad_metadata_version() -> Result<()> {
let mut td = TestDir::new()?;
let xml = mk_valid_xml(&mut td)?;
let md = mk_zeroed_md(&mut td)?;
run_ok(
cache_restore_cmd(
2021-09-10 13:53:53 +05:30
args![
"-i",
&xml,
"-o",
&md,
"--debug-override-metadata-version",
"12345"
],
))?;
run_fail(cache_check_cmd(args![&md]))?;
2021-09-10 13:53:53 +05:30
Ok(())
}
*/