Skip to content

Commit

Permalink
chore: apply cargo clippy suggestions to tests
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
  • Loading branch information
fabriziosestito committed Oct 20, 2023
1 parent f22016f commit 8e01b1e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/admission_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod tests {

let response = AdmissionResponse::reject(uid.clone(), message.clone(), code);
assert_eq!(response.uid, uid);
assert_eq!(response.allowed, false);
assert!(!response.allowed);
assert_eq!(response.patch, None);
assert_eq!(response.patch_type, None);

Expand Down Expand Up @@ -187,7 +187,7 @@ mod tests {
let response = response.unwrap();

assert_eq!(response.uid, uid);
assert_eq!(response.allowed, false);
assert!(!response.allowed);
assert_eq!(response.patch, None);
assert_eq!(response.patch_type, None);
assert_eq!(response.audit_annotations, Some(audit_annotations));
Expand Down
22 changes: 5 additions & 17 deletions src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::policy_metadata::ContextAwareResource;
/// This struct is used extensively inside of the `host_callback`
/// function to obtain information about the policy that is invoking
/// a host waPC function, and handle the request.
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct Policy {
/// The policy identifier. This is mostly relevant for Policy Server,
/// which uses the identifier provided by the user inside of the `policy.yml`
Expand Down Expand Up @@ -56,18 +56,6 @@ impl PartialEq for Policy {
}
}

#[cfg(test)]
impl Default for Policy {
fn default() -> Self {
Policy {
id: String::default(),
instance_id: None,
callback_channel: None,
ctx_aware_resources_allow_list: HashSet::new(),
}
}
}

impl Policy {
pub(crate) fn new(
id: String,
Expand Down Expand Up @@ -167,18 +155,18 @@ mod tests {
let id = "test".to_string();
let policy_id = Some(1);
let callback_channel = None;
let ctx_aware_resources_allow_list = Some(HashSet::new());
let ctx_aware_resources_allow_list = HashSet::new();

let policy = Policy::new(
id.clone(),
policy_id.clone(),
policy_id,
callback_channel.clone(),
ctx_aware_resources_allow_list.clone(),
Some(ctx_aware_resources_allow_list.clone()),
)
.expect("cannot create policy");

assert!(policy.id == id);
assert!(policy.instance_id == policy_id);
assert!(policy.ctx_aware_resources_allow_list == ctx_aware_resources_allow_list.unwrap());
assert!(policy.ctx_aware_resources_allow_list == ctx_aware_resources_allow_list);
}
}
2 changes: 1 addition & 1 deletion src/policy_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ mod tests {

for (mode_str, expected) in &test_data {
let actual: std::result::Result<PolicyExecutionMode, serde_json::Error> =
serde_json::from_str(&mode_str);
serde_json::from_str(mode_str);
assert_eq!(expected, &actual.unwrap());
}

Expand Down
2 changes: 1 addition & 1 deletion src/policy_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ mod tests {

#[test]
fn metadata_with_rego_execution_mode_must_have_a_valid_protocol() {
for mode in vec![PolicyExecutionMode::Opa, PolicyExecutionMode::OpaGatekeeper] {
for mode in [PolicyExecutionMode::Opa, PolicyExecutionMode::OpaGatekeeper] {
let metadata = Metadata {
protocol_version: Some(ProtocolVersion::Unknown),
execution_mode: mode,
Expand Down

0 comments on commit 8e01b1e

Please sign in to comment.