[tests] Do not perform Path to str conversion for compatibility

This commit is contained in:
Ming-Hung Tsai 2021-07-21 02:11:46 +08:00
parent 16190f0f9a
commit 222b4f0902
13 changed files with 131 additions and 196 deletions

View File

@ -90,7 +90,7 @@ test_corrupted_input_data!(CacheCheck);
fn failing_q() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let output = run_fail_raw(CACHE_CHECK, &["-q", md.to_str().unwrap()])?;
let output = run_fail_raw(CACHE_CHECK, args!["-q", &md])?;
assert_eq!(output.stdout.len(), 0);
assert_eq!(output.stderr.len(), 0);
Ok(())
@ -100,7 +100,7 @@ fn failing_q() -> Result<()> {
fn failing_quiet() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let output = run_fail_raw(CACHE_CHECK, &["--quiet", md.to_str().unwrap()])?;
let output = run_fail_raw(CACHE_CHECK, args!["--quiet", &md])?;
assert_eq!(output.stdout.len(), 0);
assert_eq!(output.stderr.len(), 0);
Ok(())

View File

@ -2,6 +2,7 @@ use anyhow::Result;
use thinp::version::tools_version;
use crate::args;
use crate::common::process::*;
use crate::common::program::*;
@ -12,7 +13,7 @@ pub fn test_help_short<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let stdout = run_ok(P::path(), &["-h"])?;
let stdout = run_ok(P::path(), args!["-h"])?;
assert_eq!(stdout, P::usage());
Ok(())
}
@ -21,7 +22,7 @@ pub fn test_help_long<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let stdout = run_ok(P::path(), &["--help"])?;
let stdout = run_ok(P::path(), args!["--help"])?;
assert_eq!(stdout, P::usage());
Ok(())
}
@ -48,7 +49,7 @@ pub fn test_version_short<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let stdout = run_ok(P::path(), &["-V"])?;
let stdout = run_ok(P::path(), args!["-V"])?;
assert!(stdout.contains(tools_version()));
Ok(())
}
@ -57,7 +58,7 @@ pub fn test_version_long<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let stdout = run_ok(P::path(), &["--version"])?;
let stdout = run_ok(P::path(), args!["--version"])?;
assert!(stdout.contains(tools_version()));
Ok(())
}
@ -84,7 +85,7 @@ where
P: Program<'a>,
{
let option = "--hedgehogs-only";
let stderr = run_fail(P::path(), &[option])?;
let stderr = run_fail(P::path(), args![option])?;
assert!(stderr.contains(&P::bad_option_hint(option)));
Ok(())
}

View File

