[functional-tests] port thin_metadata_pack tests to Rust.
cargo test
This commit is contained in:
parent
23568aaa11
commit
d2678fdf27
@ -67,49 +67,6 @@
|
||||
;; to run.
|
||||
(define (register-thin-tests) #t)
|
||||
|
||||
;;;-----------------------------------------------------------
|
||||
;;; thin_metadata_pack scenarios
|
||||
;;;-----------------------------------------------------------
|
||||
|
||||
(define-scenario (thin-metadata-pack version)
|
||||
"accepts --version"
|
||||
(run-ok-rcv (stdout _) (thin-metadata-pack "--version")
|
||||
(assert-equal "thin_metadata_pack 0.9.0-rc2" stdout)))
|
||||
|
||||
(define-scenario (thin-metadata-pack h)
|
||||
"accepts -h"
|
||||
(run-ok-rcv (stdout _) (thin-metadata-pack "-h")
|
||||
(assert-equal thin-metadata-pack-help stdout)))
|
||||
|
||||
(define-scenario (thin-metadata-pack help)
|
||||
"accepts --help"
|
||||
(run-ok-rcv (stdout _) (thin-metadata-pack "--help")
|
||||
(assert-equal thin-metadata-pack-help stdout)))
|
||||
|
||||
(define-scenario (thin-metadata-pack unrecognised-option)
|
||||
"Unrecognised option should cause failure"
|
||||
(with-valid-metadata (md)
|
||||
(run-fail-rcv (stdout stderr) (thin-metadata-pack "--unleash-the-hedgehogs")
|
||||
(assert-starts-with "error: Found argument '--unleash-the-hedgehogs'" stderr))))
|
||||
|
||||
(define-scenario (thin-metadata-pack missing-input-file)
|
||||
"the input file wasn't specified"
|
||||
(with-empty-metadata (md)
|
||||
(run-fail-rcv (_ stderr) (thin-metadata-pack "-o " md)
|
||||
(assert-starts-with "error: The following required arguments were not provided:\n -i <DEV>" stderr))))
|
||||
|
||||
(define-scenario (thin-metadata-pack no-such-input-file)
|
||||
"the input file can't be found"
|
||||
(with-empty-metadata (md)
|
||||
(run-fail-rcv (_ stderr) (thin-metadata-pack "-i no-such-file -o" md)
|
||||
(assert-starts-with "Couldn't find input file" stderr))))
|
||||
|
||||
(define-scenario (thin-metadata-pack missing-output-file)
|
||||
"the output file wasn't specified"
|
||||
(with-empty-metadata (md)
|
||||
(run-fail-rcv (_ stderr) (thin-metadata-pack "-i" md)
|
||||
(assert-starts-with "error: The following required arguments were not provided:\n -o <FILE>" stderr))))
|
||||
|
||||
;;;-----------------------------------------------------------
|
||||
;;; thin_metadata_unpack scenarios
|
||||
;;;-----------------------------------------------------------
|
||||
|
@ -81,6 +81,28 @@ macro_rules! thin_delta {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! thin_metadata_pack {
|
||||
( $( $arg: expr ),* ) => {
|
||||
{
|
||||
use std::ffi::OsString;
|
||||
let args: &[OsString] = &[$( Into::<OsString>::into($arg) ),*];
|
||||
duct::cmd("bin/thin_metadata_pack", args).stdout_capture().stderr_capture()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! thin_metadata_unpack {
|
||||
( $( $arg: expr ),* ) => {
|
||||
{
|
||||
use std::ffi::OsString;
|
||||
let args: &[OsString] = &[$( Into::<OsString>::into($arg) ),*];
|
||||
duct::cmd("bin/thin_metadata_unpack", args).stdout_capture().stderr_capture()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct TestDir {
|
||||
|
76
tests/thin_metadata_pack.rs
Normal file
76
tests/thin_metadata_pack.rs
Normal file
@ -0,0 +1,76 @@
|
||||
use anyhow::Result;
|
||||
use thinp::version::TOOLS_VERSION;
|
||||
|
||||
mod common;
|
||||
use common::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn accepts_v() -> Result<()> {
|
||||
let stdout = thin_metadata_pack!("-V").read()?;
|
||||
assert!(stdout.contains(TOOLS_VERSION));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_version() -> Result<()> {
|
||||
let stdout = thin_metadata_pack!("--version").read()?;
|
||||
assert!(stdout.contains(TOOLS_VERSION));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const USAGE: &str = "thin_metadata_pack 0.9.0-rc2\nProduces a compressed file of thin metadata. Only packs metadata blocks that are actually used.\n\nUSAGE:\n thin_metadata_pack -i <DEV> -o <FILE>\n\nFLAGS:\n -h, --help Prints help information\n -V, --version Prints version information\n\nOPTIONS:\n -i <DEV> Specify thinp metadata binary device/file\n -o <FILE> Specify packed output file";
|
||||
|
||||
#[test]
|
||||
fn accepts_h() -> Result<()> {
|
||||
let stdout = thin_metadata_pack!("-h").read()?;
|
||||
assert_eq!(stdout, USAGE);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_help() -> Result<()> {
|
||||
let stdout = thin_metadata_pack!("--help").read()?;
|
||||
assert_eq!(stdout, USAGE);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_bad_option() -> Result<()> {
|
||||
let stderr = run_fail(thin_metadata_pack!("--hedgehogs-only"))?;
|
||||
assert!(stderr.contains("Found argument \'--hedgehogs-only\'"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_input_file() -> Result<()> {
|
||||
let mut td = TestDir::new()?;
|
||||
let md = mk_zeroed_md(&mut td)?;
|
||||
let stderr = run_fail(thin_metadata_pack!("-o", &md))?;
|
||||
assert!(
|
||||
stderr.contains("error: The following required arguments were not provided:\n -i <DEV>")
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_such_input_file() -> Result<()> {
|
||||
let mut td = TestDir::new()?;
|
||||
let md = mk_zeroed_md(&mut td)?;
|
||||
let stderr = run_fail(thin_metadata_pack!("-i", "no-such-file", "-o", &md))?;
|
||||
assert!(stderr.contains("Couldn't find input file"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_output_file() -> Result<()> {
|
||||
let mut td = TestDir::new()?;
|
||||
let md = mk_zeroed_md(&mut td)?;
|
||||
let stderr = run_fail(thin_metadata_pack!("-i", &md))?;
|
||||
assert!(stderr
|
||||
.contains("error: The following required arguments were not provided:\n -o <FILE>"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------------
|
Loading…
Reference in New Issue
Block a user