diff options
author | Ben Morrison <ben@gbmor.dev> | 2020-06-16 19:16:49 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2020-06-16 19:16:49 -0400 |
commit | 40bb48bb701f88c902b912fb51fea88b5ae9a8b8 (patch) | |
tree | 978d48d1ef7734b2ca62e3dc59ad860ac7a76c3a | |
parent | c4c9412c3f459323f5acd91d4654d7ddae1526f0 (diff) | |
download | clinte-40bb48bb701f88c902b912fb51fea88b5ae9a8b8.tar.gz |
test for hashing bits
-rw-r--r-- | src/db.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/db.rs b/src/db.rs index c0e4cda..eeaa27a 100644 --- a/src/db.rs +++ b/src/db.rs @@ -68,7 +68,12 @@ impl Posts { hasher.update(body); let hash = format!("{:x}", hasher.finalize()); + #[cfg(test)] + let homedir = std::env::var("PWD")?; + + #[cfg(not(test))] let homedir = std::env::var("HOME")?; + let writepath = format!("{}/.clinte.sha256", homedir); fs::write(writepath, &hash)?; @@ -163,4 +168,22 @@ mod tests { all.delete(1); all.write(); } + + #[test] + fn check_hash() { + let strposts = fs::read_to_string(PATH).unwrap(); + let mut hasher = Sha256::new(); + hasher.update(strposts); + let rhs = format!("{:x}", hasher.finalize()); + + let all = Posts::get_all(PATH); + all.hash().unwrap(); + + let pwd = std::env::var("PWD").unwrap(); + let hashpath = format!("{}/.clinte.sha256", pwd); + let lhs = fs::read_to_string(hashpath.clone()).unwrap(); + fs::remove_file(hashpath).unwrap(); + + assert_eq!(lhs, rhs); + } } |