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::*;
|
2021-07-20 15:07:55 +05:30
|
|
|
use common::fixture::*;
|
2021-07-01 19:57:37 +05:30
|
|
|
use common::input_arg::*;
|
|
|
|
use common::output_option::*;
|
2021-07-20 15:07:55 +05:30
|
|
|
use common::process::*;
|
|
|
|
use common::program::*;
|
|
|
|
use common::target::*;
|
2020-08-07 19:00:00 +05:30
|
|
|
use common::test_dir::*;
|
2021-07-20 15:07:55 +05:30
|
|
|
use common::thin::*;
|
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-06 07:21:27 +05:30
|
|
|
struct ThinRestore;
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
impl<'a> Program<'a> for ThinRestore {
|
|
|
|
fn name() -> &'a str {
|
|
|
|
"thin_restore"
|
|
|
|
}
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-10-18 21:29:17 +05:30
|
|
|
fn cmd<I>(args: I) -> Command
|
2021-10-11 16:37:26 +05:30
|
|
|
where
|
|
|
|
I: IntoIterator,
|
|
|
|
I::Item: Into<std::ffi::OsString>,
|
|
|
|
{
|
|
|
|
thin_restore_cmd(args)
|
2021-07-06 07:21:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
fn usage() -> &'a str {
|
|
|
|
USAGE
|
|
|
|
}
|
|
|
|
|
|
|
|
fn arg_type() -> ArgType {
|
|
|
|
ArgType::IoOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bad_option_hint(option: &str) -> String {
|
|
|
|
msg::bad_option_hint(option)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> InputProgram<'a> for ThinRestore {
|
|
|
|
fn mk_valid_input(td: &mut TestDir) -> Result<std::path::PathBuf> {
|
2021-08-31 10:03:12 +05:30
|
|
|
mk_valid_xml(td)
|
2021-07-06 07:21:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
"" // we don't intent to verify error messages of XML parsing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> OutputProgram<'a> for ThinRestore {
|
|
|
|
fn missing_output_arg() -> &'a str {
|
|
|
|
msg::MISSING_OUTPUT_ARG
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-30 21:49:44 +05:30
|
|
|
impl<'a> MetadataWriter<'a> for ThinRestore {
|
|
|
|
fn file_not_found() -> &'a str {
|
|
|
|
msg::FILE_NOT_FOUND
|
|
|
|
}
|
|
|
|
}
|
2021-07-06 07:21:27 +05:30
|
|
|
|
|
|
|
//-----------------------------------------
|
|
|
|
|
|
|
|
test_accepts_help!(ThinRestore);
|
|
|
|
test_accepts_version!(ThinRestore);
|
|
|
|
|
|
|
|
test_missing_input_option!(ThinRestore);
|
|
|
|
test_input_file_not_found!(ThinRestore);
|
|
|
|
test_corrupted_input_data!(ThinRestore);
|
|
|
|
|
|
|
|
test_missing_output_option!(ThinRestore);
|
|
|
|
test_tiny_output_file!(ThinRestore);
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-08-30 21:49:44 +05:30
|
|
|
test_unwritable_output_file!(ThinRestore);
|
|
|
|
|
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-10-11 16:37:26 +05:30
|
|
|
let output = run_ok_raw(thin_restore_cmd(args!["-i", &xml, "-o", &md, 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
|
2021-09-10 08:03:53 +05:30
|
|
|
#[cfg(not(feature = "rust_tests"))]
|
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-10-11 16:37:26 +05:30
|
|
|
run_ok(thin_restore_cmd(args!["-i", &xml, "-o", &md, flag, value]))?;
|
2020-07-31 16:42:40 +05:30
|
|
|
|
2021-10-11 16:37:26 +05:30
|
|
|
let output = run_ok(thin_dump_cmd(args![&md]))?;
|
2021-07-01 19:57:37 +05:30
|
|
|
assert!(output.contains(pattern));
|
2020-07-31 16:42:40 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-09-10 08:03:53 +05:30
|
|
|
#[cfg(not(feature = "rust_tests"))]
|
2020-07-31 16:42:40 +05:30
|
|
|
fn override_transaction_id() -> Result<()> {
|
|
|
|
override_something("--transaction-id", "2345", "transaction=\"2345\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-09-10 08:03:53 +05:30
|
|
|
#[cfg(not(feature = "rust_tests"))]
|
2020-07-31 16:42:40 +05:30
|
|
|
fn override_data_block_size() -> Result<()> {
|
|
|
|
override_something("--data-block-size", "8192", "data_block_size=\"8192\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-09-10 08:03:53 +05:30
|
|
|
#[cfg(not(feature = "rust_tests"))]
|
2020-07-31 16:42:40 +05:30
|
|
|
fn override_nr_data_blocks() -> Result<()> {
|
|
|
|
override_something("--nr-data-blocks", "234500", "nr_data_blocks=\"234500\"")
|
|
|
|
}
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
//-----------------------------------------
|