2021-07-19 10:50:18 +02:00
use std ::process ::Command ;
2020-04-17 14:11:25 +02:00
use anyhow ::{ Error } ;
2018-12-30 15:33:43 +01:00
2021-07-19 10:50:18 +02:00
use pbs_client ::pxar ::* ;
2018-12-30 15:33:43 +01:00
fn run_test ( dir_name : & str ) -> Result < ( ) , Error > {
2019-04-06 11:26:17 +02:00
println! ( " run pxar test {} " , dir_name ) ;
2018-12-30 15:33:43 +01:00
Command ::new ( " casync " )
. arg ( " make " )
. arg ( " test-casync.catar " )
. arg ( dir_name )
. status ( )
. expect ( " failed to execute casync " ) ;
2020-03-23 15:03:18 +01:00
let writer = std ::fs ::OpenOptions ::new ( )
2018-12-30 15:33:43 +01:00
. create ( true )
. write ( true )
. truncate ( true )
. open ( " test-proxmox.catar " ) ? ;
2020-03-23 15:03:18 +01:00
let writer = pxar ::encoder ::sync ::StandardWriter ::new ( writer ) ;
2018-12-30 15:33:43 +01:00
2020-03-23 15:03:18 +01:00
let dir = nix ::dir ::Dir ::open (
2018-12-30 15:33:43 +01:00
dir_name , nix ::fcntl ::OFlag ::O_NOFOLLOW ,
nix ::sys ::stat ::Mode ::empty ( ) ) ? ;
2021-01-25 14:42:54 +01:00
let options = PxarCreateOptions {
entries_max : ENCODER_MAX_ENTRIES ,
.. PxarCreateOptions ::default ( )
} ;
2021-02-09 13:03:48 +01:00
let rt = tokio ::runtime ::Runtime ::new ( ) . unwrap ( ) ;
rt . block_on ( create_archive (
2020-03-23 15:03:18 +01:00
dir ,
writer ,
2020-06-10 11:03:42 +02:00
Flags ::DEFAULT ,
2020-03-23 15:03:18 +01:00
| _ | Ok ( ( ) ) ,
None ,
2021-01-25 14:42:54 +01:00
options ,
2021-02-09 13:03:48 +01:00
) ) ? ;
2018-12-30 15:33:43 +01:00
Command ::new ( " cmp " )
. arg ( " --verbose " )
. arg ( " test-casync.catar " )
. arg ( " test-proxmox.catar " )
. status ( )
. expect ( " test failed - archives are different " ) ;
Ok ( ( ) )
}
fn run_all_tests ( ) -> Result < ( ) , Error > {
run_test ( " tests/catar_data/test_file " ) ? ;
run_test ( " tests/catar_data/test_symlink " ) ? ;
run_test ( " tests/catar_data/test_subdir " ) ? ;
2018-12-31 10:19:15 +01:00
run_test ( " tests/catar_data/test_goodbye_sort_order " ) ? ;
2018-12-30 17:32:52 +01:00
2018-12-31 10:22:39 +01:00
run_test ( " tests/catar_data/test_files_and_subdirs " ) ? ;
2018-12-30 15:33:43 +01:00
Ok ( ( ) )
}
2019-01-31 15:32:04 +01:00
#[ test ] #[ ignore ]
2018-12-31 10:19:15 +01:00
fn catar_simple ( ) {
2018-12-30 15:33:43 +01:00
if let Err ( err ) = run_all_tests ( ) {
eprintln! ( " Error: {} " , err ) ;
std ::process ::exit ( 1 ) ;
}
}