lib: RepoCheckoutAtOptions

This commit is contained in:
Felix Krull authored and Colin Walters committed 2022-05-06 12:53:54 -04:00
1 parent 16718eb155
commit eec4a2287d
7 files changed
+254 -13

No files matched your search

+52 -8
View File
@@ -1,5 +1,6 @@
extern crate gio;
extern crate glib;
extern crate openat;
extern crate ostree;
extern crate tempfile;
#[macro_use]
@@ -11,7 +12,10 @@ use util::*;
use gio::prelude::*;
use gio::NONE_CANCELLABLE;
use glib::prelude::*;
use ostree::{ObjectName, ObjectType};
use ostree::{
ObjectName, ObjectType, RepoCheckoutAtOptions, RepoCheckoutMode, RepoCheckoutOverwriteMode,
};
use std::os::unix::io::AsRawFd;
#[test]
fn should_commit_content_to_repo_and_list_refs_again() {
@@ -91,11 +95,51 @@ fn should_checkout_tree() {
)
.expect("checkout tree");
let testfile_path = checkout_dir
.path()
.join("test-checkout")
.join("testdir")
.join("testfile");
let testfile_contents = std::fs::read_to_string(testfile_path).expect("test file");
assert_eq!("test\n", testfile_contents);
assert_test_file(checkout_dir.path());
}
#[test]
fn should_checkout_at_with_none_options() {
let test_repo = TestRepo::new();
let checksum = test_repo.test_commit("test");
let checkout_dir = tempfile::tempdir().expect("checkout dir");
let dirfd = openat::Dir::open(checkout_dir.path()).expect("openat");
test_repo
.repo
.checkout_at(
None,
dirfd.as_raw_fd(),
"test-checkout",
&checksum,
NONE_CANCELLABLE,
)
.expect("checkout at");
assert_test_file(checkout_dir.path());
}
#[test]
fn should_checkout_at_with_options() {
let test_repo = TestRepo::new();
let checksum = test_repo.test_commit("test");
let checkout_dir = tempfile::tempdir().expect("checkout dir");
let dirfd = openat::Dir::open(checkout_dir.path()).expect("openat");
test_repo
.repo
.checkout_at(
Some(&RepoCheckoutAtOptions {
mode: RepoCheckoutMode::User,
overwrite_mode: RepoCheckoutOverwriteMode::UnionIdentical,
..Default::default()
}),
dirfd.as_raw_fd(),
"test-checkout",
&checksum,
NONE_CANCELLABLE,
)
.expect("checkout at");
assert_test_file(checkout_dir.path());
}
+9
View File
@@ -64,3 +64,12 @@ pub fn commit(repo: &ostree::Repo, mtree: &ostree::MutableTree, ref_: &str) -> G
.expect("commit transaction");
checksum
}
pub fn assert_test_file(checkout: &Path) {
let testfile_path = checkout
.join("test-checkout")
.join("testdir")
.join("testfile");
let testfile_contents = std::fs::read_to_string(testfile_path).expect("test file");
assert_eq!("test\n", testfile_contents);
}