Files
radicle-git/git-storage/t/src/tmp.rs
T
Jorge Iglesias Garcia f6b72dce85 git-storage: add ODB tests
We add tests for ODB functionality, as well as a new `TreeBuilder`
Struct to make building git trees easier (see below).

The `git2::TreeBuilder` can be a pain to use since it has a lifetime
that is tied to the `git2::Repository`. This was causing issues when
trying to write generators for property tests.

Instead, define a custom TreeBuilder which is a defunctionalised list
operations that represent the `insert` and `remove` methods on
`git2::TreeBuilder`.

The implementation of writing a tree then becomes converting the
custom `TreeBuilder` into a `git2::TreeBuilder`.

Signed-off-by: Jorge Iglesias Garcia <me@jorgeig.com>
2022-10-24 16:52:56 +08:00

15 lines
413 B
Rust

use git2::Repository;
use git_storage::{signature::UserInfo, Write};
use test_helpers::tempdir::WithTmpDir;
pub type TmpWriter = WithTmpDir<Write>;
pub type TmpRepo = WithTmpDir<Repository>;
pub fn writer(user: UserInfo) -> TmpWriter {
WithTmpDir::new(|path| {
Write::open(path, user)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("{}", e)))
})
.unwrap()
}