thin-provisioning-tools/tests/thin_delta.rs
Ming-Hung Tsai 16190f0f9a [tests] Pull out common submodules
New modules: fixture, process, program, target, and thin
2021-07-21 17:50:34 +08:00

84 lines
2.1 KiB
Rust

use anyhow::Result;
mod common;
use common::common_args::*;
use common::process::*;
use common::program::*;
use common::target::*;
use common::test_dir::*;
use common::thin::*;
//------------------------------------------
const USAGE: &str = "Usage: thin_delta [options] <device or file>\n\
Options:\n \
{--thin1, --snap1, --root1}\n \
{--thin2, --snap2, --root2}\n \
{-m, --metadata-snap} [block#]\n \
{--verbose}\n \
{-h|--help}\n \
{-V|--version}";
//------------------------------------------
struct ThinDelta;
impl<'a> Program<'a> for ThinDelta {
fn name() -> &'a str {
"thin_delta"
}
fn path() -> &'a std::ffi::OsStr {
THIN_DELTA.as_ref()
}
fn usage() -> &'a str {
USAGE
}
fn arg_type() -> ArgType {
ArgType::InputArg
}
fn bad_option_hint(option: &str) -> String {
cpp_msg::bad_option_hint(option)
}
}
//------------------------------------------
test_accepts_help!(ThinDelta);
test_accepts_version!(ThinDelta);
test_rejects_bad_option!(ThinDelta);
//------------------------------------------
#[test]
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()])?;
assert!(stderr.contains("--snap1 or --root1 not specified"));
Ok(())
}
#[test]
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()])?;
assert!(stderr.contains("--snap2 or --root2 not specified"));
Ok(())
}
#[test]
fn dev_unspecified() -> Result<()> {
let stderr = run_fail(THIN_DELTA, &["--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(())
}
//------------------------------------------