[all] Apply cargo fmt, and fix clippy warnings

This commit is contained in:
Ming-Hung Tsai
2021-10-19 22:35:06 +08:00
parent 13aeefcdeb
commit c8a1da1df9
39 changed files with 125 additions and 151 deletions

View File

@@ -13,8 +13,7 @@ use common::test_dir::*;
//------------------------------------------
const USAGE: &str =
"cache_check 0.9.0
const USAGE: &str = "cache_check 0.9.0
USAGE:
cache_check [FLAGS] <INPUT>
@@ -105,7 +104,10 @@ fn failing_q() -> Result<()> {
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());
eprintln!(
"stderr = '{}'",
std::str::from_utf8(&output.stderr).unwrap()
);
assert_eq!(output.stderr.len(), 0);
Ok(())
}
@@ -128,7 +130,6 @@ fn valid_metadata_passes() -> Result<()> {
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.

View File

@@ -12,8 +12,7 @@ use common::test_dir::*;
//------------------------------------------
const USAGE: &str =
"cache_repair 0.9.0
const USAGE: &str = "cache_repair 0.9.0
Repair binary cache metadata, and write it to a different device or file
USAGE:

View File

@@ -14,8 +14,7 @@ use common::test_dir::*;
//------------------------------------------
const USAGE: &str =
"cache_restore 0.9.0
const USAGE: &str = "cache_restore 0.9.0
Convert XML format metadata to binary.
USAGE:

View File

@@ -64,7 +64,7 @@ impl XmlGen for CacheGen {
let mut cblocks = (0..self.nr_cache_blocks).collect::<Vec<u32>>();
cblocks.shuffle(&mut rand::thread_rng());
cblocks.truncate(nr_resident as usize);
cblocks.sort();
cblocks.sort_unstable();
v.mappings_b()?;
{

View File

@@ -222,9 +222,8 @@ where
let wrapper = build_args_fn(P::arg_type())?;
wrapper(&mut td, input.as_ref(), &|args: &[&OsStr]| {
let stderr = run_fail(P::cmd(args))?;
let msg = format!(
"This looks like XML. This tool only checks the binary metadata format.",
);
let msg =
"This looks like XML. This tool only checks the binary metadata format.".to_string();
assert!(stderr.contains(&msg));
Ok(())
})

View File

@@ -57,10 +57,10 @@ impl fmt::Display for Command {
fn log_output(output: &process::Output) {
use std::str::from_utf8;
if output.stdout.len() > 0 {
if !output.stdout.is_empty() {
eprintln!("stdout: \n{}<<END>>", from_utf8(&output.stdout).unwrap());
}
if output.stderr.len() > 0 {
if !output.stderr.is_empty() {
eprintln!("stderr: \n{}<<END>>", from_utf8(&output.stderr).unwrap());
}
}

View File

@@ -118,7 +118,7 @@ pub fn generate_metadata_leaks(
pub fn get_needs_check(md: &PathBuf) -> Result<bool> {
use thinp::thin::superblock::*;
let engine = SyncIoEngine::new(&md, 1, false)?;
let engine = SyncIoEngine::new(md, 1, false)?;
let sb = read_superblock(&engine, SUPERBLOCK_LOCATION)?;
Ok(sb.flags.needs_check)
}

View File

@@ -145,11 +145,11 @@ fn accepts_quiet() -> Result<()> {
let md = mk_valid_md(&mut td)?;
let output = run_ok_raw(thin_check_cmd(args!["--quiet", &md]))?;
if output.stdout.len() > 0 {
if !output.stdout.is_empty() {
eprintln!("stdout: {:?}", &std::str::from_utf8(&output.stdout));
}
if output.stderr.len() > 0 {
if !output.stderr.is_empty() {
eprintln!("stderr: {:?}", &std::str::from_utf8(&output.stderr));
}
assert_eq!(output.stdout.len(), 0);

View File

@@ -15,8 +15,7 @@ use common::thin::*;
//------------------------------------------
const USAGE: &str =
"thin_dump 0.9.0
const USAGE: &str = "thin_dump 0.9.0
Dump thin-provisioning metadata to stdout in XML format
USAGE:
@@ -178,15 +177,13 @@ fn repair_superblock() -> Result<()> {
let before = run_ok_raw(thin_dump_cmd(args![&md]))?;
damage_superblock(&md)?;
let after = run_ok_raw(thin_dump_cmd(
args![
"--repair",
"--transaction-id=1",
"--data-block-size=128",
"--nr-data-blocks=20480",
&md
],
))?;
let after = run_ok_raw(thin_dump_cmd(args![
"--repair",
"--transaction-id=1",
"--data-block-size=128",
"--nr-data-blocks=20480",
&md
]))?;
if !cfg!(feature = "rust_tests") {
assert_eq!(after.stderr.len(), 0);
}
@@ -204,15 +201,12 @@ fn missing_transaction_id() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
damage_superblock(&md)?;
let stderr = run_fail(
thin_dump_cmd(
args![
"--repair",
"--data-block-size=128",
"--nr-data-blocks=20480",
&md
],
))?;
let stderr = run_fail(thin_dump_cmd(args![
"--repair",
"--data-block-size=128",
"--nr-data-blocks=20480",
&md
]))?;
assert!(stderr.contains("transaction id"));
Ok(())
}
@@ -222,15 +216,12 @@ fn missing_data_block_size() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
damage_superblock(&md)?;
let stderr = run_fail(
thin_dump_cmd(
args![
"--repair",
"--transaction-id=1",
"--nr-data-blocks=20480",
&md
],
))?;
let stderr = run_fail(thin_dump_cmd(args![
"--repair",
"--transaction-id=1",
"--nr-data-blocks=20480",
&md
]))?;
assert!(stderr.contains("data block size"));
Ok(())
}
@@ -240,15 +231,12 @@ fn missing_nr_data_blocks() -> Result<()> {
let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?;
damage_superblock(&md)?;
let stderr = run_fail(
thin_dump_cmd(
args![
"--repair",
"--transaction-id=1",
"--data-block-size=128",
&md
],
))?;
let stderr = run_fail(thin_dump_cmd(args![
"--repair",
"--transaction-id=1",
"--data-block-size=128",
&md
]))?;
assert!(stderr.contains("nr data blocks"));
Ok(())
}

View File

@@ -106,8 +106,18 @@ 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_cmd(args!["-i", &md_in, "-o", "meta.pack"]))?;
run_ok(thin_metadata_unpack_cmd(args!["-i", "meta.pack", "-o", &md_out]))?;
run_ok(thin_metadata_pack_cmd(args![
"-i",
&md_in,
"-o",
"meta.pack"
]))?;
run_ok(thin_metadata_unpack_cmd(args![
"-i",
"meta.pack",
"-o",
&md_out
]))?;
let dump1 = run_ok(thin_dump_cmd(args![&md_in]))?;
let dump2 = run_ok(thin_dump_cmd(args![&md_out]))?;

View File

@@ -161,18 +161,15 @@ fn superblock_succeeds() -> Result<()> {
}
damage_superblock(&md1)?;
let md2 = mk_zeroed_md(&mut td)?;
run_ok(
thin_repair_cmd(
args![
"--transaction-id=1",
"--data-block-size=128",
"--nr-data-blocks=20480",
"-i",
&md1,
"-o",
&md2
],
))?;
run_ok(thin_repair_cmd(args![
"--transaction-id=1",
"--data-block-size=128",
"--nr-data-blocks=20480",
"-i",
&md1,
"-o",
&md2
]))?;
let repaired = run_ok_raw(thin_dump_cmd(args![&md2]))?;
if !cfg!(feature = "rust_tests") {
assert_eq!(repaired.stderr.len(), 0);