@ -1,6 +1,9 @@
use anyhow::Result;
use std::ffi::OsStr;
use thinp::file_utils;
use crate::args;
use crate::common::fixture::*;
use crate::common::process::*;
use crate::common::program::*;
@ -10,38 +13,38 @@ use crate::common::thin_xml_generator::{write_xml, FragmentedS};
//------------------------------------------
// wrappers
type ArgsBuilder = fn(&mut TestDir, &str, &dyn Fn(&[&str]) -> Result<()>) -> Result<()>;
type ArgsBuilder = fn(&mut TestDir, &OsStr, &dyn Fn(&[&OsStr]) -> Result<()>) -> Result<()>;
fn with_output_md_untouched(
td: &mut TestDir,
input: &str,
thunk: &dyn Fn(&[&str]) -> Result<()>,
input: &OsStr,
thunk: &dyn Fn(&[&OsStr]) -> Result<()>,
) -> Result<()> {
let output = mk_zeroed_md(td)?;
ensure_untouched(&output, || {
let args = ["-i", input, "-o", output.to_str().unwrap()];
let args = args!["-i", input, "-o", &output];
thunk(&args)
})
}
fn with_output_superblock_zeroed(
td: &mut TestDir,
input: &str,
thunk: &dyn Fn(&[&str]) -> Result<()>,
input: &OsStr,
thunk: &dyn Fn(&[&OsStr]) -> Result<()>,
) -> Result<()> {
let output = mk_zeroed_md(td)?;
ensure_superblock_zeroed(&output, || {
let args = ["-i", input, "-o", output.to_str().unwrap()];
let args = args!["-i", input, "-o", &output];
thunk(&args)
})
}
fn input_arg_only(
_td: &mut TestDir,
input: &str,
thunk: &dyn Fn(&[&str]) -> Result<()>,
input: &OsStr,
thunk: &dyn Fn(&[&OsStr]) -> Result<()>,
) -> Result<()> {
let args = [input];
let args = args![input];
thunk(&args)
}
@ -82,7 +85,7 @@ where
let mut td = TestDir::new()?;
let output = mk_zeroed_md(&mut td)?;
ensure_untouched(&output, || {
let args = ["-o", output.to_str().unwrap()];
let args = args!["-o", &output];
let stderr = run_fail(P::path(), &args)?;
assert!(stderr.contains(P::missing_input_arg()));
Ok(())
@ -106,7 +109,7 @@ where
let mut td = TestDir::new()?;
let wrapper = build_args_fn(P::arg_type())?;
wrapper(&mut td, "no-such-file", &|args: &[&str]| {
wrapper(&mut td, "no-such-file".as_ref(), &|args: &[&OsStr]| {
let stderr = run_fail(P::path(), args)?;
assert!(stderr.contains(P::file_not_found()));
Ok(())
@ -130,7 +133,7 @@ where
let mut td = TestDir::new()?;
let wrapper = build_args_fn(P::arg_type())?;
wrapper(&mut td, "/tmp", &|args: &[&str]| {
wrapper(&mut td, "/tmp".as_ref(), &|args: &[&OsStr]| {
let stderr = run_fail(P::path(), args)?;
assert!(stderr.contains("Not a block device or regular file"));
Ok(())
@ -158,7 +161,7 @@ where
duct::cmd!("chmod", "-r", &input).run()?;
let wrapper = build_args_fn(P::arg_type())?;
wrapper(&mut td, input.to_str().unwrap(), &|args: &[&str]| {
wrapper(&mut td, input.as_ref(), &|args: &[&OsStr]| {
let stderr = run_fail(P::path(), args)?;
assert!(stderr.contains("Permission denied"));
Ok(())
@ -188,7 +191,7 @@ where
file_utils::create_sized_file(&input, 1024)?;
let wrapper = build_args_fn(P::arg_type())?;
wrapper(&mut td, input.to_str().unwrap(), &|args: &[&str]| {
wrapper(&mut td, input.as_ref(), &|args: &[&OsStr]| {
let stderr = run_fail(P::path(), args)?;
assert!(stderr.contains("Metadata device/file too small. Is this binary metadata?"));
Ok(())
@ -217,7 +220,7 @@ where
write_xml(&input, &mut gen)?;
let wrapper = build_args_fn(P::arg_type())?;
wrapper(&mut td, input.to_str().unwrap(), &|args: &[&str]| {
wrapper(&mut td, input.as_ref(), &|args: &[&OsStr]| {
let stderr = run_fail(P::path(), args)?;
eprintln!("{}", stderr);
let msg = format!(
@ -250,7 +253,7 @@ where
ArgType::InputArg => input_arg_only,
ArgType::IoOptions => with_output_superblock_zeroed,
};
wrapper(&mut td, input.to_str().unwrap(), &|args: &[&str]| {
wrapper(&mut td, input.as_ref(), &|args: &[&OsStr]| {
let stderr = run_fail(P::path(), args)?;
assert!(stderr.contains(P::corrupted_input()));
Ok(())

View File

@ -2,6 +2,7 @@ use anyhow::Result;
use thinp::file_utils;
use crate::args;
use crate::common::process::*;
use crate::common::program::*;
use crate::common::test_dir::*;
@ -15,7 +16,7 @@ where
{
let mut td = TestDir::new()?;
let input = P::mk_valid_input(&mut td)?;
let stderr = run_fail(P::path(), &["-i", input.to_str().unwrap()])?;
let stderr = run_fail(P::path(), args!["-i", &input])?;
assert!(stderr.contains(P::missing_output_arg()));
Ok(())
}
@ -36,10 +37,7 @@ where
{
let mut td = TestDir::new()?;
let input = P::mk_valid_input(&mut td)?;
let stderr = run_fail(
P::path(),
&["-i", input.to_str().unwrap(), "-o", "no-such-file"],
)?;
let stderr = run_fail(P::path(), args!["-i", &input, "-o", "no-such-file"])?;
assert!(stderr.contains(<P as OutputProgram>::file_not_found()));
Ok(())
}
@ -60,7 +58,7 @@ where
{
let mut td = TestDir::new()?;
let input = P::mk_valid_input(&mut td)?;
let stderr = run_fail(P::path(), &["-i", input.to_str().unwrap(), "-o", "/tmp"])?;
let stderr = run_fail(P::path(), args!["-i", &input, "-o", "/tmp"])?;
assert!(stderr.contains("Not a block device or regular file"));
Ok(())
}
@ -86,15 +84,7 @@ where
let _file = file_utils::create_sized_file(&output, 4096);
duct::cmd!("chmod", "-w", &output).run()?;
let stderr = run_fail(
P::path(),
&[
"-i",
input.to_str().unwrap(),
"-o",
output.to_str().unwrap(),
],
)?;
let stderr = run_fail(P::path(), args!["-i", &input, "-o", &output])?;
assert!(stderr.contains("Permission denied"));
Ok(())
}
@ -123,15 +113,7 @@ where
let output = td.mk_path("meta.bin");
let _file = file_utils::create_sized_file(&output, 4096);
let stderr = run_fail(
P::path(),
&[
"-i",
input.to_str().unwrap(),
"-o",
output.to_str().unwrap(),
],
)?;
let stderr = run_fail(P::path(), args!["-i", &input, "-o", &output])?;
assert!(stderr.contains("Output file too small"));
Ok(())
}

View File

@ -3,6 +3,17 @@ use std::ffi::{OsStr, OsString};
//------------------------------------------
#[macro_export]
macro_rules! args {
( $( $arg: expr ),* ) => {
{
use std::ffi::OsStr;
let args = [$( OsStr::new($arg) ),*];
args
}
};
}
// Returns stdout. The command must return zero.
pub fn run_ok<S, I>(program: S, args: I) -> Result<String>
where

View File

@ -4,6 +4,7 @@ use std::path::PathBuf;
use thinp::file_utils;
use thinp::io_engine::*;
use crate::args;
use crate::common::fixture::*;
use crate::common::process::*;
use crate::common::target::*;
@ -27,7 +28,7 @@ pub fn mk_valid_md(td: &mut TestDir) -> Result<PathBuf> {
write_xml(&xml, &mut gen)?;
let _file = file_utils::create_sized_file(&md, 4096 * 4096);
let args = ["-i", xml.to_str().unwrap(), "-o", md.to_str().unwrap()];
let args = args!["-i", &xml, "-o", &md];
run_ok(THIN_RESTORE, &args)?;
Ok(md)
@ -38,27 +39,21 @@ pub fn mk_valid_md(td: &mut TestDir) -> Result<PathBuf> {
// FIXME: replace mk_valid_md with this?
pub fn prep_metadata(td: &mut TestDir) -> Result<PathBuf> {
let md = mk_zeroed_md(td)?;
let args = [
"-o",
md.to_str().unwrap(),
"--format",
"--nr-data-blocks",
"102400",
];
let args = args!["-o", &md, "--format", "--nr-data-blocks", "102400"];
run_ok(THIN_GENERATE_METADATA, &args)?;
// Create a 2GB device
let args = ["-o", md.to_str().unwrap(), "--create-thin", "1"];
let args = args!["-o", &md, "--create-thin", "1"];
run_ok(THIN_GENERATE_METADATA, &args)?;
let args = [
let args = args![
"-o",
md.to_str().unwrap(),
&md,
"--dev-id",
"1",
"--size",
"2097152",
"--rw=randwrite",
"--seq-nr=16",
"--seq-nr=16"
];
run_ok(THIN_GENERATE_MAPPINGS, &args)?;
@ -66,20 +61,14 @@ pub fn prep_metadata(td: &mut TestDir) -> Result<PathBuf> {
let mut snap_id = 2;
for _i in 0..10 {
// take a snapshot
let args = [
"-o",
md.to_str().unwrap(),
"--create-snap",
&snap_id.to_string(),
"--origin",
"1",
];
let snap_id_str = snap_id.to_string();
let args = args!["-o", &md, "--create-snap", &snap_id_str, "--origin", "1"];
run_ok(THIN_GENERATE_METADATA, &args)?;
// partially overwrite the origin (64MB)
let args = [
let args = args![
"-o",
md.to_str().unwrap(),
&md,
"--dev-id",
"1",
"--size",
@ -87,7 +76,7 @@ pub fn prep_metadata(td: &mut TestDir) -> Result<PathBuf> {
"--io-size",
"131072",
"--rw=randwrite",
"--seq-nr=16",
"--seq-nr=16"
];
run_ok(THIN_GENERATE_MAPPINGS, &args)?;
snap_id += 1;
@ -97,7 +86,7 @@ pub fn prep_metadata(td: &mut TestDir) -> Result<PathBuf> {
}
pub fn set_needs_check(md: &PathBuf) -> Result<()> {
let args = ["-o", md.to_str().unwrap(), "--set-needs-check"];
let args = args!["-o", &md, "--set-needs-check"];
run_ok(THIN_GENERATE_METADATA, &args)?;
Ok(())
}
@ -108,16 +97,19 @@ pub fn generate_metadata_leaks(
expected: u32,
actual: u32,
) -> Result<()> {
let args = [
let nr_blocks_str = nr_blocks.to_string();
let expected_str = expected.to_string();
let actual_str = actual.to_string();
let args = args![
"-o",
md.to_str().unwrap(),
&md,
"--create-metadata-leaks",
"--nr-blocks",
&nr_blocks.to_string(),
&nr_blocks_str,
"--expected",
&expected.to_string(),
&expected_str,
"--actual",
&actual.to_string(),
&actual_str
];
run_ok(THIN_GENERATE_DAMAGE, &args)?;

View File

@ -93,8 +93,7 @@ test_corrupted_input_data!(ThinCheck);
fn accepts_flag(flag: &str) -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
run_ok(THIN_CHECK, &[flag, md_path])?;
run_ok(THIN_CHECK, args![flag, &md])?;
Ok(())
}
@ -130,9 +129,8 @@ fn accepts_auto_repair() -> Result<()> {
fn accepts_quiet() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
let output = run_ok_raw(THIN_CHECK, &["--quiet", md_path])?;
let output = run_ok_raw(THIN_CHECK, args!["--quiet", &md])?;
assert_eq!(output.stdout.len(), 0);
assert_eq!(output.stderr.len(), 0);
Ok(())
@ -145,8 +143,7 @@ fn accepts_quiet() -> Result<()> {
fn detects_corrupt_superblock_with_superblock_only() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let md_path = md.to_str().unwrap();
let _stderr = run_fail(THIN_CHECK, &["--super-block-only", md_path])?;
let _stderr = run_fail(THIN_CHECK, args!["--super-block-only", &md])?;
Ok(())
}
@ -157,8 +154,7 @@ fn detects_corrupt_superblock_with_superblock_only() -> Result<()> {
fn prints_info_fields() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
let stdout = run_ok(THIN_CHECK, &[md_path])?;
let stdout = run_ok(THIN_CHECK, args![&md])?;
assert!(stdout.contains("TRANSACTION_ID="));
assert!(stdout.contains("METADATA_FREE_BLOCKS="));
Ok(())
@ -171,20 +167,19 @@ fn prints_info_fields() -> Result<()> {
fn auto_repair_incompatible_opts() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
run_fail(THIN_CHECK, &["--auto-repair", "-m", md_path])?;
run_fail(THIN_CHECK, args!["--auto-repair", "-m", &md])?;
run_fail(
THIN_CHECK,
&["--auto-repair", "--override-mapping-root", "123", md_path],
args!["--auto-repair", "--override-mapping-root", "123", &md],
)?;
run_fail(
THIN_CHECK,
&["--auto-repair", "--super-block-only", md_path],
args!["--auto-repair", "--super-block-only", &md],
)?;
run_fail(THIN_CHECK, &["--auto-repair", "--skip-mappings", md_path])?;
run_fail(THIN_CHECK, args!["--auto-repair", "--skip-mappings", &md])?;
run_fail(
THIN_CHECK,
&["--auto-repair", "--ignore-non-fatal-errors", md_path],
args!["--auto-repair", "--ignore-non-fatal-errors", &md],
)?;
Ok(())
}
@ -193,28 +188,23 @@ fn auto_repair_incompatible_opts() -> Result<()> {
fn clear_needs_check_incompatible_opts() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
run_fail(THIN_CHECK, &["--clear-needs-check-flag", "-m", md_path])?;
run_fail(THIN_CHECK, args!["--clear-needs-check-flag", "-m", &md])?;
run_fail(
THIN_CHECK,
&[
args![
"--clear-needs-check-flag",
"--override-mapping-root",
"123",
md_path,
&md
],
)?;
run_fail(
THIN_CHECK,
&["--clear-needs-check-flag", "--super-block-only", md_path],
args!["--clear-needs-check-flag", "--super-block-only", &md],
)?;
run_fail(
THIN_CHECK,
&[
"--clear-needs-check-flag",
"--ignore-non-fatal-errors",
md_path,
],
args!["--clear-needs-check-flag", "--ignore-non-fatal-errors", &md],
)?;
Ok(())
}
@ -226,12 +216,11 @@ fn clear_needs_check_incompatible_opts() -> Result<()> {
fn clear_needs_check() -> Result<()> {
let mut td = TestDir::new()?;
let md = prep_metadata(&mut td)?;
let md_path = md.to_str().unwrap();
set_needs_check(&md)?;
assert!(get_needs_check(&md)?);
run_ok(THIN_CHECK, &["--clear-needs-check-flag", md_path])?;
run_ok(THIN_CHECK, args!["--clear-needs-check-flag", &md])?;
assert!(!get_needs_check(&md)?);
Ok(())
}
@ -240,11 +229,10 @@ fn clear_needs_check() -> Result<()> {
fn no_clear_needs_check_if_error() -> Result<()> {
let mut td = TestDir::new()?;
let md = prep_metadata(&mut td)?;
let md_path = md.to_str().unwrap();
set_needs_check(&md)?;
generate_metadata_leaks(&md, 1, 0, 1)?;
run_fail(THIN_CHECK, &["--clear-needs-check-flag", md_path])?;
run_fail(THIN_CHECK, args!["--clear-needs-check-flag", &md])?;
assert!(get_needs_check(&md)?);
Ok(())
}
@ -253,7 +241,6 @@ fn no_clear_needs_check_if_error() -> Result<()> {
fn clear_needs_check_if_skip_mappings() -> Result<()> {
let mut td = TestDir::new()?;
let md = prep_metadata(&mut td)?;
let md_path = md.to_str().unwrap();
set_needs_check(&md)?;
generate_metadata_leaks(&md, 1, 0, 1)?;
@ -261,7 +248,7 @@ fn clear_needs_check_if_skip_mappings() -> Result<()> {
assert!(get_needs_check(&md)?);
run_ok(
THIN_CHECK,
&["--clear-needs-check-flag", "--skip-mappings", md_path],
args!["--clear-needs-check-flag", "--skip-mappings", &md],
)?;
assert!(!get_needs_check(&md)?);
Ok(())
@ -274,10 +261,9 @@ fn clear_needs_check_if_skip_mappings() -> Result<()> {
fn metadata_leaks_are_non_fatal() -> Result<()> {
let mut td = TestDir::new()?;
let md = prep_metadata(&mut td)?;
let md_path = md.to_str().unwrap();
generate_metadata_leaks(&md, 1, 0, 1)?;
run_fail(THIN_CHECK, &[md_path])?;
run_ok(THIN_CHECK, &["--ignore-non-fatal-errors", md_path])?;
run_fail(THIN_CHECK, args![&md])?;
run_ok(THIN_CHECK, args!["--ignore-non-fatal-errors", &md])?;
Ok(())
}
@ -285,11 +271,10 @@ fn metadata_leaks_are_non_fatal() -> Result<()> {
fn fatal_errors_cant_be_ignored() -> Result<()> {
let mut td = TestDir::new()?;
let md = prep_metadata(&mut td)?;
let md_path = md.to_str().unwrap();
generate_metadata_leaks(&md, 1, 1, 0)?;
ensure_untouched(&md, || {
run_fail(THIN_CHECK, &["--ignore-non-fatal-errors", md_path])?;
run_fail(THIN_CHECK, args!["--ignore-non-fatal-errors", &md])?;
Ok(())
})
}
@ -301,18 +286,17 @@ fn fatal_errors_cant_be_ignored() -> Result<()> {
fn auto_repair() -> Result<()> {
let mut td = TestDir::new()?;
let md = prep_metadata(&mut td)?;
let md_path = md.to_str().unwrap();
// auto-repair should have no effect on good metadata.
ensure_untouched(&md, || {
run_ok(THIN_CHECK, &["--auto-repair", md_path])?;
run_ok(THIN_CHECK, args!["--auto-repair", &md])?;
Ok(())
})?;
generate_metadata_leaks(&md, 16, 0, 1)?;
run_fail(THIN_CHECK, &[md_path])?;
run_ok(THIN_CHECK, &["--auto-repair", md_path])?;
run_ok(THIN_CHECK, &[md_path])?;
run_fail(THIN_CHECK, args![&md])?;
run_ok(THIN_CHECK, args!["--auto-repair", &md])?;
run_ok(THIN_CHECK, args![&md])?;
Ok(())
}
@ -320,11 +304,10 @@ fn auto_repair() -> Result<()> {
fn auto_repair_has_limits() -> Result<()> {
let mut td = TestDir::new()?;
let md = prep_metadata(&mut td)?;
let md_path = md.to_str().unwrap();
generate_metadata_leaks(&md, 16, 1, 0)?;
ensure_untouched(&md, || {
run_fail(THIN_CHECK, &["--auto-repair", md_path])?;
run_fail(THIN_CHECK, args!["--auto-repair", &md])?;
Ok(())
})?;
Ok(())
@ -334,10 +317,9 @@ fn auto_repair_has_limits() -> Result<()> {
fn auto_repair_clears_needs_check() -> Result<()> {
let mut td = TestDir::new()?;
let md = prep_metadata(&mut td)?;
let md_path = md.to_str().unwrap();
set_needs_check(&md)?;
run_ok(THIN_CHECK, &["--auto-repair", md_path])?;
run_ok(THIN_CHECK, args!["--auto-repair", &md])?;
assert!(!get_needs_check(&md)?);
Ok(())
}

View File

@ -58,7 +58,7 @@ test_rejects_bad_option!(ThinDelta);
fn snap1_unspecified() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let stderr = run_fail(THIN_DELTA, &["--snap2", "45", md.to_str().unwrap()])?;
let stderr = run_fail(THIN_DELTA, args!["--snap2", "45", &md])?;
assert!(stderr.contains("--snap1 or --root1 not specified"));
Ok(())
}
@ -67,14 +67,14 @@ fn snap1_unspecified() -> Result<()> {
fn snap2_unspecified() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let stderr = run_fail(THIN_DELTA, &["--snap1", "45", md.to_str().unwrap()])?;
let stderr = run_fail(THIN_DELTA, args!["--snap1", "45", &md])?;
assert!(stderr.contains("--snap2 or --root2 not specified"));
Ok(())
}
#[test]
fn dev_unspecified() -> Result<()> {
let stderr = run_fail(THIN_DELTA, &["--snap1", "45", "--snap2", "46"])?;
let stderr = run_fail(THIN_DELTA, args!["--snap1", "45", "--snap2", "46"])?;
// TODO: replace with msg::MISSING_INPUT_ARG once the rust version is ready
assert!(stderr.contains("No input file provided"));
Ok(())

View File

@ -90,8 +90,7 @@ fn dump_restore_cycle() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
let output = run_ok_raw(THIN_DUMP, &[md_path])?;
let output = run_ok_raw(THIN_DUMP, args![&md])?;
let xml = td.mk_path("meta.xml");
let mut file = OpenOptions::new()
@ -103,11 +102,9 @@ fn dump_restore_cycle() -> Result<()> {
drop(file);
let md2 = mk_zeroed_md(&mut td)?;
let md2_path = md2.to_str().unwrap();
let xml_path = xml.to_str().unwrap();
run_ok(THIN_RESTORE, &["-i", xml_path, "-o", md2_path])?;
run_ok(THIN_RESTORE, args!["-i", &xml, "-o", &md2])?;
let output2 = run_ok_raw(THIN_DUMP, &[md2_path])?;
let output2 = run_ok_raw(THIN_DUMP, args![&md2])?;
assert_eq!(output.stdout, output2.stdout);
Ok(())
@ -121,8 +118,7 @@ fn no_stderr() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
let output = run_ok_raw(THIN_DUMP, &[md_path])?;
let output = run_ok_raw(THIN_DUMP, args![&md])?;
assert_eq!(output.stderr.len(), 0);
Ok(())
@ -135,8 +131,7 @@ fn no_stderr() -> Result<()> {
fn override_something(flag: &str, value: &str, pattern: &str) -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
let output = run_ok_raw(THIN_DUMP, &[md_path, flag, value])?;
let output = run_ok_raw(THIN_DUMP, args![&md, flag, value])?;
assert_eq!(output.stderr.len(), 0);
assert!(from_utf8(&output.stdout[0..])?.contains(pattern));
@ -165,23 +160,23 @@ fn repair_superblock() -> Result<()> {
let md = mk_valid_md(&mut td)?;
let before = run_ok_raw(
THIN_DUMP,
&[
args![
"--transaction-id=5",
"--data-block-size=128",
"--nr-data-blocks=4096000",
md.to_str().unwrap(),
&md
],
)?;
damage_superblock(&md)?;
let after = run_ok_raw(
THIN_DUMP,
&[
args![
"--repair",
"--transaction-id=5",
"--data-block-size=128",
"--nr-data-blocks=4096000",
md.to_str().unwrap(),
&md
],
)?;
assert_eq!(after.stderr.len(), 0);
@ -201,11 +196,11 @@ fn missing_transaction_id() -> Result<()> {
damage_superblock(&md)?;
let stderr = run_fail(
THIN_DUMP,
&[
args![
"--repair",
"--data-block-size=128",
"--nr-data-blocks=4096000",
md.to_str().unwrap(),
&md
],
)?;
assert!(stderr.contains("transaction id"));
@ -219,11 +214,11 @@ fn missing_data_block_size() -> Result<()> {
damage_superblock(&md)?;
let stderr = run_fail(
THIN_DUMP,
&[
args![
"--repair",
"--transaction-id=5",
"--nr-data-blocks=4096000",
md.to_str().unwrap(),
&md
],
)?;
assert!(stderr.contains("data block size"));
@ -237,11 +232,11 @@ fn missing_nr_data_blocks() -> Result<()> {
damage_superblock(&md)?;
let stderr = run_fail(
THIN_DUMP,
&[
args![
"--repair",
"--transaction-id=5",
"--data-block-size=128",
md.to_str().unwrap(),
&md
],
)?;
assert!(stderr.contains("nr data blocks"));

View File

@ -106,17 +106,14 @@ fn end_to_end() -> Result<()> {
let mut td = TestDir::new()?;
let md_in = mk_valid_md(&mut td)?;
let md_out = mk_zeroed_md(&mut td)?;
run_ok(
THIN_METADATA_PACK,
&["-i", md_in.to_str().unwrap(), "-o", "meta.pack"],
)?;
run_ok(THIN_METADATA_PACK, args!["-i", &md_in, "-o", "meta.pack"])?;
run_ok(
THIN_METADATA_UNPACK,
&["-i", "meta.pack", "-o", md_out.to_str().unwrap()],
args!["-i", "meta.pack", "-o", &md_out],
)?;
let dump1 = run_ok(THIN_DUMP, &[md_in.to_str().unwrap()])?;
let dump2 = run_ok(THIN_DUMP, &[md_out.to_str().unwrap()])?;
let dump1 = run_ok(THIN_DUMP, args![&md_in])?;
let dump2 = run_ok(THIN_DUMP, args![&md_out])?;
assert_eq!(dump1, dump2);
Ok(())
}

View File

@ -100,9 +100,7 @@ fn dont_repair_xml() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_zeroed_md(&mut td)?;
let xml = mk_valid_xml(&mut td)?;
let xml_path = xml.to_str().unwrap();
let md_path = md.to_str().unwrap();
run_fail(THIN_REPAIR, &["-i", xml_path, "-o", md_path])?;
run_fail(THIN_REPAIR, args!["-i", &xml, "-o", &md])?;
Ok(())
}
@ -114,12 +112,9 @@ fn override_thing(flag: &str, val: &str, pattern: &str) -> Result<()> {
let mut td = TestDir::new()?;
let md1 = mk_valid_md(&mut td)?;
let md2 = mk_zeroed_md(&mut td)?;
let md1_path = md1.to_str().unwrap();
let md2_path = md2.to_str().unwrap();
let output = run_ok_raw(THIN_REPAIR, &[flag, val, "-i", md1_path, "-o", md2_path])?;
let output = run_ok_raw(THIN_REPAIR, args![flag, val, "-i", &md1, "-o", &md2])?;
assert_eq!(output.stderr.len(), 0);
let md2_path = md2.to_str().unwrap();
let output = run_ok(THIN_DUMP, &[md2_path])?;
let output = run_ok(THIN_DUMP, args![&md2])?;
assert!(output.contains(pattern));
Ok(())
}
@ -144,33 +139,31 @@ fn override_nr_data_blocks() -> Result<()> {
fn superblock_succeeds() -> Result<()> {
let mut td = TestDir::new()?;
let md1 = mk_valid_md(&mut td)?;
let md1_path = md1.to_str().unwrap();
let original = run_ok_raw(
THIN_DUMP,
&[
args![
"--transaction-id=5",
"--data-block-size=128",
"--nr-data-blocks=4096000",
md1_path,
&md1
],
)?;
assert_eq!(original.stderr.len(), 0);
damage_superblock(&md1)?;
let md2 = mk_zeroed_md(&mut td)?;
let md2_path = md2.to_str().unwrap();
run_ok(
THIN_REPAIR,
&[
args![
"--transaction-id=5",
"--data-block-size=128",
"--nr-data-blocks=4096000",
"-i",
md1_path,
&md1,
"-o",
md2_path,
&md2
],
)?;
let repaired = run_ok_raw(THIN_DUMP, &[md2_path])?;
let repaired = run_ok_raw(THIN_DUMP, args![&md2])?;
assert_eq!(repaired.stderr.len(), 0);
assert_eq!(original.stdout, repaired.stdout);
Ok(())
@ -185,17 +178,7 @@ fn missing_thing(flag1: &str, flag2: &str, pattern: &str) -> Result<()> {
let md1 = mk_valid_md(&mut td)?;
damage_superblock(&md1)?;
let md2 = mk_zeroed_md(&mut td)?;
let stderr = run_fail(
THIN_REPAIR,
&[
flag1,
flag2,
"-i",
md1.to_str().unwrap(),
"-o",
md2.to_str().unwrap(),
],
)?;
let stderr = run_fail(THIN_REPAIR, args![flag1, flag2, "-i", &md1, "-o", &md2])?;
assert!(stderr.contains(pattern));
Ok(())
}

View File

@ -102,9 +102,7 @@ fn quiet_flag(flag: &str) -> Result<()> {
let xml = mk_valid_xml(&mut td)?;
let md = mk_zeroed_md(&mut td)?;
let xml_path = xml.to_str().unwrap();
let md_path = md.to_str().unwrap();
let output = run_ok_raw(THIN_RESTORE, &["-i", xml_path, "-o", md_path, flag])?;
let output = run_ok_raw(THIN_RESTORE, args!["-i", &xml, "-o", &md, flag])?;
assert_eq!(output.stdout.len(), 0);
assert_eq!(output.stderr.len(), 0);
@ -130,11 +128,9 @@ fn override_something(flag: &str, value: &str, pattern: &str) -> Result<()> {
let xml = mk_valid_xml(&mut td)?;
let md = mk_zeroed_md(&mut td)?;
let xml_path = xml.to_str().unwrap();
let md_path = md.to_str().unwrap();
run_ok(THIN_RESTORE, &["-i", xml_path, "-o", md_path, flag, value])?;
run_ok(THIN_RESTORE, args!["-i", &xml, "-o", &md, flag, value])?;
let output = run_ok(THIN_DUMP, &[md_path])?;
let output = run_ok(THIN_DUMP, args![&md])?;
assert!(output.contains(pattern));
Ok(())
}

View File

@ -58,8 +58,7 @@ test_rejects_bad_option!(ThinRmap);
fn valid_region_format_should_pass() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
let md_path = md.to_str().unwrap();
run_ok(THIN_RMAP, &["--region", "23..7890", md_path])?;
run_ok(THIN_RMAP, args!["--region", "23..7890", &md])?;
Ok(())
}
@ -78,7 +77,7 @@ fn invalid_regions_should_fail() -> Result<()> {
for r in &invalid_regions {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
run_fail(THIN_RMAP, &[&r.to_string(), md.to_str().unwrap()])?;
run_fail(THIN_RMAP, args![r, &md])?;
}
Ok(())
}
@ -89,13 +88,7 @@ fn multiple_regions_should_pass() -> Result<()> {
let md = mk_valid_md(&mut td)?;
run_ok(
THIN_RMAP,
&[
"--region",
"1..23",
"--region",
"45..78",
md.to_str().unwrap(),
],
args!["--region", "1..23", "--region", "45..78", &md],
)?;
Ok(())
}
@ -104,7 +97,7 @@ fn multiple_regions_should_pass() -> Result<()> {
fn junk_input() -> Result<()> {
let mut td = TestDir::new()?;
let xml = mk_valid_xml(&mut td)?;
run_fail(THIN_RMAP, &["--region", "0..-1", xml.to_str().unwrap()])?;
run_fail(THIN_RMAP, args!["--region", "0..-1", &xml])?;
Ok(())
}