From 1f55c18945b85c89178778a984b1e6a646c37a6e Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 11 Oct 2020 13:20:50 +0200 Subject: [PATCH] add unittests for checkout --- asyncgit/src/sync/branch.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/asyncgit/src/sync/branch.rs b/asyncgit/src/sync/branch.rs index 64b2f8b2..5a99344b 100644 --- a/asyncgit/src/sync/branch.rs +++ b/asyncgit/src/sync/branch.rs @@ -219,3 +219,38 @@ mod tests_branches { ); } } + +#[cfg(test)] +mod tests_checkout { + use super::*; + use crate::sync::tests::repo_init; + + #[test] + fn test_smoke() { + let (_td, repo) = repo_init().unwrap(); + let root = repo.path().parent().unwrap(); + let repo_path = root.as_os_str().to_str().unwrap(); + + assert!( + checkout_branch(repo_path, "refs/heads/master").is_ok() + ); + assert!( + checkout_branch(repo_path, "refs/heads/foobar").is_err() + ); + } + + #[test] + fn test_multiple() { + let (_td, repo) = repo_init().unwrap(); + let root = repo.path().parent().unwrap(); + let repo_path = root.as_os_str().to_str().unwrap(); + + create_branch(repo_path, "test").unwrap(); + + assert!(checkout_branch(repo_path, "refs/heads/test").is_ok()); + assert!( + checkout_branch(repo_path, "refs/heads/master").is_ok() + ); + assert!(checkout_branch(repo_path, "refs/heads/test").is_ok()); + } +}