Add a few simple integration tests
This commit is contained in:
11
tests/helpers.rs
Normal file
11
tests/helpers.rs
Normal 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
43
tests/repo.rs
Normal 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(())
|
||||
}
|
||||
Reference in New Issue
Block a user