Refactor tests and add test for traverse_commit
This commit is contained in:
1 parent
ff3e268a3b
commit
c89270969c
5 files changed
+131
-79
No files matched your search
@@ -0,0 +1,67 @@
|
||||
use gio::NONE_CANCELLABLE;
|
||||
use glib::prelude::*;
|
||||
use glib::GString;
|
||||
use ostree::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TestRepo {
|
||||
pub dir: tempfile::TempDir,
|
||||
pub repo: ostree::Repo,
|
||||
}
|
||||
|
||||
impl TestRepo {
|
||||
pub fn new() -> TestRepo {
|
||||
TestRepo::new_with_mode(ostree::RepoMode::BareUser)
|
||||
}
|
||||
|
||||
pub fn new_with_mode(repo_mode: ostree::RepoMode) -> TestRepo {
|
||||
let dir = tempfile::tempdir().expect("temp repo dir");
|
||||
let repo = ostree::Repo::new_for_path(dir.path());
|
||||
repo.create(repo_mode, NONE_CANCELLABLE)
|
||||
.expect("OSTree repo");
|
||||
TestRepo { dir, repo }
|
||||
}
|
||||
|
||||
pub fn test_commit(&self) -> GString {
|
||||
let mtree = create_mtree(&self.repo);
|
||||
commit(&self.repo, &mtree, "test")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_mtree(repo: &ostree::Repo) -> ostree::MutableTree {
|
||||
let mtree = ostree::MutableTree::new();
|
||||
let file = gio::File::new_for_path(
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("tests")
|
||||
.join("data")
|
||||
.join("test.tar"),
|
||||
);
|
||||
repo.write_archive_to_mtree(&file, &mtree, None, true, NONE_CANCELLABLE)
|
||||
.expect("test mtree");
|
||||
mtree
|
||||
}
|
||||
|
||||
pub fn commit(repo: &ostree::Repo, mtree: &ostree::MutableTree, ref_: &str) -> GString {
|
||||
repo.prepare_transaction(NONE_CANCELLABLE)
|
||||
.expect("prepare transaction");
|
||||
let repo_file = repo
|
||||
.write_mtree(mtree, NONE_CANCELLABLE)
|
||||
.expect("write mtree")
|
||||
.downcast::<ostree::RepoFile>()
|
||||
.unwrap();
|
||||
let checksum = repo
|
||||
.write_commit(
|
||||
None,
|
||||
"Test Commit".into(),
|
||||
None,
|
||||
None,
|
||||
&repo_file,
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.expect("write commit");
|
||||
repo.transaction_set_ref(None, ref_, checksum.as_str().into());
|
||||
repo.commit_transaction(NONE_CANCELLABLE)
|
||||
.expect("commit transaction");
|
||||
checksum
|
||||
}
|
||||
Reference in new issue
Block a user