Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muhamadazmy committed Sep 21, 2023
1 parent 86ed118 commit 7b973e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 45 deletions.
29 changes: 1 addition & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ serde_json = "1.0"
sha2 = "0.10"
aes-gcm = "0.10"
hex = "0.4"
lazy_static = "1.4"
# next are only needed for the binarys
simple_logger = {version = "1.0.1", optional = true}
daemonize = { version = "0.5", optional = true }
Expand All @@ -67,7 +68,6 @@ optional = true
[dev-dependencies]
reqwest = { version = "0.11", features = ["blocking"] }
assert_cmd = "2.0"
rand = "0.8"

[profile.release]
lto = true
Expand Down
28 changes: 12 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,8 @@ mod test {
fungi::meta,
store::{dir::DirStore, Router},
};
use rand::Rng;
use std::path::PathBuf;
use tokio::fs;
use tokio::io::AsyncWriteExt;
use tokio::{fs, io::AsyncReadExt};

#[tokio::test]
async fn pack_unpack() {
Expand All @@ -236,10 +234,14 @@ mod test {
let source = root.join("source");
fs::create_dir_all(&source).await.unwrap();

let mut buffer: [u8; 1024] = [0; 1024];
let mut rng = rand::thread_rng();
// generate random files.
for size in [0, 100 * 1024, 1024 * 1024, 10 * 1024 * 1024] {
let mut urandom = fs::OpenOptions::default()
.read(true)
.open("/dev/urandom")
.await
.unwrap()
.take(size);

let name = format!("file-{}.rnd", size);
let p = source.join(&name);
let mut file = fs::OpenOptions::default()
Expand All @@ -249,18 +251,10 @@ mod test {
.await
.unwrap();

let mut filled = 0;
// fill it with random data
loop {
rng.fill(&mut buffer);
file.write_all(&buffer).await.unwrap();
filled += buffer.len();
if filled >= size {
break;
}
}
tokio::io::copy(&mut urandom, &mut file).await.unwrap();
}

println!("file generation complete");
let writer = meta::Writer::new(root.join("meta.fl")).await.unwrap();

// while we at it we can already create 2 stores and create a router store on top
Expand All @@ -274,6 +268,7 @@ mod test {

pack(writer, store, &source).await.unwrap();

println!("packing complete");
// recreate the stores for reading.
let store0 = DirStore::new(root.join("store0")).await.unwrap();
let store1 = DirStore::new(root.join("store1")).await.unwrap();
Expand All @@ -298,6 +293,7 @@ mod test {
.await
.unwrap();

println!("unpacking complete");
// compare that source directory is exactly the same as target directory
let status = std::process::Command::new("diff")
.arg(root.join("source"))
Expand Down

0 comments on commit 7b973e2

Please sign in to comment.