pub(crate) mod doctor;
pub(crate) mod labels;
pub(crate) mod project;
pub(crate) use project::Project;
pub(crate) const SCHEMA_VERSION: u32 = 1;
pub(crate) fn validate_schema_version(requested: u32) -> anyhow::Result<u32> {
if requested != SCHEMA_VERSION {
anyhow::bail!(
"unsupported --schema-version {requested}; this binary speaks {SCHEMA_VERSION}",
);
}
Ok(requested)
}
fn schemas_base_url() -> &'static str {
env!("RUNNER_SCHEMA_BASE").trim_end_matches('/')
}
pub(crate) fn schema_url(command: &str) -> String {
format!("{}/{command}.schema.json", schemas_base_url())
}
pub(crate) fn config_schema_url() -> String {
format!("{}/runner.toml.schema.json", schemas_base_url())
}
#[cfg(test)]
mod tests {
use super::{SCHEMA_VERSION, validate_schema_version};
#[test]
fn validate_schema_version_accepts_only_the_current_version() {
assert_eq!(validate_schema_version(1).unwrap(), 1);
assert_eq!(SCHEMA_VERSION, 1);
}
#[test]
fn validate_schema_version_rejects_anything_else() {
let err = validate_schema_version(0).expect_err("v0 must error");
assert!(format!("{err}").contains("unsupported"));
let err = validate_schema_version(2).expect_err("v2 no longer exists");
let msg = format!("{err}");
assert!(msg.contains("unsupported"));
assert!(
msg.contains("speaks 1"),
"error should advertise the supported version: {msg}",
);
}
}