Add a few simple integration tests

This commit is contained in:
2021-11-21 22:00:18 +01:00
parent ca1f649ecf
commit 78a957268d
5 changed files with 121 additions and 1 deletions

11
tests/helpers.rs Normal file
View File

@@ -0,0 +1,11 @@
use tempdir::TempDir;
pub fn init_tmpdir() -> TempDir {
let tmp_dir = TempDir::new("grm-test").unwrap();
println!("Temporary directory: {}", tmp_dir.path().display());
tmp_dir
}
pub fn cleanup_tmpdir(tempdir: TempDir) {
tempdir.close().unwrap();
}

43
tests/repo.rs Normal file
View File

@@ -0,0 +1,43 @@
use grm::repo::*;
mod helpers;
use helpers::*;
#[test]
fn open_empty_repo() {
let tmpdir = init_tmpdir();
assert!(matches!(
open_repo(tmpdir.path(), true),
Err(RepoError {
kind: RepoErrorKind::NotFound
})
));
assert!(matches!(
open_repo(tmpdir.path(), false),
Err(RepoError {
kind: RepoErrorKind::NotFound
})
));
cleanup_tmpdir(tmpdir);
}
#[test]
fn create_repo() -> Result<(), Box<dyn std::error::Error>> {
let tmpdir = init_tmpdir();
let repo = init_repo(tmpdir.path(), false)?;
assert!(!repo.is_bare());
assert!(repo.is_empty()?);
cleanup_tmpdir(tmpdir);
Ok(())
}
#[test]
fn create_repo_with_worktree() -> Result<(), Box<dyn std::error::Error>> {
let tmpdir = init_tmpdir();
let repo = init_repo(tmpdir.path(), true)?;
assert!(repo.is_bare());
assert!(repo.is_empty()?);
cleanup_tmpdir(tmpdir);
Ok(())
}