[pack/unpack] Get the functional tests working again.

There's some hard coded version numbers in the tests, but I'm
leaving for now since I'll rewrite in Rust to avoid too much
of a proliferation of languages.
This commit is contained in:
Joe Thornber 2020-06-09 13:03:39 +01:00
parent db5a71a53c
commit 409a660082
6 changed files with 77 additions and 35 deletions

View File

@ -75,20 +75,34 @@ Options:
{-V|--version}")
(define thin-metadata-pack-help
"Usage: thin_metadata_pack [options]
Options:
{-i|--input} <input metadata (binary format)>
{-o|--output} <output packed metadata>
{-h|--help}
{-V|--version}")
"thin_metadata_pack 0.8.5
Produces a compressed file of thin metadata. Only packs metadata blocks that are actually used.
USAGE:
thin_metadata_pack -i <DEV> -o <FILE>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-i <DEV> Specify thinp metadata binary device/file
-o <FILE> Specify packed output file")
(define thin-metadata-unpack-help
"Usage: thin_metadata_unpack [options]
Options:
{-i|--input} <input packed metadata>
{-o|--output} <output metadata (binary format)>
{-h|--help}
{-V|--version}")
"thin_metadata_unpack 0.8.5
Unpack a compressed file of thin metadata.
USAGE:
thin_metadata_unpack -i <DEV> -o <FILE>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-i <DEV> Specify thinp metadata binary device/file
-o <FILE> Specify packed output file")
(define cache-check-help
"Usage: cache_check [options] {device|file}

View File

@ -509,17 +509,17 @@
;;;-----------------------------------------------------------
(define-scenario (thin-metadata-pack version)
"thin_metadata_pack accepts --version"
"accepts --version"
(run-ok-rcv (stdout _) (thin-metadata-pack "--version")
(assert-equal tools-version stdout)))
(assert-equal "thin_metadata_pack 0.8.5" stdout)))
(define-scenario (thin-metadata-pack h)
"thin_metadata_pack accepts -h"
"accepts -h"
(run-ok-rcv (stdout _) (thin-metadata-pack "-h")
(assert-equal thin-metadata-pack-help stdout)))
(define-scenario (thin-metadata-pack help)
"thin_metadata_pack accepts --help"
"accepts --help"
(run-ok-rcv (stdout _) (thin-metadata-pack "--help")
(assert-equal thin-metadata-pack-help stdout)))
@ -527,41 +527,41 @@
"Unrecognised option should cause failure"
(with-valid-metadata (md)
(run-fail-rcv (stdout stderr) (thin-metadata-pack "--unleash-the-hedgehogs")
(assert-matches ".*thin_metadata_pack: unrecognized option '--unleash-the-hedgehogs" stderr))))
(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 "No input file provided." stderr))))
(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 stat path" stderr))))
(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 "No output file provided." stderr))))
(assert-starts-with "error: The following required arguments were not provided:\n -o <FILE>" stderr))))
;;;-----------------------------------------------------------
;;; thin_metadata_pack scenarios
;;; thin_metadata_unpack scenarios
;;;-----------------------------------------------------------
(define-scenario (thin-metadata-unpack version)
"thin_metadata_pack accepts --version"
"accepts --version"
(run-ok-rcv (stdout _) (thin-metadata-unpack "--version")
(assert-equal tools-version stdout)))
(assert-equal "thin_metadata_unpack 0.8.5" stdout)))
(define-scenario (thin-metadata-unpack h)
"thin_metadata_pack accepts -h"
"accepts -h"
(run-ok-rcv (stdout _) (thin-metadata-unpack "-h")
(assert-equal thin-metadata-unpack-help stdout)))
(define-scenario (thin-metadata-unpack help)
"thin_metadata_pack accepts --help"
"accepts --help"
(run-ok-rcv (stdout _) (thin-metadata-unpack "--help")
(assert-equal thin-metadata-unpack-help stdout)))
@ -569,25 +569,25 @@
"Unrecognised option should cause failure"
(with-valid-metadata (md)
(run-fail-rcv (stdout stderr) (thin-metadata-unpack "--unleash-the-hedgehogs")
(assert-matches ".*thin_metadata_unpack: unrecognized option '--unleash-the-hedgehogs" stderr))))
(assert-starts-with "error: Found argument '--unleash-the-hedgehogs'" stderr))))
(define-scenario (thin-metadata-unpack missing-input-file)
"the input file wasn't specified"
(with-empty-metadata (md)
(run-fail-rcv (_ stderr) (thin-metadata-unpack "-o " md)
(assert-starts-with "No input file provided." stderr))))
(assert-starts-with "error: The following required arguments were not provided:\n -i <DEV>" stderr))))
(define-scenario (thin-metadata-unpack no-such-input-file)
"the input file can't be found"
(with-empty-metadata (md)
(run-fail-rcv (_ stderr) (thin-metadata-unpack "-i no-such-file -o" md)
(assert-starts-with "Couldn't open pack file" stderr))))
(assert-starts-with "Couldn't find input file" stderr))))
(define-scenario (thin-metadata-unpack missing-output-file)
"the output file wasn't specified"
(with-empty-metadata (md)
(run-fail-rcv (_ stderr) (thin-metadata-unpack "-i" md)
(assert-starts-with "No output file provided." stderr))))
(assert-starts-with "error: The following required arguments were not provided:\n -o <FILE>" stderr))))
(define-scenario (thin-metadata-unpack garbage-input-file)
"the input file is just zeroes"

View File

@ -2,7 +2,8 @@ extern crate clap;
extern crate thinp;
use clap::{App, Arg};
use std::process;
use std::process::exit;
use thinp::file_utils;
fn main() {
let parser = App::new("thin_metadata_pack")
@ -25,8 +26,13 @@ fn main() {
let input_file = matches.value_of("INPUT").unwrap();
let output_file = matches.value_of("OUTPUT").unwrap();
if !file_utils::file_exists(input_file) {
eprintln!("Couldn't find input file '{}'.", &input_file);
exit(1);
}
if let Err(reason) = thinp::pack::pack::pack(&input_file, &output_file) {
println!("Application error: {}\n", reason);
process::exit(1);
exit(1);
}
}

View File

@ -3,6 +3,9 @@ extern crate thinp;
use clap::{App, Arg};
use std::process;
use thinp::file_utils;
use std::process::exit;
fn main() {
let parser = App::new("thin_metadata_unpack")
@ -21,11 +24,15 @@ fn main() {
.value_name("FILE")
.takes_value(true));
let matches = parser.get_matches();
let input_file = matches.value_of("INPUT").unwrap();
let output_file = matches.value_of("OUTPUT").unwrap();
if !file_utils::file_exists(input_file) {
eprintln!("Couldn't find input file '{}'.", &input_file);
exit(1);
}
if let Err(reason) = thinp::pack::pack::unpack(&input_file, &output_file) {
println!("Application error: {}", reason);
process::exit(1);

View File

@ -13,5 +13,6 @@ extern crate quickcheck_macros;
pub mod block_manager;
pub mod check;
pub mod file_utils;
pub mod pack;
pub mod version;

View File

@ -168,12 +168,26 @@ fn read_header<R>(mut r: R) -> io::Result<u64>
where
R: byteorder::ReadBytesExt,
{
use std::process::exit;
let magic = r.read_u64::<LittleEndian>()?;
assert_eq!(magic, MAGIC);
if magic != MAGIC {
eprintln!("Not a pack file.");
exit(1);
}
let version = r.read_u64::<LittleEndian>()?;
assert_eq!(version, PACK_VERSION);
if version != PACK_VERSION {
eprintln!("unsupported pack file version ({}).", PACK_VERSION);
exit(1);
}
let block_size = r.read_u64::<LittleEndian>()?;
assert_eq!(block_size, 4096);
if block_size != BLOCK_SIZE {
eprintln!("block size is not {}", BLOCK_SIZE);
exit(1);
}
r.read_u64::<LittleEndian>()
}