tests: rust fmt
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
4de1c42c20
commit
6082d75966
|
@ -1,39 +1,40 @@
|
|||
use std::sync::Arc;
|
||||
use std::io::Cursor;
|
||||
use std::io::{Read, Write, Seek, SeekFrom };
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{bail, Error};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use pbs_tools::crypt_config::CryptConfig;
|
||||
use pbs_datastore::{DataBlob, DataBlobReader, DataBlobWriter};
|
||||
use pbs_tools::crypt_config::CryptConfig;
|
||||
|
||||
lazy_static! {
|
||||
static ref TEST_DATA: Vec<u8> = {
|
||||
let mut data = Vec::new();
|
||||
|
||||
for i in 0..100_000 {
|
||||
data.push((i%255) as u8);
|
||||
data.push((i % 255) as u8);
|
||||
}
|
||||
|
||||
data
|
||||
};
|
||||
|
||||
static ref CRYPT_CONFIG: Arc<CryptConfig> = {
|
||||
let key = [1u8; 32];
|
||||
Arc::new(CryptConfig::new(key).unwrap())
|
||||
};
|
||||
|
||||
static ref TEST_DIGEST_PLAIN: [u8; 32] = [83, 154, 96, 195, 167, 204, 38, 142, 204, 224, 130, 201, 24, 71, 2, 188, 130, 155, 177, 6, 162, 100, 61, 238, 38, 219, 63, 240, 191, 132, 87, 238];
|
||||
|
||||
static ref TEST_DIGEST_ENC: [u8; 32] = [50, 162, 191, 93, 255, 132, 9, 14, 127, 23, 92, 39, 246, 102, 245, 204, 130, 104, 4, 106, 182, 239, 218, 14, 80, 17, 150, 188, 239, 253, 198, 117];
|
||||
static ref TEST_DIGEST_PLAIN: [u8; 32] = [
|
||||
83, 154, 96, 195, 167, 204, 38, 142, 204, 224, 130, 201, 24, 71, 2, 188, 130, 155, 177, 6,
|
||||
162, 100, 61, 238, 38, 219, 63, 240, 191, 132, 87, 238
|
||||
];
|
||||
static ref TEST_DIGEST_ENC: [u8; 32] = [
|
||||
50, 162, 191, 93, 255, 132, 9, 14, 127, 23, 92, 39, 246, 102, 245, 204, 130, 104, 4, 106,
|
||||
182, 239, 218, 14, 80, 17, 150, 188, 239, 253, 198, 117
|
||||
];
|
||||
}
|
||||
|
||||
fn verify_test_blob(mut cursor: Cursor<Vec<u8>>, digest: &[u8; 32]) -> Result<(), Error> {
|
||||
|
||||
// run read tests with different buffer sizes
|
||||
for size in [1, 3, 64*1024].iter() {
|
||||
|
||||
for size in [1, 3, 64 * 1024].iter() {
|
||||
println!("Starting DataBlobReader test (size = {})", size);
|
||||
|
||||
cursor.seek(SeekFrom::Start(0))?;
|
||||
|
@ -44,7 +45,9 @@ fn verify_test_blob(mut cursor: Cursor<Vec<u8>>, digest: &[u8; 32]) -> Result<()
|
|||
let mut buf = vec![0u8; *size];
|
||||
loop {
|
||||
let count = reader.read(&mut buf)?;
|
||||
if count == 0 { break; }
|
||||
if count == 0 {
|
||||
break;
|
||||
}
|
||||
buffer.extend(&buf[..count]);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ use anyhow::Error;
|
|||
use pbs_client::pxar::*;
|
||||
|
||||
fn run_test(dir_name: &str) -> Result<(), Error> {
|
||||
|
||||
println!("run pxar test {}", dir_name);
|
||||
|
||||
Command::new("casync")
|
||||
|
@ -23,8 +22,10 @@ fn run_test(dir_name: &str) -> Result<(), Error> {
|
|||
let writer = pxar::encoder::sync::StandardWriter::new(writer);
|
||||
|
||||
let dir = nix::dir::Dir::open(
|
||||
dir_name, nix::fcntl::OFlag::O_NOFOLLOW,
|
||||
nix::sys::stat::Mode::empty())?;
|
||||
dir_name,
|
||||
nix::fcntl::OFlag::O_NOFOLLOW,
|
||||
nix::sys::stat::Mode::empty(),
|
||||
)?;
|
||||
|
||||
let options = PxarCreateOptions {
|
||||
entries_max: ENCODER_MAX_ENTRIES,
|
||||
|
@ -52,7 +53,6 @@ fn run_test(dir_name: &str) -> Result<(), Error> {
|
|||
}
|
||||
|
||||
fn run_all_tests() -> Result<(), Error> {
|
||||
|
||||
run_test("tests/catar_data/test_file")?;
|
||||
|
||||
run_test("tests/catar_data/test_symlink")?;
|
||||
|
@ -66,9 +66,9 @@ fn run_all_tests() -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test] #[ignore]
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn catar_simple() {
|
||||
|
||||
if let Err(err) = run_all_tests() {
|
||||
eprintln!("Error: {}", err);
|
||||
std::process::exit(1);
|
||||
|
|
|
@ -12,7 +12,6 @@ fn get_prune_list(
|
|||
return_kept: bool,
|
||||
options: &PruneOptions,
|
||||
) -> Vec<PathBuf> {
|
||||
|
||||
let mut prune_info = compute_prune_info(list, options).unwrap();
|
||||
|
||||
prune_info.reverse();
|
||||
|
@ -29,11 +28,7 @@ fn get_prune_list(
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn create_info(
|
||||
snapshot: &str,
|
||||
partial: bool,
|
||||
) -> BackupInfo {
|
||||
|
||||
fn create_info(snapshot: &str, partial: bool) -> BackupInfo {
|
||||
let backup_dir: BackupDir = snapshot.parse().unwrap();
|
||||
|
||||
let mut files = Vec::new();
|
||||
|
@ -42,13 +37,14 @@ fn create_info(
|
|||
files.push(String::from(MANIFEST_BLOB_NAME));
|
||||
}
|
||||
|
||||
BackupInfo { backup_dir, files, protected: false }
|
||||
BackupInfo {
|
||||
backup_dir,
|
||||
files,
|
||||
protected: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn create_info_protected(
|
||||
snapshot: &str,
|
||||
partial: bool,
|
||||
) -> BackupInfo {
|
||||
fn create_info_protected(snapshot: &str, partial: bool) -> BackupInfo {
|
||||
let mut info = create_info(snapshot, partial);
|
||||
info.protected = true;
|
||||
info
|
||||
|
@ -58,34 +54,35 @@ fn create_info_protected(
|
|||
fn test_prune_protected() -> Result<(), Error> {
|
||||
let mut orig_list = Vec::new();
|
||||
|
||||
orig_list.push(create_info_protected("host/elsa/2019-11-15T09:39:15Z", false));
|
||||
orig_list.push(create_info_protected(
|
||||
"host/elsa/2019-11-15T09:39:15Z",
|
||||
false,
|
||||
));
|
||||
orig_list.push(create_info("host/elsa/2019-11-15T10:39:15Z", false));
|
||||
orig_list.push(create_info("host/elsa/2019-11-15T10:49:15Z", false));
|
||||
orig_list.push(create_info_protected("host/elsa/2019-11-15T10:59:15Z", false));
|
||||
orig_list.push(create_info_protected(
|
||||
"host/elsa/2019-11-15T10:59:15Z",
|
||||
false,
|
||||
));
|
||||
|
||||
eprintln!("{:?}", orig_list);
|
||||
|
||||
let mut options = PruneOptions::default();
|
||||
options.keep_last = Some(1);
|
||||
let remove_list = get_prune_list(orig_list.clone(), false, &options);
|
||||
let expect: Vec<PathBuf> = vec![
|
||||
PathBuf::from("host/elsa/2019-11-15T10:39:15Z"),
|
||||
];
|
||||
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-11-15T10:39:15Z")];
|
||||
assert_eq!(remove_list, expect);
|
||||
|
||||
let mut options = PruneOptions::default();
|
||||
options.keep_hourly = Some(1);
|
||||
let remove_list = get_prune_list(orig_list.clone(), false, &options);
|
||||
let expect: Vec<PathBuf> = vec![
|
||||
PathBuf::from("host/elsa/2019-11-15T10:39:15Z"),
|
||||
];
|
||||
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-11-15T10:39:15Z")];
|
||||
assert_eq!(remove_list, expect);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_prune_hourly() -> Result<(), Error> {
|
||||
|
||||
let mut orig_list = Vec::new();
|
||||
|
||||
orig_list.push(create_info("host/elsa/2019-11-15T09:39:15Z", false));
|
||||
|
@ -121,7 +118,6 @@ fn test_prune_hourly() -> Result<(), Error> {
|
|||
|
||||
#[test]
|
||||
fn test_prune_simple2() -> Result<(), Error> {
|
||||
|
||||
let mut orig_list = Vec::new();
|
||||
|
||||
orig_list.push(create_info("host/elsa/2018-11-15T11:59:15Z", false));
|
||||
|
@ -138,9 +134,7 @@ fn test_prune_simple2() -> Result<(), Error> {
|
|||
let mut options = PruneOptions::default();
|
||||
options.keep_daily = Some(1);
|
||||
let remove_list = get_prune_list(list, true, &options);
|
||||
let expect: Vec<PathBuf> = vec![
|
||||
PathBuf::from("host/elsa/2019-12-04T11:59:15Z"),
|
||||
];
|
||||
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-12-04T11:59:15Z")];
|
||||
assert_eq!(remove_list, expect);
|
||||
|
||||
let list = orig_list.clone();
|
||||
|
@ -194,7 +188,6 @@ fn test_prune_simple2() -> Result<(), Error> {
|
|||
|
||||
#[test]
|
||||
fn test_prune_simple() -> Result<(), Error> {
|
||||
|
||||
let mut orig_list = Vec::new();
|
||||
|
||||
orig_list.push(create_info("host/elsa/2019-12-02T11:59:15Z", false));
|
||||
|
@ -215,9 +208,7 @@ fn test_prune_simple() -> Result<(), Error> {
|
|||
let mut options = PruneOptions::default();
|
||||
options.keep_last = Some(3);
|
||||
let remove_list = get_prune_list(list, false, &options);
|
||||
let expect: Vec<PathBuf> = vec![
|
||||
PathBuf::from("host/elsa/2019-12-02T11:59:15Z"),
|
||||
];
|
||||
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-12-02T11:59:15Z")];
|
||||
assert_eq!(remove_list, expect);
|
||||
|
||||
let list = orig_list.clone();
|
||||
|
|
|
@ -2,8 +2,8 @@ use std::collections::HashSet;
|
|||
|
||||
use anyhow::{bail, format_err, Error};
|
||||
|
||||
use proxmox_router::{ApiMethod, Permission, Router, SubRoute, SubdirMap};
|
||||
use proxmox_schema::*;
|
||||
use proxmox_router::{ApiMethod, Permission, Router, SubdirMap, SubRoute};
|
||||
|
||||
use proxmox_backup::api2;
|
||||
|
||||
|
@ -11,18 +11,19 @@ use proxmox_backup::api2;
|
|||
// correctly sorted.
|
||||
|
||||
fn verify_object_schema(schema: &ObjectSchema) -> Result<(), Error> {
|
||||
|
||||
let map = schema.properties;
|
||||
|
||||
if !map.is_empty() {
|
||||
|
||||
for i in 1..map.len() {
|
||||
|
||||
if map[i].0 <= map[i-1].0 {
|
||||
if map[i].0 <= map[i - 1].0 {
|
||||
for (name, _, _) in map.iter() {
|
||||
eprintln!("{}", name);
|
||||
}
|
||||
bail!("found unsorted property map ({} <= {})", map[i].0, map[i-1].0);
|
||||
bail!(
|
||||
"found unsorted property map ({} <= {})",
|
||||
map[i].0,
|
||||
map[i - 1].0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,15 +80,18 @@ fn verify_schema(schema: &Schema) -> Result<(), Error> {
|
|||
}
|
||||
|
||||
fn verify_access_permissions(permission: &Permission) -> Result<(), Error> {
|
||||
|
||||
match permission {
|
||||
Permission::Or(list) => {
|
||||
for perm in list.iter() { verify_access_permissions(perm)?; }
|
||||
for perm in list.iter() {
|
||||
verify_access_permissions(perm)?;
|
||||
}
|
||||
}
|
||||
Permission::And(list) => {
|
||||
for perm in list.iter() { verify_access_permissions(perm)?; }
|
||||
for perm in list.iter() {
|
||||
verify_access_permissions(perm)?;
|
||||
}
|
||||
Permission::Privilege(path_comp, ..)=> {
|
||||
}
|
||||
Permission::Privilege(path_comp, ..) => {
|
||||
let path = format!("/{}", path_comp.join("/"));
|
||||
pbs_config::acl::check_acl_path(&path)?;
|
||||
}
|
||||
|
@ -96,12 +100,7 @@ fn verify_access_permissions(permission: &Permission) -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn verify_api_method(
|
||||
method: &str,
|
||||
path: &str,
|
||||
info: &ApiMethod
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
fn verify_api_method(method: &str, path: &str, info: &ApiMethod) -> Result<(), Error> {
|
||||
match &info.parameters {
|
||||
ParameterSchema::Object(obj) => {
|
||||
verify_object_schema(obj)
|
||||
|
@ -122,22 +121,20 @@ fn verify_api_method(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn verify_dirmap(
|
||||
path: &str,
|
||||
dirmap: SubdirMap,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
fn verify_dirmap(path: &str, dirmap: SubdirMap) -> Result<(), Error> {
|
||||
if !dirmap.is_empty() {
|
||||
|
||||
for i in 1..dirmap.len() {
|
||||
|
||||
if dirmap[i].0 <= dirmap[i-1].0 {
|
||||
if dirmap[i].0 <= dirmap[i - 1].0 {
|
||||
for (name, _) in dirmap.iter() {
|
||||
eprintln!("{}/{}", path, name);
|
||||
}
|
||||
bail!("found unsorted dirmap at {:?} ({} <= {})", path, dirmap[i].0, dirmap[i-1].0);
|
||||
bail!(
|
||||
"found unsorted dirmap at {:?} ({} <= {})",
|
||||
path,
|
||||
dirmap[i].0,
|
||||
dirmap[i - 1].0
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +147,6 @@ fn verify_dirmap(
|
|||
}
|
||||
|
||||
fn verify_router(path: &str, router: &Router) -> Result<(), Error> {
|
||||
|
||||
println!("Verify {}", path);
|
||||
|
||||
if let Some(api_method) = router.get {
|
||||
|
@ -182,7 +178,6 @@ fn verify_router(path: &str, router: &Router) -> Result<(), Error> {
|
|||
|
||||
#[test]
|
||||
fn verify_backup_api() -> Result<(), Error> {
|
||||
|
||||
let api = &api2::backup::BACKUP_API_ROUTER;
|
||||
verify_router("backup-api", api)?;
|
||||
|
||||
|
@ -191,7 +186,6 @@ fn verify_backup_api() -> Result<(), Error> {
|
|||
|
||||
#[test]
|
||||
fn verify_reader_api() -> Result<(), Error> {
|
||||
|
||||
let api = &api2::reader::READER_API_ROUTER;
|
||||
verify_router("reader-api", api)?;
|
||||
|
||||
|
@ -200,7 +194,6 @@ fn verify_reader_api() -> Result<(), Error> {
|
|||
|
||||
#[test]
|
||||
fn verify_root_api() -> Result<(), Error> {
|
||||
|
||||
let api = &api2::ROUTER;
|
||||
verify_router("root", api)?;
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@ use anyhow::{bail, Error};
|
|||
|
||||
extern crate proxmox_backup;
|
||||
|
||||
extern crate tokio;
|
||||
extern crate nix;
|
||||
extern crate tokio;
|
||||
|
||||
use proxmox_sys::fs::CreateOptions;
|
||||
use proxmox_lang::try_block;
|
||||
use proxmox_sys::fs::CreateOptions;
|
||||
use proxmox_sys::{task_log, WorkerTaskContext};
|
||||
|
||||
use pbs_api_types::{Authid, UPID};
|
||||
|
@ -14,7 +14,6 @@ use pbs_api_types::{Authid, UPID};
|
|||
use proxmox_rest_server::{CommandSocket, WorkerTask};
|
||||
|
||||
fn garbage_collection(worker: &WorkerTask) -> Result<(), Error> {
|
||||
|
||||
task_log!(worker, "start garbage collection");
|
||||
|
||||
for i in 0..50 {
|
||||
|
@ -30,7 +29,6 @@ fn garbage_collection(worker: &WorkerTask) -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn worker_task_abort() -> Result<(), Error> {
|
||||
|
@ -47,9 +45,10 @@ fn worker_task_abort() -> Result<(), Error> {
|
|||
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async move {
|
||||
|
||||
let mut commando_sock = CommandSocket::new(
|
||||
proxmox_rest_server::our_ctrl_sock(), nix::unistd::Gid::current());
|
||||
proxmox_rest_server::our_ctrl_sock(),
|
||||
nix::unistd::Gid::current(),
|
||||
);
|
||||
|
||||
let init_result: Result<(), Error> = try_block!({
|
||||
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
||||
|
@ -82,7 +81,9 @@ fn worker_task_abort() -> Result<(), Error> {
|
|||
println!("got expected error: {}", err);
|
||||
} else {
|
||||
let mut data = errmsg.lock().unwrap();
|
||||
*data = Some(String::from("thread finished - seems abort did not work as expected"));
|
||||
*data = Some(String::from(
|
||||
"thread finished - seems abort did not work as expected",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -96,7 +97,9 @@ fn worker_task_abort() -> Result<(), Error> {
|
|||
Ok(wid) => {
|
||||
println!("WORKER: {}", wid);
|
||||
proxmox_rest_server::abort_worker_nowait(wid.parse::<UPID>().unwrap());
|
||||
proxmox_rest_server::wait_for_local_worker(&wid).await.unwrap();
|
||||
proxmox_rest_server::wait_for_local_worker(&wid)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -104,7 +107,7 @@ fn worker_task_abort() -> Result<(), Error> {
|
|||
let data = errmsg.lock().unwrap();
|
||||
match *data {
|
||||
Some(ref err) => bail!("Error: {}", err),
|
||||
None => {},
|
||||
None => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue