[functional-tests] Port thin_rmap tests to Rust.
cargo test
This commit is contained in:
parent
ad29fe65fa
commit
9552cb4817
@ -67,58 +67,6 @@
|
||||
;; to run.
|
||||
(define (register-thin-tests) #t)
|
||||
|
||||
;;;-----------------------------------------------------------
|
||||
;;; thin_rmap scenarios
|
||||
;;;-----------------------------------------------------------
|
||||
|
||||
(define-scenario (thin-rmap v)
|
||||
"thin_rmap accepts -V"
|
||||
(run-ok-rcv (stdout _) (thin-rmap "-V")
|
||||
(assert-equal tools-version stdout)))
|
||||
|
||||
(define-scenario (thin-rmap version)
|
||||
"thin_rmap accepts --version"
|
||||
(run-ok-rcv (stdout _) (thin-rmap "--version")
|
||||
(assert-equal tools-version stdout)))
|
||||
|
||||
(define-scenario (thin-rmap h)
|
||||
"thin_rmap accepts -h"
|
||||
(run-ok-rcv (stdout _) (thin-rmap "-h")
|
||||
(assert-equal thin-rmap-help stdout)))
|
||||
|
||||
(define-scenario (thin-rmap help)
|
||||
"thin_rmap accepts --help"
|
||||
(run-ok-rcv (stdout _) (thin-rmap "--help")
|
||||
(assert-equal thin-rmap-help stdout)))
|
||||
|
||||
(define-scenario (thin-rmap unrecognised-flag)
|
||||
"thin_rmap complains with bad flags."
|
||||
(run-fail (thin-rmap "--unleash-the-hedgehogs")))
|
||||
|
||||
(define-scenario (thin-rmap valid-region-format-should-pass)
|
||||
"thin_rmap with a valid region format should pass."
|
||||
(with-valid-metadata (md)
|
||||
(run-ok
|
||||
(thin-rmap "--region 23..7890" md))))
|
||||
|
||||
(define-scenario (thin-rmap invalid-region-should-fail)
|
||||
"thin_rmap with an invalid region format should fail."
|
||||
(for-each (lambda (pattern)
|
||||
(with-valid-metadata (md)
|
||||
(run-fail (thin-rmap "--region" pattern md))))
|
||||
'("23,7890" "23..six" "found..7890" "89..88" "89..89" "89.." "" "89...99")))
|
||||
|
||||
(define-scenario (thin-rmap multiple-regions-should-pass)
|
||||
"thin_rmap should handle multiple regions."
|
||||
(with-valid-metadata (md)
|
||||
(run-ok (thin-rmap "--region 1..23 --region 45..78" md))))
|
||||
|
||||
(define-scenario (thin-rmap handles-junk-input)
|
||||
"Fail gracefully if given nonsense"
|
||||
(with-thin-xml (xml)
|
||||
(run-fail-rcv (_ stderr) (thin-rmap "--region 0..-1" xml)
|
||||
#t)))
|
||||
|
||||
;;;-----------------------------------------------------------
|
||||
;;; thin_delta scenarios
|
||||
;;;-----------------------------------------------------------
|
||||
|
@ -46,6 +46,17 @@ macro_rules! thin_dump {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! thin_rmap {
|
||||
( $( $arg: expr ),* ) => {
|
||||
{
|
||||
use std::ffi::OsString;
|
||||
let args: &[OsString] = &[$( Into::<OsString>::into($arg) ),*];
|
||||
duct::cmd("bin/thin_rmap", args).stdout_capture().stderr_capture()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct TestDir {
|
||||
@ -86,7 +97,7 @@ pub fn mk_valid_md(td: &mut TestDir) -> Result<PathBuf> {
|
||||
let xml = td.mk_path("meta.xml");
|
||||
let md = td.mk_path("meta.bin");
|
||||
|
||||
let mut gen = SingleThinS::new(0, 1024, 2048, 2048);
|
||||
let mut gen = SingleThinS::new(0, 1024, 20480, 20480);
|
||||
write_xml(&xml, &mut gen)?;
|
||||
|
||||
let _file = file_utils::create_sized_file(&md, 4096 * 4096);
|
||||
|
@ -23,7 +23,7 @@ fn accepts_version() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const USAGE: &'static str = "Usage: thin_check [options] {device|file}\nOptions:\n {-q|--quiet}\n {-h|--help}\n {-V|--version}\n {-m|--metadata-snap}\n {--override-mapping-root}\n {--clear-needs-check-flag}\n {--ignore-non-fatal-errors}\n {--skip-mappings}\n {--super-block-only}";
|
||||
const USAGE: &str = "Usage: thin_check [options] {device|file}\nOptions:\n {-q|--quiet}\n {-h|--help}\n {-V|--version}\n {-m|--metadata-snap}\n {--override-mapping-root}\n {--clear-needs-check-flag}\n {--ignore-non-fatal-errors}\n {--skip-mappings}\n {--super-block-only}";
|
||||
|
||||
#[test]
|
||||
fn accepts_h() -> Result<()> {
|
||||
|
@ -120,17 +120,3 @@ fn missing_nr_data_blocks() -> Result<()> {
|
||||
assert!(stderr.contains("nr data blocks"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
// (define-scenario (thin-dump repair-superblock missing-data-block-size)
|
||||
// "--data-block-size is mandatory if the superblock is damaged"
|
||||
// (with-damaged-superblock (md)
|
||||
// (run-fail-rcv (_ stderr) (thin-dump "--repair" "--transaction-id=5" "--nr-data-blocks=4096000" md)
|
||||
// (assert-matches ".*data block size.*" stderr))))
|
||||
//
|
||||
// (define-scenario (thin-dump repair-superblock missing-nr-data-blocks)
|
||||
// "--nr-data-blocks is mandatory if the superblock is damaged"
|
||||
// (with-damaged-superblock (md)
|
||||
// (run-fail-rcv (_ stderr) (thin-dump "--repair" "--transaction-id=5" "--data-block-size=128" md)
|
||||
// (assert-matches ".*nr data blocks.*" stderr))))
|
||||
//
|
||||
|
97
tests/thin_rmap.rs
Normal file
97
tests/thin_rmap.rs
Normal file
@ -0,0 +1,97 @@
|
||||
use anyhow::Result;
|
||||
use thinp::file_utils;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{Write};
|
||||
use std::str::from_utf8;
|
||||
use thinp::version::TOOLS_VERSION;
|
||||
|
||||
mod common;
|
||||
|
||||
use common::xml_generator::{write_xml, FragmentedS, SingleThinS};
|
||||
use common::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn accepts_v() -> Result<()> {
|
||||
let stdout = thin_rmap!("-V").read()?;
|
||||
assert_eq!(stdout, TOOLS_VERSION);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_version() -> Result<()> {
|
||||
let stdout = thin_rmap!("--version").read()?;
|
||||
assert_eq!(stdout, TOOLS_VERSION);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const USAGE: &str = "Usage: thin_rmap [options] {device|file}\nOptions:\n {-h|--help}\n {-V|--version}\n {--region <block range>}*\nWhere:\n <block range> is of the form <begin>..<one-past-the-end>\n for example 5..45 denotes blocks 5 to 44 inclusive, but not block 45";
|
||||
|
||||
#[test]
|
||||
fn accepts_h() -> Result<()> {
|
||||
let stdout = thin_rmap!("-h").read()?;
|
||||
assert_eq!(stdout, USAGE);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_help() -> Result<()> {
|
||||
let stdout = thin_rmap!("--help").read()?;
|
||||
assert_eq!(stdout, USAGE);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_bad_option() -> Result<()> {
|
||||
let stderr = run_fail(thin_rmap!("--hedgehogs-only"))?;
|
||||
assert!(stderr.contains("unrecognized option \'--hedgehogs-only\'"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_region_format_should_pass() -> Result<()> {
|
||||
let mut td = TestDir::new()?;
|
||||
let md = mk_valid_md(&mut td)?;
|
||||
let output = thin_rmap!("--region", "23..7890", &md).unchecked().run()?;
|
||||
eprintln!("stdout: {:?}", output.stdout);
|
||||
eprintln!("stderr: {:?}", output.stderr);
|
||||
assert!(output.status.success());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_regions_should_fail() -> Result<()> {
|
||||
let invalid_regions = ["23,7890", "23..six", "found..7890", "89..88", "89..89", "89..", "", "89...99"];
|
||||
for r in &invalid_regions {
|
||||
let mut td = TestDir::new()?;
|
||||
let md = mk_valid_md(&mut td)?;
|
||||
run_fail(thin_rmap!(r, &md))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_regions_should_pass() -> Result<()> {
|
||||
let mut td = TestDir::new()?;
|
||||
let md = mk_valid_md(&mut td)?;
|
||||
thin_rmap!("--region", "1..23", "--region", "45..78", &md).run()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn junk_input() -> Result<()> {
|
||||
let mut td = TestDir::new()?;
|
||||
let xml = mk_valid_xml(&mut td)?;
|
||||
let stderr = run_fail(thin_rmap!("--region", "0..-1", &xml))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// (define-scenario (thin-rmap handles-junk-input)
|
||||
// "Fail gracefully if given nonsense"
|
||||
// (with-thin-xml (xml)
|
||||
// (run-fail-rcv (_ stderr) (thin-rmap "--region 0..-1" xml)
|
||||
// #t)))
|
||||
|
||||
|
||||
//------------------------------------------
|
Loading…
Reference in New Issue
Block a user