From 17e70229ee483d4449d9df4ded827966c54a5147 Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Mon, 2 Dec 2024 21:51:50 +0000 Subject: [PATCH] test(policy): fix assert_status_accepted to panic assert_status_accepted was not panicking when the status was not accepted. This change updates the e2e_egress_network test to properly wait on networks that are not accepted. --- policy-test/src/lib.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/policy-test/src/lib.rs b/policy-test/src/lib.rs index cdf2aba7d405c..da69d55a10d40 100644 --- a/policy-test/src/lib.rs +++ b/policy-test/src/lib.rs @@ -355,19 +355,29 @@ pub fn egress_network_traffic_policy_is( ) -> impl Condition + 'static { move |egress_net: Option<&EgressNetwork>| { if let Some(egress_net) = &egress_net { - let status = egress_net.status.clone(); - assert_status_accepted(status.map(|s| s.conditions).unwrap_or_default()); - - return egress_net.spec.traffic_policy == policy; + return egress_net + .status + .as_ref() + .map_or(false, |s| is_status_accepted(&s.conditions)) + && egress_net.spec.traffic_policy == policy; } false } } -pub fn assert_status_accepted(conditions: Vec) { +fn is_status_accepted(conditions: &[k8s::Condition]) -> bool { conditions .iter() - .any(|c| c.type_ == "Accepted" && c.status == "True"); + .any(|c| c.type_ == "Accepted" && c.status == "True") +} + +#[track_caller] +pub fn assert_status_accepted(conditions: Vec) { + assert!( + is_status_accepted(&conditions), + "status must be accepted: {:?}", + conditions + ); } #[tracing::instrument(skip_all, fields(%pod, %container))]