use super::*;
type TestResult = Result<(), Box<dyn std::error::Error>>;
#[test]
fn the_embedded_document_loads_and_verifies() -> TestResult {
let embedded = EmbeddedUpdateCheck::load()?;
assert_eq!(embedded.workflow_type(), UPDATE_CHECK_WORKFLOW_TYPE);
assert_eq!(embedded.source(), EMBEDDED_UPDATE_CHECK_DOCUMENT);
Ok(())
}
#[test]
fn the_compiled_identity_is_deterministic() -> TestResult {
let first = EmbeddedUpdateCheck::load()?;
let second = EmbeddedUpdateCheck::from_source(EMBEDDED_UPDATE_CHECK_DOCUMENT)?;
assert_eq!(first.content_hash(), second.content_hash());
Ok(())
}
#[test]
fn a_drifted_command_refuses_by_name() -> TestResult {
let drifted = EMBEDDED_UPDATE_CHECK_DOCUMENT.replace(
FETCH_COMMAND,
"curl -fsS https://example.com/somewhere-else",
);
match EmbeddedUpdateCheck::from_source(&drifted) {
Err(EmbeddedUpdateCheckError::WrongBody { found: Some(found) }) => {
assert_eq!(found, "curl -fsS https://example.com/somewhere-else");
Ok(())
}
other => Err(format!("a drifted command must refuse as WrongBody: {other:?}").into()),
}
}
#[test]
fn a_renamed_action_refuses() -> TestResult {
let renamed = EMBEDDED_UPDATE_CHECK_DOCUMENT.replace(FETCH_ACTION, "fetch_release_feed");
match EmbeddedUpdateCheck::from_source(&renamed) {
Err(EmbeddedUpdateCheckError::MissingAction) => Ok(()),
other => Err(format!("a renamed action must refuse as MissingAction: {other:?}").into()),
}
}
#[test]
fn a_renamed_workflow_type_refuses() -> TestResult {
let renamed =
EMBEDDED_UPDATE_CHECK_DOCUMENT.replace("workflow update_check", "workflow version_check");
match EmbeddedUpdateCheck::from_source(&renamed) {
Err(EmbeddedUpdateCheckError::WrongWorkflowType { found }) => {
assert_eq!(found, "version_check");
Ok(())
}
other => Err(format!("a renamed type must refuse as WrongWorkflowType: {other:?}").into()),
}
}
#[test]
fn a_moved_queue_refuses() -> TestResult {
let moved = EMBEDDED_UPDATE_CHECK_DOCUMENT.replace("worker update_check", "worker maintenance");
match EmbeddedUpdateCheck::from_source(&moved) {
Err(EmbeddedUpdateCheckError::MissingAction) => Ok(()),
other => Err(format!("a moved queue must refuse as MissingAction: {other:?}").into()),
}
}
#[test]
fn the_document_authors_the_exact_constant_command() {
assert!(
EMBEDDED_UPDATE_CHECK_DOCUMENT.contains(&format!("run \"{FETCH_COMMAND}\"")),
"the document must author `run \"{FETCH_COMMAND}\"` verbatim"
);
}
#[test]
fn the_fetched_url_and_the_accepted_crate_name_agree() {
let expected_tail = format!("/{}", super::super::index::INDEX_CRATE_NAME);
assert!(
FETCH_COMMAND.ends_with(&expected_tail),
"`{FETCH_COMMAND}` must end in `{expected_tail}` — the parser refuses lines naming any \
other crate"
);
}