56 lines
1.5 KiB
Rust
56 lines
1.5 KiB
Rust
|
|
//! Unit tests for `InstanceHandle` serialization, display, and equality.
|
||
|
|
|
||
|
|
use ontoref_compute::InstanceHandle;
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn display_matches_inner_string() {
|
||
|
|
let h = InstanceHandle::new("hetzner-12345");
|
||
|
|
assert_eq!(format!("{h}"), "hetzner-12345");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn as_str_matches_inner_string() {
|
||
|
|
let h = InstanceHandle::new("docker-abc123456789");
|
||
|
|
assert_eq!(h.as_str(), "docker-abc123456789");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn from_str_and_from_string_are_equivalent() {
|
||
|
|
let from_str = InstanceHandle::from("ns/job-name");
|
||
|
|
let from_string = InstanceHandle::from("ns/job-name".to_string());
|
||
|
|
assert_eq!(from_str, from_string);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn equality_is_string_based() {
|
||
|
|
let a = InstanceHandle::new("same");
|
||
|
|
let b = InstanceHandle::new("same");
|
||
|
|
let c = InstanceHandle::new("different");
|
||
|
|
assert_eq!(a, b);
|
||
|
|
assert_ne!(a, c);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn serde_roundtrip_transparent() {
|
||
|
|
let h = InstanceHandle::new("k8s/ontoref-abcdef012345");
|
||
|
|
let json = serde_json::to_string(&h).expect("serialize");
|
||
|
|
// Transparent encoding: just a JSON string, no wrapper object.
|
||
|
|
assert_eq!(json, r#""k8s/ontoref-abcdef012345""#);
|
||
|
|
let decoded: InstanceHandle = serde_json::from_str(&json).expect("deserialize");
|
||
|
|
assert_eq!(decoded, h);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn handle_as_ref_str() {
|
||
|
|
let h = InstanceHandle::new("ref-test");
|
||
|
|
let s: &str = h.as_ref();
|
||
|
|
assert_eq!(s, "ref-test");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn handle_ordering_is_lexicographic() {
|
||
|
|
let a = InstanceHandle::new("a-handle");
|
||
|
|
let b = InstanceHandle::new("b-handle");
|
||
|
|
assert!(a < b);
|
||
|
|
}
|