ostree/rust-bindings/rust/tests/repo/checkout_at.rs

109 lines
3.3 KiB
Rust
Raw Normal View History

use crate::util::*;
use gio::NONE_CANCELLABLE;
use ostree::*;
2019-05-26 20:18:12 +03:00
use std::os::unix::io::AsRawFd;
#[test]
2019-05-26 20:18:12 +03:00
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());
}
2019-05-31 21:02:02 +03:00
#[test]
fn should_checkout_at_with_default_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::default()),
dirfd.as_raw_fd(),
"test-checkout",
&checksum,
NONE_CANCELLABLE,
)
.expect("checkout at");
assert_test_file(checkout_dir.path());
}
2019-05-26 20:18:12 +03:00
#[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,
2019-05-31 21:02:02 +03:00
overwrite_mode: RepoCheckoutOverwriteMode::AddFiles,
enable_fsync: true,
force_copy: true,
force_copy_zerosized: true,
devino_to_csum_cache: Some(RepoDevInoCache::new()),
filter: repo_checkout_filter(|_repo, _path, _stat| RepoCheckoutFilterResult::Allow),
2019-05-26 20:18:12 +03:00
..Default::default()
}),
dirfd.as_raw_fd(),
"test-checkout",
&checksum,
NONE_CANCELLABLE,
)
.expect("checkout at");
assert_test_file(checkout_dir.path());
2019-05-25 01:59:22 +03:00
}
#[test]
fn should_checkout_at_with_filter() {
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 {
filter: repo_checkout_filter(|_repo, path, _stat| {
if let Some("testfile") = path.file_name().map(|s| s.to_str().unwrap()) {
RepoCheckoutFilterResult::Skip
} else {
RepoCheckoutFilterResult::Allow
}
}),
..Default::default()
}),
dirfd.as_raw_fd(),
"test-checkout",
&checksum,
NONE_CANCELLABLE,
)
.expect("checkout at");
let testdir = checkout_dir.path().join("test-checkout").join("testdir");
assert!(std::fs::read_dir(&testdir).is_ok());
assert!(std::fs::File::open(&testdir.join("testfile")).is_err());
}