diff options
Diffstat (limited to 'subplotlib/tests/files.rs')
-rw-r--r-- | subplotlib/tests/files.rs | 507 |
1 files changed, 308 insertions, 199 deletions
diff --git a/subplotlib/tests/files.rs b/subplotlib/tests/files.rs index a8fce3d..2f0bc6c 100644 --- a/subplotlib/tests/files.rs +++ b/subplotlib/tests/files.rs @@ -1,70 +1,90 @@ use subplotlib::prelude::*; + + // -------------------------------- lazy_static! { - static ref SUBPLOT_EMBEDDED_FILES: Vec<SubplotDataFile> = - vec![SubplotDataFile::new("aGVsbG8udHh0", "aGVsbG8sIHdvcmxkCg=="),]; + static ref SUBPLOT_EMBEDDED_FILES: Vec<SubplotDataFile> = vec![ + + SubplotDataFile::new("aGVsbG8udHh0", + "aGVsbG8sIHdvcmxkCg=="), + + ]; } + + // --------------------------------- // Create on-disk files from embedded files #[test] fn create_on_disk_files_from_embedded_files() { - let mut scenario = Scenario::new(&base64_decode( - "Q3JlYXRlIG9uLWRpc2sgZmlsZXMgZnJvbSBlbWJlZGRlZCBmaWxlcw==", - )); - + let mut scenario = Scenario::new(&base64_decode("Q3JlYXRlIG9uLWRpc2sgZmlsZXMgZnJvbSBlbWJlZGRlZCBmaWxlcw==")); + let step = subplotlib::steplibrary::files::create_from_embedded::Builder::default() - .embedded_file({ - use std::path::PathBuf; - // hello.txt - let target_name: PathBuf = base64_decode("aGVsbG8udHh0").into(); - SUBPLOT_EMBEDDED_FILES - .iter() - .find(|df| df.name() == target_name) - .expect("Unable to find file at runtime") - .clone() - }) - .build(); + .embedded_file( + + { + use std::path::PathBuf; + // hello.txt + let target_name: PathBuf = base64_decode("aGVsbG8udHh0").into(); + SUBPLOT_EMBEDDED_FILES + .iter() + .find(|df| df.name() == target_name) + .expect("Unable to find file at runtime") + .clone() + } + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::file_exists::Builder::default() - .filename( + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::file_contains::Builder::default() - .filename( + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" ) - .data( + ) + .data( + // "hello, world" - &base64_decode("aGVsbG8sIHdvcmxk"), + &base64_decode("aGVsbG8sIHdvcmxk" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::file_does_not_exist::Builder::default() - .filename( + .filename( + // "other.txt" - &base64_decode("b3RoZXIudHh0"), + &base64_decode("b3RoZXIudHh0" + ) ) - .build(); + .build(); scenario.add_step(step, None); - - let step = - subplotlib::steplibrary::files::create_from_embedded_with_other_name::Builder::default() - .filename_on_disk( - // "other.txt" - &base64_decode("b3RoZXIudHh0"), - ) - .embedded_file({ + + let step = subplotlib::steplibrary::files::create_from_embedded_with_other_name::Builder::default() + .filename_on_disk( + + // "other.txt" + &base64_decode("b3RoZXIudHh0" + ) + ) + .embedded_file( + + { use std::path::PathBuf; // hello.txt let target_name: PathBuf = base64_decode("aGVsbG8udHh0").into(); @@ -73,293 +93,369 @@ fn create_on_disk_files_from_embedded_files() { .find(|df| df.name() == target_name) .expect("Unable to find file at runtime") .clone() - }) - .build(); + } + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::file_exists::Builder::default() - .filename( + .filename( + // "other.txt" - &base64_decode("b3RoZXIudHh0"), + &base64_decode("b3RoZXIudHh0" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::file_match::Builder::default() - .filename1( + .filename1( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" + ) ) - .filename2( + .filename2( + // "other.txt" - &base64_decode("b3RoZXIudHh0"), + &base64_decode("b3RoZXIudHh0" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::only_these_exist::Builder::default() - .filenames( + .filenames( + // "hello.txt, other.txt" - &base64_decode("aGVsbG8udHh0LCBvdGhlci50eHQ="), + &base64_decode("aGVsbG8udHh0LCBvdGhlci50eHQ=" ) - .build(); + ) + .build(); scenario.add_step(step, None); + scenario.run().unwrap(); } + // --------------------------------- // File metadata #[test] fn file_metadata() { let mut scenario = Scenario::new(&base64_decode("RmlsZSBtZXRhZGF0YQ==")); - + let step = subplotlib::steplibrary::files::create_from_embedded::Builder::default() - .embedded_file({ - use std::path::PathBuf; - // hello.txt - let target_name: PathBuf = base64_decode("aGVsbG8udHh0").into(); - SUBPLOT_EMBEDDED_FILES - .iter() - .find(|df| df.name() == target_name) - .expect("Unable to find file at runtime") - .clone() - }) - .build(); + .embedded_file( + + { + use std::path::PathBuf; + // hello.txt + let target_name: PathBuf = base64_decode("aGVsbG8udHh0").into(); + SUBPLOT_EMBEDDED_FILES + .iter() + .find(|df| df.name() == target_name) + .expect("Unable to find file at runtime") + .clone() + } + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::remember_metadata::Builder::default() - .filename( + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::has_remembered_metadata::Builder::default() - .filename( + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::create_from_text::Builder::default() - .text( + .text( + // "yo" - &base64_decode("eW8="), + &base64_decode("eW8=" ) - .filename( + ) + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::has_different_metadata::Builder::default() - .filename( + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" + ) ) - .build(); + .build(); scenario.add_step(step, None); + scenario.run().unwrap(); } + // --------------------------------- // File modification time #[test] fn file_modification_time() { let mut scenario = Scenario::new(&base64_decode("RmlsZSBtb2RpZmljYXRpb24gdGltZQ==")); - + let step = subplotlib::steplibrary::files::touch_with_timestamp::Builder::default() - .filename( + .filename( + // "foo.dat" - &base64_decode("Zm9vLmRhdA=="), + &base64_decode("Zm9vLmRhdA==" ) - .mtime( + ) + .mtime( + // "1970-01-02 03:04:05" - &base64_decode("MTk3MC0wMS0wMiAwMzowNDowNQ=="), + &base64_decode("MTk3MC0wMS0wMiAwMzowNDowNQ==" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::mtime_is_ancient::Builder::default() - .filename( + .filename( + // "foo.dat" - &base64_decode("Zm9vLmRhdA=="), + &base64_decode("Zm9vLmRhdA==" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::touch::Builder::default() - .filename( + .filename( + // "foo.dat" - &base64_decode("Zm9vLmRhdA=="), + &base64_decode("Zm9vLmRhdA==" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::mtime_is_recent::Builder::default() - .filename( + .filename( + // "foo.dat" - &base64_decode("Zm9vLmRhdA=="), + &base64_decode("Zm9vLmRhdA==" ) - .build(); + ) + .build(); scenario.add_step(step, None); + scenario.run().unwrap(); } + // --------------------------------- // File contents #[test] fn file_contents() { let mut scenario = Scenario::new(&base64_decode("RmlsZSBjb250ZW50cw==")); - + let step = subplotlib::steplibrary::files::create_from_embedded::Builder::default() - .embedded_file({ - use std::path::PathBuf; - // hello.txt - let target_name: PathBuf = base64_decode("aGVsbG8udHh0").into(); - SUBPLOT_EMBEDDED_FILES - .iter() - .find(|df| df.name() == target_name) - .expect("Unable to find file at runtime") - .clone() - }) - .build(); + .embedded_file( + + { + use std::path::PathBuf; + // hello.txt + let target_name: PathBuf = base64_decode("aGVsbG8udHh0").into(); + SUBPLOT_EMBEDDED_FILES + .iter() + .find(|df| df.name() == target_name) + .expect("Unable to find file at runtime") + .clone() + } + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::file_contains::Builder::default() - .filename( + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" ) - .data( + ) + .data( + // "hello, world" - &base64_decode("aGVsbG8sIHdvcmxk"), + &base64_decode("aGVsbG8sIHdvcmxk" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::file_matches_regex::Builder::default() - .filename( + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" + ) ) - .regex( + .regex( + // "hello, .*" - &base64_decode("aGVsbG8sIC4q"), + &base64_decode("aGVsbG8sIC4q" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::file_matches_regex::Builder::default() - .filename( + .filename( + // "hello.txt" - &base64_decode("aGVsbG8udHh0"), + &base64_decode("aGVsbG8udHh0" ) - .regex( + ) + .regex( + // "hello, .*" - &base64_decode("aGVsbG8sIC4q"), + &base64_decode("aGVsbG8sIC4q" + ) ) - .build(); + .build(); scenario.add_step(step, None); + scenario.run().unwrap(); } + // --------------------------------- // Directories #[test] fn directories() { let mut scenario = Scenario::new(&base64_decode("RGlyZWN0b3JpZXM=")); - + let step = subplotlib::steplibrary::files::make_directory::Builder::default() - .path( + .path( + // "first" - &base64_decode("Zmlyc3Q="), + &base64_decode("Zmlyc3Q=" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_exists::Builder::default() - .path( + .path( + // "first" - &base64_decode("Zmlyc3Q="), + &base64_decode("Zmlyc3Q=" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_is_empty::Builder::default() - .path( + .path( + // "first" - &base64_decode("Zmlyc3Q="), + &base64_decode("Zmlyc3Q=" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_does_not_exist::Builder::default() - .path( + .path( + // "second" - &base64_decode("c2Vjb25k"), + &base64_decode("c2Vjb25k" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::remove_directory::Builder::default() - .path( + .path( + // "first" - &base64_decode("Zmlyc3Q="), + &base64_decode("Zmlyc3Q=" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_does_not_exist::Builder::default() - .path( + .path( + // "first" - &base64_decode("Zmlyc3Q="), + &base64_decode("Zmlyc3Q=" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::make_directory::Builder::default() - .path( + .path( + // "second" - &base64_decode("c2Vjb25k"), + &base64_decode("c2Vjb25k" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_exists::Builder::default() - .path( + .path( + // "second" - &base64_decode("c2Vjb25k"), + &base64_decode("c2Vjb25k" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_is_empty::Builder::default() - .path( + .path( + // "second" - &base64_decode("c2Vjb25k"), + &base64_decode("c2Vjb25k" + ) ) - .build(); + .build(); scenario.add_step(step, None); - - let step = - subplotlib::steplibrary::files::create_from_embedded_with_other_name::Builder::default() - .filename_on_disk( - // "second/third/hello.txt" - &base64_decode("c2Vjb25kL3RoaXJkL2hlbGxvLnR4dA=="), - ) - .embedded_file({ + + let step = subplotlib::steplibrary::files::create_from_embedded_with_other_name::Builder::default() + .filename_on_disk( + + // "second/third/hello.txt" + &base64_decode("c2Vjb25kL3RoaXJkL2hlbGxvLnR4dA==" + ) + ) + .embedded_file( + + { use std::path::PathBuf; // hello.txt let target_name: PathBuf = base64_decode("aGVsbG8udHh0").into(); @@ -368,49 +464,62 @@ fn directories() { .find(|df| df.name() == target_name) .expect("Unable to find file at runtime") .clone() - }) - .build(); + } + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_is_not_empty::Builder::default() - .path( + .path( + // "second" - &base64_decode("c2Vjb25k"), + &base64_decode("c2Vjb25k" ) - .build(); + ) + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_exists::Builder::default() - .path( + .path( + // "second/third" - &base64_decode("c2Vjb25kL3RoaXJk"), + &base64_decode("c2Vjb25kL3RoaXJk" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_is_not_empty::Builder::default() - .path( + .path( + // "second/third" - &base64_decode("c2Vjb25kL3RoaXJk"), + &base64_decode("c2Vjb25kL3RoaXJk" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::remove_directory::Builder::default() - .path( + .path( + // "second" - &base64_decode("c2Vjb25k"), + &base64_decode("c2Vjb25k" + ) ) - .build(); + .build(); scenario.add_step(step, None); - + let step = subplotlib::steplibrary::files::path_does_not_exist::Builder::default() - .path( + .path( + // "second" - &base64_decode("c2Vjb25k"), + &base64_decode("c2Vjb25k" + ) ) - .build(); + .build(); scenario.add_step(step, None); + scenario.run().unwrap(); } + |