2020-07-31 16:42:40 +05:30
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
mod common;
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
use common::common_args::*;
|
|
|
|
use common::input_arg::*;
|
|
|
|
use common::output_option::*;
|
2020-08-07 19:00:00 +05:30
|
|
|
use common::test_dir::*;
|
2021-05-04 13:40:20 +05:30
|
|
|
use common::*;
|
2020-07-31 16:42:40 +05:30
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
const USAGE: &str = "Usage: thin_restore [options]\n\
|
|
|
|
Options:\n \
|
|
|
|
{-h|--help}\n \
|
|
|
|
{-i|--input} <input xml file>\n \
|
|
|
|
{-o|--output} <output device or file>\n \
|
|
|
|
{--transaction-id} <natural>\n \
|
|
|
|
{--data-block-size} <natural>\n \
|
|
|
|
{--nr-data-blocks} <natural>\n \
|
|
|
|
{-q|--quiet}\n \
|
|
|
|
{-V|--version}";
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
//------------------------------------------
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
test_accepts_help!(THIN_RESTORE, USAGE);
|
|
|
|
test_accepts_version!(THIN_RESTORE);
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
test_missing_input_option!(THIN_RESTORE);
|
|
|
|
test_input_file_not_found!(THIN_RESTORE, OPTION);
|
|
|
|
test_corrupted_input_data!(THIN_RESTORE, OPTION);
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
test_missing_output_option!(THIN_RESTORE, mk_valid_xml);
|
|
|
|
test_tiny_output_file!(THIN_RESTORE, mk_valid_xml);
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
//-----------------------------------------
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
// TODO: share with cache_restore, era_restore
|
2020-07-31 16:42:40 +05:30
|
|
|
|
|
|
|
fn quiet_flag(flag: &str) -> Result<()> {
|
2020-07-31 18:56:22 +05:30
|
|
|
let mut td = TestDir::new()?;
|
|
|
|
let xml = mk_valid_xml(&mut td)?;
|
|
|
|
let md = mk_zeroed_md(&mut td)?;
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
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])?;
|
2020-07-31 16:42:40 +05:30
|
|
|
|
|
|
|
assert_eq!(output.stdout.len(), 0);
|
|
|
|
assert_eq!(output.stderr.len(), 0);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn accepts_q() -> Result<()> {
|
|
|
|
quiet_flag("-q")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn accepts_quiet() -> Result<()> {
|
|
|
|
quiet_flag("--quiet")
|
|
|
|
}
|
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
//-----------------------------------------
|
|
|
|
|
|
|
|
// TODO: share with thin_dump
|
|
|
|
|
2020-07-31 16:42:40 +05:30
|
|
|
fn override_something(flag: &str, value: &str, pattern: &str) -> Result<()> {
|
2020-07-31 18:56:22 +05:30
|
|
|
let mut td = TestDir::new()?;
|
|
|
|
let xml = mk_valid_xml(&mut td)?;
|
|
|
|
let md = mk_zeroed_md(&mut td)?;
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
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])?;
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
let output = run_ok(THIN_DUMP, &[md_path])?;
|
|
|
|
assert!(output.contains(pattern));
|
2020-07-31 16:42:40 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_transaction_id() -> Result<()> {
|
|
|
|
override_something("--transaction-id", "2345", "transaction=\"2345\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_data_block_size() -> Result<()> {
|
|
|
|
override_something("--data-block-size", "8192", "data_block_size=\"8192\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_nr_data_blocks() -> Result<()> {
|
|
|
|
override_something("--nr-data-blocks", "234500", "nr_data_blocks=\"234500\"")
|
|
|
|
}
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
//-----------------------------------------
|