Skip to main content

resolve

Function resolve 

Source
pub fn resolve<'a>(
    ctx: &'a Context,
    uri: &str,
) -> Result<Resolved<'a>, CapabilityError>
Expand description

Resolve a URI: the capability the registry projects at it, then the object behind a resource or the answer of a query. An unknown URI is NotFound; a registry naming an object the index does not hold is Internal; a query that refuses passes its refusal through, and any other failure of the query is Internal, naming the capability.

use majordomus_cli::capability::builtin::{resolve, Resolved, REPOSITORY_URI};
use majordomus_cli::capability::{builtin, CapabilityError, CapabilityRegistry, Context};
use majordomus_cli::git::GitState;
use majordomus_cli::index::{Index, RepositoryInfo, State};
use std::sync::Arc;
// an index with no objects: only the repository report answers
let index = Index {
    repository: RepositoryInfo {
        root: "/tmp/doc".into(), layer_schema: "ai-repository/v1".into(),
        sections: Default::default(), git: GitState::Unavailable { reason: "doc".into() },
        discovery: "filesystem".into(), source_classes: vec![], kind_sources: vec![],
        scope_origin: majordomus_cli::scope::Origin::Distribution, scope_path: String::new(),
        observed: Default::default(),
    },
    objects: vec![], diagnostics: vec![], state: State::Ok, fingerprint: String::new(),
    scoped: Default::default(), distribution: None, providers: Default::default(),
    share: None,
};
let registry = CapabilityRegistry::builder().with_builtin(builtin::all()).with_index(&index).build().unwrap();
let ctx = Context::new(Arc::new(index), Arc::new(registry));
match resolve(&ctx, REPOSITORY_URI).unwrap() {
    Resolved::Answer { capability, resource, value } => {
        assert_eq!(capability.id.as_str(), "repository.info");
        assert_eq!(resource.name, "repository");
        assert_eq!(value["objects"], 0);
    }
    other => panic!("{other:?}"),
}
assert!(matches!(resolve(&ctx, "majordomus://rule/none@1"), Err(CapabilityError::NotFound(_))));