fix: Wrap Write and Read functions with results

This commit is contained in:
2023-10-24 23:54:58 +02:00
parent c68cdb3b60
commit fd0439aa44
2 changed files with 30 additions and 19 deletions

View File

@@ -1,7 +1,10 @@
#[cfg(test)]
mod tests {
use std::{thread::{self}, time::{self, Duration}};
use rustysearch::{types::Stats, search::Rustysearch};
const TEN_MILLIS: Duration = time::Duration::from_millis(100);
#[test]
fn test_write_new_stats(){
let stats = Stats{
@@ -15,7 +18,8 @@ mod tests {
let search = Rustysearch::new("/tmp/rustysearch");
search.setup();
search.write_stats(stats);
search.write_stats(stats).unwrap();
thread::sleep(TEN_MILLIS);
}
#[test]
@@ -25,9 +29,10 @@ mod tests {
clean_stats();
let stats = search.read_stats();
let stats = search.read_stats().unwrap();
assert_eq!(stats.version, "0.1.0");
assert_eq!(stats.total_docs, 0);
thread::sleep(TEN_MILLIS);
}
#[test]
@@ -37,12 +42,13 @@ mod tests {
clean_stats();
let stats = search.read_stats();
let stats = search.read_stats().unwrap();
assert_eq!(stats.total_docs, 0);
search.increment_total_docs();
let stats = search.read_stats();
let stats = search.read_stats().unwrap();
assert_eq!(stats.total_docs, 1);
thread::sleep(TEN_MILLIS);
}
#[test]
@@ -52,15 +58,16 @@ mod tests {
clean_stats();
let stats = search.read_stats();
let stats = search.read_stats().unwrap();
assert_eq!(stats.total_docs, 0);
search.increment_total_docs();
let stats = search.read_stats();
let stats = search.read_stats().unwrap();
assert_eq!(stats.total_docs, 1);
let total_docs = search.get_total_docs();
assert_eq!(total_docs, 1);
thread::sleep(TEN_MILLIS);
}
fn clean_stats(){
@@ -71,6 +78,7 @@ mod tests {
version: String::from("0.1.0"),
total_docs: 0,
};
search.write_stats(new_stats);
search.write_stats(new_stats).unwrap();
thread::sleep(TEN_MILLIS);
}
}