use super::*;
#[test]
fn only_a_commit_target_names_a_commit() {
assert!(names_commit(&Base::Commit("a".repeat(40))));
assert!(!names_commit(&Base::Unborn));
}
#[test]
fn each_failure_is_worded_by_its_cause() {
assert_eq!(LandingError::Git(GitFailure(String::from("git broke"))).to_string(), "git broke");
assert_eq!(LandingError::Recovery(RecoveryError(String::from("recovery broke"))).to_string(), "recovery broke");
assert_eq!(LandingError::Journal(String::from("journal broke")).to_string(), "journal broke");
assert_eq!(LandingError::Release(String::from("release broke")).to_string(), "release broke");
assert_eq!(
LandingError::Phase(PhaseMarkerError::Io(std::io::Error::other("disk"))).to_string(),
"transaction phase marker failed: disk"
);
assert!(
LandingError::Lock(CoordinationFailure::Stop(String::from("lock broke")))
.to_string()
.contains("lock broke")
);
}
#[test]
fn a_failure_after_the_advance_names_the_landed_commit_and_forbids_a_retry() {
let failure: LandingError = LandingError::LandedThenFailed {
oid: "a".repeat(40),
target: String::from("refs/heads/main"),
cause: Box::new(LandingError::Journal(String::from("marker broke"))),
};
let text: String = failure.to_string();
assert!(text.contains(&format!("the commit {} landed on refs/heads/main", "a".repeat(40))), "{text}");
assert!(text.contains("completing its records failed: marker broke"), "{text}");
assert!(text.contains("do not retry it"), "{text}");
}