From 0657da58db7d7514d9906e8a8ec9d6d267f04276 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 5 Apr 2020 15:39:02 +0200 Subject: [PATCH] unittest for commiting --- asyncgit/src/sync/utils.rs | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index 4ff8a7a2..66942839 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -82,3 +82,43 @@ pub fn stage_add(repo_path: &str, path: &Path) -> bool { false } + +#[cfg(test)] +mod tests { + use super::*; + use crate::sync::{ + stage_add, + status::{get_status, StatusType}, + tests::repo_init, + }; + use std::{fs::File, io::Write, path::Path}; + + #[test] + fn test_commit() { + let file_path = Path::new("foo"); + let (_td, repo) = repo_init(); + let root = repo.path().parent().unwrap(); + let repo_path = root.as_os_str().to_str().unwrap(); + + let status_count = |s: StatusType| -> usize { + get_status(repo_path, s).len() + }; + + File::create(&root.join(file_path)) + .unwrap() + .write_all(b"test\nfoo") + .unwrap(); + + assert_eq!(status_count(StatusType::WorkingDir), 1); + + assert_eq!(stage_add(repo_path, file_path), true); + + assert_eq!(status_count(StatusType::WorkingDir), 0); + assert_eq!(status_count(StatusType::Stage), 1); + + commit(repo_path, "commit msg"); + + assert_eq!(status_count(StatusType::Stage), 0); + assert_eq!(status_count(StatusType::WorkingDir), 0); + } +}