summaryrefslogtreecommitdiff
path: root/tests/inst/src/sysroot.rs
blob: 301ef8b31d6cc93cbc2621e47c14344f58c498f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Tests that mostly use the API and access the booted sysroot read-only.

use anyhow::Result;
use ostree_ext::prelude::*;
use ostree_ext::{gio, ostree};

use crate::test::*;

fn skip_non_ostree_host() -> bool {
    !std::path::Path::new("/run/ostree-booted").exists()
}

#[itest]
fn test_sysroot_ro() -> Result<()> {
    // TODO add a skipped identifier
    if skip_non_ostree_host() {
        return Ok(());
    }
    let cancellable = Some(gio::Cancellable::new());
    let sysroot = ostree::Sysroot::new_default();
    sysroot.load(cancellable.as_ref())?;
    assert!(sysroot.is_booted());

    let booted = sysroot.booted_deployment().expect("booted deployment");
    assert!(!booted.is_staged());
    let repo = sysroot.repo().expect("repo");

    let csum = booted.csum().expect("booted csum");
    let csum = csum.as_str();

    let (root, rev) = repo.read_commit(csum, cancellable.as_ref())?;
    assert_eq!(rev, csum);
    let root = root.downcast::<ostree::RepoFile>().expect("downcast");
    root.ensure_resolved()?;

    Ok(())
}

#[itest]
fn test_immutable_bit() -> Result<()> {
    if skip_non_ostree_host() {
        return Ok(());
    }
    // https://bugzilla.redhat.com/show_bug.cgi?id=1867601
    cmd_has_output(sh_inline::bash_command!("lsattr -d /").unwrap(), "-i-")?;
    Ok(())
}