Skip to main content

standing

Function standing 

Source
pub fn standing(
    root: &Path,
    expected: &str,
    only: Option<&str>,
    git: &dyn Ancestry,
) -> ServedStanding
Expand description

The standing of every recorded deployment against expected. Public so that a consumer that judges an intent’s deployment criterion reads the same derivation as this read.

use majordomus_cli::capability::builtin::served::standing;
use majordomus_cli::served::{append, observe, Ancestry, Fetch, Fetched, ServedVerdict};
use std::time::SystemTime;
struct Linear;  // a <- b
impl Ancestry for Linear {
    fn has(&self, c: &str) -> Option<bool> { Some(c.starts_with('a') || c.starts_with('b')) }
    fn contains(&self, d: &str, a: &str) -> Option<bool> { Some(d >= a) }
}
struct Serves(String);
impl Fetch for Serves {
    fn fetch(&self, _: &str) -> Fetched {
        Fetched::Body(format!(r#"{{"commit":"{}","dirty":false}}"#, self.0).into_bytes())
    }
}
let (a, b) = ("a".repeat(40), "b".repeat(40));
let dir = tempfile::tempdir().unwrap();
let o = observe("pages", "https://s", "build.json", &a, &Serves(a.clone()), &Linear,
                SystemTime::UNIX_EPOCH);
append(dir.path(), &o).unwrap();

// the record still proves the commit it was taken against ...
let now = standing(dir.path(), &a, None, &Linear);
assert_eq!(now.deployments[0].now.verdict, ServedVerdict::Served);
// ... and stops proving once the commit asked about moves past it
let later = standing(dir.path(), &b, None, &Linear);
assert_eq!(later.deployments[0].now.verdict, ServedVerdict::Stale);