diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-05-03 10:44:26 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-05-03 11:23:38 +0300 |
commit | 3d50e1497dd07929655636cfea0c48ccadd3ab8e (patch) | |
tree | 69770791ebb26ebbce6137ea481e85f19ec35041 /src/generation.rs | |
parent | 856d32c448a87245234315462d2190c5a9aab549 (diff) | |
download | obnam2-3d50e1497dd07929655636cfea0c48ccadd3ab8e.tar.gz |
test: add test for storing, retrieving u64::MAX values in JSON
The test passes. We create a FilesystemEntry with a length field
containing u64::MAX, store that into a generation, and read it back.
This works. The entry is serialised into JSON for storing in SQLite,
and this proves we can handle any u64 value in an entry. serde_json
deals with it fine, and we don't need to worry about it.
Sponsored-by: author
Diffstat (limited to 'src/generation.rs')
-rw-r--r-- | src/generation.rs | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/generation.rs b/src/generation.rs index 180efbe..cec3d14 100644 --- a/src/generation.rs +++ b/src/generation.rs @@ -296,8 +296,44 @@ impl LocalGeneration { #[cfg(test)] mod test { - use super::{LabelChecksumKind, LocalGeneration, NascentGeneration, SchemaVersion}; - use tempfile::NamedTempFile; + use super::{LabelChecksumKind, LocalGeneration, NascentGeneration, Reason, SchemaVersion}; + use crate::fsentry::FilesystemEntry; + use crate::fsentry::FilesystemKind; + use std::path::Path; + 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 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 mut gen = + NascentGeneration::create(&filename, schema, LabelChecksumKind::Sha256).unwrap(); + gen.insert(e, &[], Reason::IsNew, false).unwrap(); + gen.close().unwrap(); + } + + let db = LocalGeneration::open(&filename).unwrap(); + let e = db.get_file(Path::new("/")).unwrap().unwrap(); + assert_eq!(e.len(), u64::MAX); + } #[test] fn empty() { |