Skip to content

Commit

Permalink
Fix rpm test (#43)
Browse files Browse the repository at this point in the history
* Update db.rs

* Update db.rs

* Update db.rs
  • Loading branch information
wiiznokes authored Jun 18, 2024
1 parent cf45649 commit d521b32
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
utils,
};

type TimeId = i64; // maybe add some randomness at the end
type TimeId = i64; // maybe add some randomness at the end https://github.com/dylanhart/ulid-rs

const DB_PATH: &str = "clipboard-manager-db-1.sqlite";

Expand Down Expand Up @@ -409,6 +409,7 @@ mod test {
fs::{self, File},
io::{Read, Write},
path::PathBuf,
thread::sleep,
time::Duration,
};

Expand Down Expand Up @@ -446,12 +447,16 @@ mod test {

assert!(db.len() == 1);

sleep(Duration::from_millis(1000));

let data = Data::new("text/plain".into(), "content".as_bytes().into());

db.insert(data).unwrap();

assert!(db.len() == 1);

sleep(Duration::from_millis(1000));

let data = Data::new("text/plain".into(), "content2".as_bytes().into());

db.insert(data.clone()).unwrap();
Expand All @@ -476,6 +481,8 @@ mod test {
let data = Data::new("text/plain".into(), "content".as_bytes().into());
db.insert(data).unwrap();

sleep(Duration::from_millis(100));

let data = Data::new("text/plain".into(), "content2".as_bytes().into());
db.insert(data).unwrap();

Expand Down Expand Up @@ -516,4 +523,33 @@ mod test {
db.insert(data).unwrap();
assert!(db.len() == 1);
}

// activate if we add randomness on the id.
// see https://github.com/dylanhart/ulid-rs
// #[test]
fn different_content_same_time() {
let db_path = PathBuf::from("tests/different_content_same_time");
let _ = fs::remove_file(&db_path);

let mut db = Db::inner_new(None, &db_path).unwrap();

let now = utils::now_millis();

let data = Data {
creation: now,
mime: "text/plain".into(),
content: "content".as_bytes().into(),
};

db.insert(data).unwrap();

let data = Data {
creation: now,
mime: "text/plain".into(),
content: "content2".as_bytes().into(),
};

db.insert(data).unwrap();
assert!(db.len() == 2);
}
}

0 comments on commit d521b32

Please sign in to comment.