From 9296dffe28f178c3611d4379d41876fcd507b1c8 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 4 Nov 2017 16:21:33 -0700 Subject: clarify and test sleep indexing --- src/sleep_register.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/sleep_register.rs b/src/sleep_register.rs index 7d2d38e..c169cbb 100644 --- a/src/sleep_register.rs +++ b/src/sleep_register.rs @@ -29,7 +29,8 @@ pub trait HyperRegister { /// Reads a single data entry from the store. fn get_data_entry(&mut self, entry_index: u64) -> Result>; - /// Writes an entry to the store. Requires the private key to be present. + /// Writes an entry to the store. Requires the private key to be present. Returns the entry + /// index written to. fn append(&mut self, data: &[u8]) -> Result; /// Count of data entries for this register. This is the total count (highest entry index plus @@ -597,14 +598,16 @@ fn test_sdr_append() { let tmp_dir = TempDir::new("geniza-test").unwrap(); let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap(); - sdr.append("hello world!".as_bytes()).unwrap(); + let index = sdr.append("hello world!".as_bytes()).unwrap(); + assert_eq!(index, 0); assert!(sdr.check().is_ok()); assert!(sdr.verify().is_ok()); assert_eq!(sdr.len().unwrap(), 1); assert_eq!(sdr.len_bytes().unwrap(), 12); let count = 100; // TODO: make this >1000 when things are faster - for _ in 0..count { - sdr.append(&[1, 2, 3, 4, 5]).unwrap(); + for i in 0..count { + let index = sdr.append(&[1, 2, 3, 4, 5]).unwrap(); + assert_eq!(index, i+1); } assert!(sdr.check().is_ok()); assert!(sdr.verify().is_ok()); -- cgit v1.2.3