Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 1 addition & 45 deletions crates/api-model/src/allocation_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ mod tests {
);
}

// Derived `PartialEq`/`Eq` over both `AllocationType` and `AssignStaticResult`:
// a variant equals only itself. `AssignStaticResult` has no other pure logic, so
// equality across its full variant set is its coverage.
// Derived `PartialEq`/`Eq` over `AllocationType`: a variant equals only itself.
#[test]
fn variants_compare_by_identity() {
value_scenarios!(
Expand Down Expand Up @@ -301,47 +299,5 @@ mod tests {
(AllocationType::Static, AllocationType::Slaac) => false,
}
);

value_scenarios!(
run = |(left, right)| left == right;
"assigned == assigned" {
(AssignStaticResult::Assigned, AssignStaticResult::Assigned) => true,
}

"replaced static == replaced static" {
(
AssignStaticResult::ReplacedStatic,
AssignStaticResult::ReplacedStatic,
) => true,
}

"replaced dhcp == replaced dhcp" {
(
AssignStaticResult::ReplacedDhcp,
AssignStaticResult::ReplacedDhcp,
) => true,
}

"assigned != replaced static" {
(
AssignStaticResult::Assigned,
AssignStaticResult::ReplacedStatic,
) => false,
}

"replaced static != replaced dhcp" {
(
AssignStaticResult::ReplacedStatic,
AssignStaticResult::ReplacedDhcp,
) => false,
}

"assigned != replaced dhcp" {
(
AssignStaticResult::Assigned,
AssignStaticResult::ReplacedDhcp,
) => false,
}
);
}
}
39 changes: 0 additions & 39 deletions crates/api-model/src/controller_outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,45 +279,6 @@ mod tests {
);
}

// Display for both types delegates to Debug. The rendered String is the
// contract; comparing against the Debug rendering keeps the rows honest
// without hard-coding the exact derived layout.
#[test]
fn test_display_matches_debug() {
value_scenarios!(
run = |rendered| rendered;
"source reference display equals debug" {
format!("{}", source_ref()) => format!("{:?}", source_ref()),
}

"transition outcome display equals debug" {
format!(
"{}",
PersistentStateHandlerOutcome::Transition { source_ref: None }
) => format!(
"{:?}",
PersistentStateHandlerOutcome::Transition { source_ref: None }
),
}

"wait outcome display equals debug" {
format!(
"{}",
PersistentStateHandlerOutcome::Wait {
reason: "r".to_string(),
source_ref: Some(source_ref()),
}
) => format!(
"{:?}",
PersistentStateHandlerOutcome::Wait {
reason: "r".to_string(),
source_ref: Some(source_ref()),
}
),
}
);
}

// Display for the source reference contains both the file and the line.
#[test]
fn test_source_reference_display_tokens() {
Expand Down
106 changes: 0 additions & 106 deletions crates/api-model/src/machine/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,50 +405,6 @@ mod tests {
.check(|qs| qs);
}

// Verify that IpAddr::to_string() produces the expected format for both
// address families, since several call sites throughout the codebase
// use .to_string() on the loopback_ip value. Folded from a pair of
// hand-written asserts into a table covering both families plus the
// boundary/canonicalization cases (zero, broadcast, all-ones,
// loopback, embedded-IPv4) where formatting can surprise.
#[test]
fn test_ip_addr_to_string_format() {
value_scenarios!(
run = |ip| ip.to_string();
"ipv4" {
IpAddr::V4(Ipv4Addr::new(10, 0, 0, 1)) => "10.0.0.1".to_string(),
}

"ipv4 unspecified" {
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)) => "0.0.0.0".to_string(),
}

"ipv4 broadcast" {
IpAddr::V4(Ipv4Addr::new(255, 255, 255, 255)) => "255.255.255.255".to_string(),
}

"ipv4 loopback" {
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)) => "127.0.0.1".to_string(),
}

"ipv6 compressed" {
IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)) => "2001:db8::1".to_string(),
}

"ipv6 unspecified collapses to ::" {
IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)) => "::".to_string(),
}

