use super::{
restart_policy_shape, store_data_dir_identity_hash, StoreResourceReportError,
StoreResourceRestartPolicyShape,
};
use crate::store::RestartPolicy;
#[test]
fn data_dir_identity_hash_canonicalizes_existing_path_spellings() {
let dir = tempfile::TempDir::new().expect("create temp dir");
let raw_spelling = dir.path().join(".");
let canonical =
crate::store::platform::fs::canonicalize(dir.path()).expect("canonicalize temp dir");
assert_eq!(
store_data_dir_identity_hash(&raw_spelling),
store_data_dir_identity_hash(&canonical)
);
}
#[test]
fn restart_policy_shape_maps_each_variant_and_preserves_bounded_fields() {
assert_eq!(
restart_policy_shape(&RestartPolicy::Once),
StoreResourceRestartPolicyShape::Once,
"Once must project to the Once shape"
);
assert_eq!(
restart_policy_shape(&RestartPolicy::Bounded {
max_restarts: 7,
within_ms: 1234,
}),
StoreResourceRestartPolicyShape::Bounded {
max_restarts: 7,
within_ms: 1234,
},
"Bounded must project both fields into the right slots (no swap, no default)"
);
}
#[test]
fn data_dir_identity_hash_is_nonzero_and_distinguishes_missing_paths() {
let dir = tempfile::TempDir::new().expect("create temp dir");
let real = store_data_dir_identity_hash(dir.path());
assert_ne!(
real, [0u8; 32],
"an existing data dir must hash to a non-zero identity"
);
let missing_a = dir.path().join("does-not-exist-a");
let missing_b = dir.path().join("does-not-exist-b");
assert_eq!(
store_data_dir_identity_hash(&missing_a),
store_data_dir_identity_hash(&missing_a),
"the missing-path fallback must be deterministic for one path"
);
assert_ne!(
store_data_dir_identity_hash(&missing_a),
store_data_dir_identity_hash(&missing_b),
"distinct missing paths must hash distinctly (raw path-bytes fallback, not a constant)"
);
}
#[test]
fn store_resource_report_error_display_carries_the_encoding_message() {
let error = StoreResourceReportError::BodyEncoding {
message: "msgpack: unexpected end of buffer".to_owned(),
};
let rendered = error.to_string();
assert!(
rendered.contains("msgpack: unexpected end of buffer"),
"the encoding error message must be surfaced in Display, got {rendered:?}"
);
assert!(
rendered.contains("store resource report body encoding failed"),
"the Display prefix must name the failing operation, got {rendered:?}"
);
}