Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(policy): fix assert_status_accepted to panic #13413

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
22 changes: 16 additions & 6 deletions policy-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,29 @@ pub fn egress_network_traffic_policy_is(
) -> impl Condition<EgressNetwork> + '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<k8s::Condition>) {
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<k8s::Condition>) {
assert!(
is_status_accepted(&conditions),
"status must be accepted: {:?}",
conditions
);
}

#[tracing::instrument(skip_all, fields(%pod, %container))]
Expand Down
Loading