"ipv6 loopback collapses to ::1" {
IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)) => "::1".to_string(),
}

"ipv6 full (no run to compress)" {
IpAddr::V6(Ipv6Addr::new(0xfd00, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x42)) => "fd00:1:2:3:4:5:6:42".to_string(),
}
);
}

// ManagedHostQuarantineState::reason_str() returns the reason or an empty
// string when None. ManagedHostQuarantineMode has a single variant today;
// its as_str()/mode_str() must render it exactly so the persisted form is
Expand Down Expand Up @@ -613,68 +569,6 @@ mod tests {
);
}

// Parse pool strings as IpAddr (resource pools store values as strings and
// parse them via IpAddr::from_str). Yielding the exact IpAddr value also
// covers the original is_ipv4()/is_ipv6() family assertions. AddrParseError
// is not PartialEq, so failing rows would use `Fails`; both rows parse.
#[test]
fn test_ip_addr_parse_from_pool_strings() {
scenarios!(
run = |s| s.parse::<IpAddr>().map_err(drop);
"ipv4 string" {
"10.0.0.1" => Yields(IpAddr::V4(Ipv4Addr::new(10, 0, 0, 1))),
}

"ipv6 string" {
"2001:db8::1" => Yields(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1))),
}

"ipv4 unspecified" {
"0.0.0.0" => Yields(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))),
}

"ipv4 broadcast" {
"255.255.255.255" => Yields(IpAddr::V4(Ipv4Addr::new(255, 255, 255, 255))),
}

"ipv6 unspecified" {
"::" => Yields(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0))),
}

"ipv6 loopback" {
"::1" => Yields(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1))),
}

"empty string is rejected" {
"" => Fails,
}

"non-address text is rejected" {
"not-an-ip" => Fails,
}

"ipv4 octet out of range is rejected" {
"256.0.0.1" => Fails,
}

"ipv4 with too few octets is rejected" {
"10.0.0" => Fails,
}

"ipv4 with trailing whitespace is rejected" {
"10.0.0.1 " => Fails,
}

"ipv6 with double :: is rejected" {
"2001::db8::1" => Fails,
}

"cidr suffix is not an address" {
"10.0.0.0/24" => Fails,
}
);
}

// Deserialize raw JSON whose shape is malformed or whose IP strings are
// invalid; serde_json::Error is not PartialEq, so rejected rows use `Fails`.
// Also covers a populated quarantine_state, which the earlier deserialize
Expand Down
33 changes: 10 additions & 23 deletions crates/api-model/src/machine/upgrade_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@ mod tests {
);
}

// Total ordering over build versions. Each row pins the `cmp` result; the
// runner also asserts `partial_cmp` agrees (it must return `Some(cmp)`), so
// the PartialOrd impl is checked against Ord on every row.
#[test]
fn build_version_ordering() {
struct Pair {
Expand All @@ -754,7 +757,13 @@ mod tests {
run = |Pair { left, right }| {
let l = BuildVersion::try_from(left).unwrap();
let r = BuildVersion::try_from(right).unwrap();
l.cmp(&r)
let ordering = l.cmp(&r);
assert_eq!(
l.partial_cmp(&r),
Some(ordering),
"partial_cmp must agree with cmp for {left} vs {right}",
);
ordering
};
"older date less than newer date" {
Pair {
Expand Down Expand Up @@ -828,28 +837,6 @@ mod tests {
);
}

#[test]
fn build_version_partial_cmp_matches_cmp() {
value_scenarios!(
run = |(l, r)| {
BuildVersion::try_from(l)
.unwrap()
.partial_cmp(&BuildVersion::try_from(r).unwrap())
};
"less" {
("v0.0.1", "v1.0.0") => Some(Ordering::Less),
}

"greater" {
("v1.0.0", "v0.0.1") => Some(Ordering::Greater),
}

"equal" {
("v1.0.0", "v1.0.0") => Some(Ordering::Equal),
}
);
}

#[test]
fn test_compare_versions() -> eyre::Result<()> {
use rand::prelude::SliceRandom;
Expand Down
Loading
Loading