2021-07-20 15:07:55 +05:30
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
use thinp::file_utils;
|
|
|
|
|
2021-07-20 23:41:46 +05:30
|
|
|
use crate::args;
|
2021-07-20 15:07:55 +05:30
|
|
|
use crate::common::process::*;
|
|
|
|
use crate::common::program::*;
|
|
|
|
use crate::common::test_dir::*;
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
//-----------------------------------------
|
|
|
|
// test invalid arguments
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_missing_output_option<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-07-06 07:21:27 +05:30
|
|
|
P: OutputProgram<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
2021-07-20 23:41:46 +05:30
|
|
|
let stderr = run_fail(P::path(), args!["-i", &input])?;
|
2021-07-06 07:21:27 +05:30
|
|
|
assert!(stderr.contains(P::missing_output_arg()));
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_missing_output_option {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn missing_output_option() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_missing_output_option::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_output_file_not_found<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-08-30 21:49:44 +05:30
|
|
|
P: MetadataWriter<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
2021-07-20 23:41:46 +05:30
|
|
|
let stderr = run_fail(P::path(), args!["-i", &input, "-o", "no-such-file"])?;
|
2021-08-30 21:49:44 +05:30
|
|
|
assert!(stderr.contains(<P as MetadataWriter>::file_not_found()));
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_output_file_not_found {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn output_file_not_found() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_output_file_not_found::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_output_cannot_be_a_directory<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-07-06 07:21:27 +05:30
|
|
|
P: OutputProgram<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
2021-07-20 23:41:46 +05:30
|
|
|
let stderr = run_fail(P::path(), args!["-i", &input, "-o", "/tmp"])?;
|
2021-07-06 07:21:27 +05:30
|
|
|
assert!(stderr.contains("Not a block device or regular file"));
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_output_cannot_be_a_directory {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn output_cannot_be_a_directory() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_output_cannot_be_a_directory::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_unwritable_output_file<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-07-06 07:21:27 +05:30
|
|
|
P: OutputProgram<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
let output = td.mk_path("meta.bin");
|
|
|
|
let _file = file_utils::create_sized_file(&output, 4096);
|
|
|
|
duct::cmd!("chmod", "-w", &output).run()?;
|
|
|
|
|
2021-07-20 23:41:46 +05:30
|
|
|
let stderr = run_fail(P::path(), args!["-i", &input, "-o", &output])?;
|
2021-07-01 19:57:37 +05:30
|
|
|
assert!(stderr.contains("Permission denied"));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_unwritable_output_file {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn unwritable_output_file() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_unwritable_output_file::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// test invalid content
|
|
|
|
|
|
|
|
// currently thin/cache_restore only
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_tiny_output_file<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-08-30 21:49:44 +05:30
|
|
|
P: MetadataWriter<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
let output = td.mk_path("meta.bin");
|
|
|
|
let _file = file_utils::create_sized_file(&output, 4096);
|
|
|
|
|
2021-07-20 23:41:46 +05:30
|
|
|
let stderr = run_fail(P::path(), args!["-i", &input, "-o", &output])?;
|
2021-07-01 19:57:37 +05:30
|
|
|
assert!(stderr.contains("Output file too small"));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_tiny_output_file {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn tiny_output_file() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_tiny_output_file::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------
|