~gbmor/clinte

40bb48bb701f88c902b912fb51fea88b5ae9a8b8 — Ben Morrison 1 year, 3 days ago c4c9412
test for hashing bits
1 files changed, 23 insertions(+), 0 deletions(-)

M src/db.rs
M src/db.rs => src/db.rs +23 -0
@@ 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);
    }
}