Skip to content

Commit c44cd5a

Browse files
committed
test: add test for discard_status
1 parent bc3656f commit c44cd5a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

asyncgit/src/sync/status.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,34 @@ pub fn discard_status(repo_path: &RepoPath) -> Result<bool> {
215215

216216
Ok(true)
217217
}
218+
219+
#[cfg(test)]
220+
mod tests {
221+
use super::*;
222+
use crate::sync::tests::repo_init;
223+
use std::{fs::File, io::Write, path::Path};
224+
225+
#[test]
226+
fn test_discard_status() {
227+
let file_path = Path::new("foo");
228+
let (_td, repo) = repo_init().unwrap();
229+
let root = repo.path().parent().unwrap();
230+
let repo_path: &RepoPath =
231+
&root.as_os_str().to_str().unwrap().into();
232+
233+
File::create(root.join(file_path))
234+
.unwrap()
235+
.write_all(b"test\nfoo")
236+
.unwrap();
237+
238+
let statuses = get_status(repo_path, StatusType::WorkingDir, None)
239+
.unwrap();
240+
assert_eq!(statuses.len(), 1);
241+
242+
discard_status(repo_path).unwrap();
243+
244+
let statuses = get_status(repo_path, StatusType::WorkingDir, None)
245+
.unwrap();
246+
assert_eq!(statuses.len(), 0);
247+
}
248+
}

0 commit comments

Comments
 (0)