summaryrefslogtreecommitdiff
path: root/src/generation.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-05-03 11:22:23 +0300
committerLars Wirzenius <liw@liw.fi>2022-05-03 11:25:46 +0300
commit4913347201f4d00ccaf959c53357241d5bc3f9e0 (patch)
treeb04294a85b4bcfb540107e39490018e8f42d5a6f /src/generation.rs
parent3d50e1497dd07929655636cfea0c48ccadd3ab8e (diff)
downloadobnam2-4913347201f4d00ccaf959c53357241d5bc3f9e0.tar.gz
refactor: add a builder for file system entries
The previous commit introduced a function to create FilesystemEntry values from arbitrary data. Previously one could only be created from std::fs::Metadata. This complicated our own testing, which (now) needs to construct an arbitrary entry structure. However, while the function added in the last commit was straightforward, it had 11 arguments, and that's hard to keep track of. Replace that function with an EntryBuilder struct, for clarity. Sponsored-by: author
Diffstat (limited to 'src/generation.rs')
-rw-r--r--src/generation.rs27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/generation.rs b/src/generation.rs
index cec3d14..477edc0 100644
--- a/src/generation.rs
+++ b/src/generation.rs
@@ -297,33 +297,22 @@ impl LocalGeneration {
#[cfg(test)]
mod test {
use super::{LabelChecksumKind, LocalGeneration, NascentGeneration, Reason, SchemaVersion};
- use crate::fsentry::FilesystemEntry;
+ use crate::fsentry::EntryBuilder;
use crate::fsentry::FilesystemKind;
- use std::path::Path;
+ use std::path::PathBuf;
use tempfile::{tempdir, NamedTempFile};
- use users::UsersCache;
#[test]
fn round_trips_u64_max() {
let tmp = tempdir().unwrap();
let filename = tmp.path().join("test.db");
- let mut cache = UsersCache::new();
+ let path = PathBuf::from("/");
let schema = SchemaVersion::new(0, 0);
{
- let e = FilesystemEntry::new(
- Path::new("/"),
- FilesystemKind::Directory,
- 0,
- 0,
- u64::MAX,
- 0,
- 0,
- 0,
- 0,
- 0,
- &mut cache,
- )
- .unwrap();
+ let e = EntryBuilder::new(FilesystemKind::Directory)
+ .path(path.clone())
+ .len(u64::MAX)
+ .build();
let mut gen =
NascentGeneration::create(&filename, schema, LabelChecksumKind::Sha256).unwrap();
gen.insert(e, &[], Reason::IsNew, false).unwrap();
@@ -331,7 +320,7 @@ mod test {
}
let db = LocalGeneration::open(&filename).unwrap();
- let e = db.get_file(Path::new("/")).unwrap().unwrap();
+ let e = db.get_file(&path).unwrap().unwrap();
assert_eq!(e.len(), u64::MAX);
}