use haematite::branch::history::{Error as HistoryError, Key};
use haematite::branch::{CommitError, RefError};
use haematite::db::branches::ForkKeptError;
use haematite::tree::Hash;
use super::fork_kept_failure;
#[test]
fn kept_source_errors_keep_their_names_and_full_reasons() {
let key = Key {
branch: Hash::of(b"source"),
generation: 10,
sequence: 2,
};
let cases = [
(
ForkKeptError::ServiceBindingStale {
source: CommitError::UnnamedBranch,
},
"kept_service_binding_stale",
),
(
ForkKeptError::ServiceInvalid {
name: "source".to_owned(),
},
"kept_service_invalid",
),
(
ForkKeptError::ShardSetIncomplete { service: true },
"kept_shard_set_incomplete",
),
(
ForkKeptError::ShardSetIncomplete { service: false },
"kept_shard_set_incomplete",
),
(ForkKeptError::RowMissing { key }, "kept_row_missing"),
(
ForkKeptError::RowInvalid {
key,
source: HistoryError::ValueTruncated,
},
"kept_row_invalid",
),
(
ForkKeptError::RowRead {
shard_id: 0,
reason: "node read failed".to_owned(),
},
"kept_row_read",
),
(
ForkKeptError::RootUnavailable {
shard_id: 1,
root: Hash::of(b"missing"),
reason: "root missing in owning store".to_owned(),
},
"kept_root_unavailable",
),
];
for (error, code) in cases {
let message = error.to_string();
let failure = fork_kept_failure(&error, false);
assert_eq!(failure.code, code);
assert_eq!(failure.message, message);
assert!(failure.path.is_none());
}
}
#[test]
fn publication_errors_preserve_the_destination_install_boundary() {
for (installed, code) in [(false, "write_refused"), (true, "durability_unknown")] {
let error = ForkKeptError::Fork(CommitError::Ref(RefError::Io(std::io::Error::other(
"destination reference fence failed",
))));
let message = error.to_string();
let failure = fork_kept_failure(&error, installed);
assert_eq!(failure.code, code);
assert_eq!(failure.message, message);
}
}