mirror of
https://github.com/Prominence/rshred.git
synced 2026-07-03 02:36:45 +03:00
Initial setup for integration tests.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
pub const PLAIN_FILE_CONTENT: &str = "some sensitive data";
|
||||
|
||||
pub const TEST_FILE: &str = "target/test/test.txt";
|
||||
const TEST_DIR: &str = "target/test";
|
||||
|
||||
pub fn setup() {
|
||||
std::fs::create_dir_all(TEST_DIR).unwrap();
|
||||
let mut file = File::create("target/test/test.txt").unwrap();
|
||||
file.write(PLAIN_FILE_CONTENT.as_bytes()).unwrap();
|
||||
}
|
||||
|
||||
pub fn cleanup() {
|
||||
std::fs::remove_file(TEST_FILE).unwrap();
|
||||
std::fs::remove_dir(TEST_DIR).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
extern crate rshred;
|
||||
|
||||
use ntest::timeout;
|
||||
use ntest::assert_false;
|
||||
|
||||
mod common;
|
||||
|
||||
#[test]
|
||||
#[timeout(1000)]
|
||||
fn test_basic_shredding() {
|
||||
common::setup();
|
||||
|
||||
let initial_file_length = std::fs::metadata(common::TEST_FILE).unwrap().len();
|
||||
|
||||
let options = rshred::ShredOptions::new(common::TEST_FILE.to_string())
|
||||
.set_verbosity(rshred::Verbosity::None)
|
||||
.set_is_interactive(false)
|
||||
.set_keep_files(true)
|
||||
.build();
|
||||
rshred::Shredder::with_options(options).run();
|
||||
|
||||
let shredded_file_length = std::fs::metadata(common::TEST_FILE).unwrap().len();
|
||||
// file's size hasn't changed
|
||||
assert_eq!(initial_file_length, shredded_file_length);
|
||||
|
||||
// file's content will become an invalid UTF-8 string
|
||||
assert_false!(std::fs::read_to_string(common::TEST_FILE).is_ok());
|
||||
|
||||
common::cleanup();
|
||||
}
|
||||
Reference in New Issue
Block a user