Browse Source

Add and fix tests

develop
Olivier 'reivilibre' 2 weeks ago
parent
commit
1b1910fcf2
  1. 7
      Cargo.lock
  2. 4
      Cargo.toml
  3. 29
      src/pile/local_sqlitebloblogs.rs

7
Cargo.lock

@ -1019,6 +1019,12 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "temp-dir"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af547b166dd1ea4b472165569fc456cfb6818116f854690b0ff205e636523dab"
[[package]]
name = "termcolor"
version = "1.1.0"
@ -1247,6 +1253,7 @@ dependencies = [
"sled",
"sodiumoxide",
"sshish",
"temp-dir",
"thiserror",
"toml",
"twox-hash",

4
Cargo.toml

@ -36,3 +36,7 @@ rayon = "1.5.0"
rusqlite = "0.24.2"
chrono = "0.4.19"
rustyline = "7.1.0"
[dev-dependencies]
temp-dir = "0.1.11"

29
src/pile/local_sqlitebloblogs.rs

@ -61,6 +61,8 @@ impl Bloblog {
chunk_id: &ChunkId,
buf: &mut Vec<u8>,
) -> anyhow::Result<()> {
buf.clear();
self.file.seek(SeekFrom::Start(offset))?;
let mut chunk_id_verif_buf: ChunkId = Default::default();
self.file.read_exact(&mut chunk_id_verif_buf)?;
@ -459,3 +461,30 @@ impl Iterator for KeyIterator {
}
}
}
#[cfg(test)]
mod tests {
use temp_dir::TempDir;
use crate::pile::local_sqlitebloblogs::Bloblog;
#[test]
pub fn bloblog_read_write_test() {
let td = TempDir::new().unwrap();
let path = td.path();
let mut bloblog = Bloblog::open(path.join("bloblog1.log").as_ref()).unwrap();
let bloblog_id_1 = bloblog.write_blob(&Default::default(), &[1, 2, 3]).unwrap();
let bloblog_id_2 = bloblog.write_blob(&Default::default(), &[4, 5]).unwrap();
drop(bloblog);
let mut bloblog = Bloblog::open(path.join("bloblog1.log").as_ref()).unwrap();
let mut vec = Vec::new();
bloblog.read_blob(bloblog_id_2, &Default::default(), &mut vec).unwrap();
assert_eq!(&vec, &[4, 5]);
bloblog.read_blob(bloblog_id_1, &Default::default(), &mut vec).unwrap();
assert_eq!(&vec, &[1, 2, 3]);
}
}
Loading…
Cancel
Save