From aec066bdf876a6cd97ca4fe043bb3984b3391ada Mon Sep 17 00:00:00 2001 From: Techassi Date: Fri, 20 Sep 2024 10:21:43 +0200 Subject: [PATCH] chore: Rename test functions --- crates/stackable-certs/src/ca/mod.rs | 7 ++- .../src/builder/configmap.rs | 2 +- .../stackable-operator/src/builder/event.rs | 2 +- crates/stackable-operator/src/builder/meta.rs | 2 +- crates/stackable-operator/src/builder/pdb.rs | 8 +-- .../src/builder/pod/container.rs | 21 ++++---- .../stackable-operator/src/builder/pod/mod.rs | 10 ++-- .../src/builder/pod/resources.rs | 4 +- .../src/builder/pod/security.rs | 2 +- .../src/builder/pod/volume.rs | 6 +-- crates/stackable-operator/src/cli.rs | 8 +-- .../src/commons/affinity.rs | 8 +-- .../src/commons/authentication/ldap.rs | 10 ++-- .../src/commons/authentication/mod.rs | 4 +- .../src/commons/authentication/oidc.rs | 12 ++--- crates/stackable-operator/src/commons/opa.rs | 13 ++--- .../src/commons/product_image_selection.rs | 4 +- crates/stackable-operator/src/commons/rbac.rs | 2 +- .../src/commons/resources.rs | 6 +-- crates/stackable-operator/src/commons/s3.rs | 17 +++---- .../src/commons/secret_class.rs | 2 +- crates/stackable-operator/src/cpu.rs | 18 +++---- crates/stackable-operator/src/helm/mod.rs | 6 +-- .../src/kvp/label/selector.rs | 8 +-- crates/stackable-operator/src/logging/mod.rs | 4 +- crates/stackable-operator/src/memory.rs | 50 +++++++------------ .../src/product_config_utils.rs | 8 +-- .../src/product_logging/framework.rs | 6 +-- .../src/status/condition/daemonset.rs | 17 ++++--- .../src/status/condition/mod.rs | 16 +++--- .../src/status/condition/operations.rs | 4 +- .../src/status/condition/statefulset.rs | 17 ++++--- crates/stackable-operator/src/utils/crds.rs | 10 ++-- crates/stackable-operator/src/utils/option.rs | 6 +-- crates/stackable-operator/src/validation.rs | 8 +-- 35 files changed, 161 insertions(+), 167 deletions(-) diff --git a/crates/stackable-certs/src/ca/mod.rs b/crates/stackable-certs/src/ca/mod.rs index 603f8c5f3..c4d5ba291 100644 --- a/crates/stackable-certs/src/ca/mod.rs +++ b/crates/stackable-certs/src/ca/mod.rs @@ -467,19 +467,18 @@ fn format_leaf_certificate_subject(name: &str, scope: &str) -> Result { } #[cfg(test)] -mod test { - +mod tests { use super::*; #[tokio::test] - async fn test_rsa_key_generation() { + async fn rsa_key_generation() { let mut ca = CertificateAuthority::new_rsa().unwrap(); ca.generate_rsa_leaf_certificate("Airflow", "pod", Duration::from_secs(3600)) .unwrap(); } #[tokio::test] - async fn test_ecdsa_key_generation() { + async fn ecdsa_key_generation() { let mut ca = CertificateAuthority::new_ecdsa().unwrap(); ca.generate_ecdsa_leaf_certificate("Airflow", "pod", Duration::from_secs(3600)) .unwrap(); diff --git a/crates/stackable-operator/src/builder/configmap.rs b/crates/stackable-operator/src/builder/configmap.rs index fb5e67cbc..095fda8fa 100644 --- a/crates/stackable-operator/src/builder/configmap.rs +++ b/crates/stackable-operator/src/builder/configmap.rs @@ -69,7 +69,7 @@ mod tests { use std::collections::BTreeMap; #[test] - fn test_configmap_builder() { + fn configmap_builder() { let mut data = BTreeMap::new(); data.insert("foo".to_string(), "bar".to_string()); let configmap = ConfigMapBuilder::new() diff --git a/crates/stackable-operator/src/builder/event.rs b/crates/stackable-operator/src/builder/event.rs index 1fbc6ce1f..b523acffb 100644 --- a/crates/stackable-operator/src/builder/event.rs +++ b/crates/stackable-operator/src/builder/event.rs @@ -130,7 +130,7 @@ mod tests { use crate::builder::pod::PodBuilder; #[test] - fn test_event_builder() { + fn event_builder() { let pod = PodBuilder::new() .metadata_builder(|builder| builder.name("testpod")) .build() diff --git a/crates/stackable-operator/src/builder/meta.rs b/crates/stackable-operator/src/builder/meta.rs index fdaeea510..fbf23e793 100644 --- a/crates/stackable-operator/src/builder/meta.rs +++ b/crates/stackable-operator/src/builder/meta.rs @@ -316,7 +316,7 @@ mod tests { use k8s_openapi::api::core::v1::Pod; #[test] - fn test_objectmeta_builder() { + fn objectmeta_builder() { let mut pod = Pod::default(); pod.metadata.name = Some("pod".to_string()); pod.metadata.uid = Some("uid".to_string()); diff --git a/crates/stackable-operator/src/builder/pdb.rs b/crates/stackable-operator/src/builder/pdb.rs index 4a4465ee1..d6ff52778 100644 --- a/crates/stackable-operator/src/builder/pdb.rs +++ b/crates/stackable-operator/src/builder/pdb.rs @@ -198,7 +198,7 @@ impl PodDisruptionBudgetBuilder { } #[cfg(test)] -mod test { +mod tests { use super::*; #[test] - fn test_builder() { + fn builder() { let resources = ResourceRequirements { limits: Some( [ diff --git a/crates/stackable-operator/src/builder/pod/security.rs b/crates/stackable-operator/src/builder/pod/security.rs index aca6680d8..55d943b3d 100644 --- a/crates/stackable-operator/src/builder/pod/security.rs +++ b/crates/stackable-operator/src/builder/pod/security.rs @@ -339,7 +339,7 @@ mod tests { use k8s_openapi::api::core::v1::{PodSecurityContext, SELinuxOptions, SeccompProfile, Sysctl}; #[test] - fn test_security_context_builder() { + fn security_context_builder() { let mut builder = PodSecurityContextBuilder::new(); let context = builder .fs_group(1000) diff --git a/crates/stackable-operator/src/builder/pod/volume.rs b/crates/stackable-operator/src/builder/pod/volume.rs index 72e3fc41f..8f160d1ec 100644 --- a/crates/stackable-operator/src/builder/pod/volume.rs +++ b/crates/stackable-operator/src/builder/pod/volume.rs @@ -558,7 +558,7 @@ mod tests { use std::collections::BTreeMap; #[test] - fn test_volume_builder() { + fn builder() { let mut volume_builder = VolumeBuilder::new("name"); volume_builder.with_config_map("configmap"); let vol = volume_builder.build(); @@ -595,7 +595,7 @@ mod tests { } #[test] - fn test_volume_mount_builder() { + fn mount_builder() { let mut volume_mount_builder = VolumeMountBuilder::new("name", "mount_path"); volume_mount_builder .mount_propagation("mount_propagation") @@ -614,7 +614,7 @@ mod tests { } #[test] - fn test_listener_operator_volume_source_builder() { + fn listener_operator_volume_source_builder() { let labels: Labels = Labels::try_from(BTreeMap::::new()).unwrap(); let builder = ListenerOperatorVolumeSourceBuilder::new( diff --git a/crates/stackable-operator/src/cli.rs b/crates/stackable-operator/src/cli.rs index cc0221de4..10bdc18fc 100644 --- a/crates/stackable-operator/src/cli.rs +++ b/crates/stackable-operator/src/cli.rs @@ -303,7 +303,7 @@ mod tests { DEPLOY_FILE_PATH )] #[case(None, vec!["bad", DEFAULT_FILE_PATH], DEFAULT_FILE_PATH, DEFAULT_FILE_PATH)] - fn test_resolve_path_good( + fn resolve_path_good( #[case] user_provided_path: Option<&str>, #[case] default_locations: Vec<&str>, #[case] path_to_create: &str, @@ -343,12 +343,12 @@ mod tests { #[test] #[should_panic] - fn test_resolve_path_user_path_not_existing() { + fn resolve_path_user_path_not_existing() { resolve_path(Some(USER_PROVIDED_PATH.as_ref()), &[DEPLOY_FILE_PATH]).unwrap(); } #[test] - fn test_resolve_path_nothing_found_errors() { + fn resolve_path_nothing_found_errors() { if let Err(Error::RequiredFileMissing { search_path }) = resolve_path(None, &[DEPLOY_FILE_PATH, DEFAULT_FILE_PATH]) { @@ -365,7 +365,7 @@ mod tests { } #[test] - fn test_product_operator_run_watch_namespace() { + fn product_operator_run_watch_namespace() { // clean env var to not interfere if already set env::remove_var(WATCH_NAMESPACE); diff --git a/crates/stackable-operator/src/commons/affinity.rs b/crates/stackable-operator/src/commons/affinity.rs index c2f56b53a..071c14e70 100644 --- a/crates/stackable-operator/src/commons/affinity.rs +++ b/crates/stackable-operator/src/commons/affinity.rs @@ -143,7 +143,7 @@ mod tests { use super::*; #[test] - fn test_affinity_merge_new_attributes() { + fn merge_new_attributes() { let default_affinity = StackableAffinityFragment { pod_affinity: None, pod_anti_affinity: Some(PodAntiAffinity { @@ -254,7 +254,7 @@ mod tests { } #[test] - fn test_affinity_merge_overwrite_existing_attribute() { + fn merge_overwrite_existing_attribute() { let default_affinity = StackableAffinityFragment { pod_affinity: None, pod_anti_affinity: Some(PodAntiAffinity { @@ -319,7 +319,7 @@ mod tests { } #[test] - fn test_affinity_between_role_pods() { + fn between_role_pods() { let app_name = "kafka"; let cluster_name = "simple-kafka"; let role = "broker"; @@ -352,7 +352,7 @@ mod tests { } #[test] - fn test_affinity_between_cluster_pods() { + fn between_cluster_pods() { let app_name = "kafka"; let cluster_name = "simple-kafka"; diff --git a/crates/stackable-operator/src/commons/authentication/ldap.rs b/crates/stackable-operator/src/commons/authentication/ldap.rs index 35370cce9..890fe4f80 100644 --- a/crates/stackable-operator/src/commons/authentication/ldap.rs +++ b/crates/stackable-operator/src/commons/authentication/ldap.rs @@ -214,11 +214,11 @@ impl Default for FieldNames { } #[cfg(test)] -mod test { +mod tests { use super::*; #[test] - fn test_ldap_minimal() { + fn minimal() { let ldap = serde_yaml::from_str::( " hostname: my.ldap.server @@ -232,7 +232,7 @@ mod test { } #[test] - fn test_ldap_with_bind_credentials() { + fn with_bind_credentials() { let _ldap = serde_yaml::from_str::( " hostname: my.ldap.server @@ -246,7 +246,7 @@ mod test { } #[test] - fn test_ldap_full() { + fn full() { let input = r#" hostname: my.ldap.server port: 42 @@ -273,6 +273,7 @@ mod test { ldap.tls.tls_ca_cert_mount_path(), Some("/stackable/secrets/ldap-ca-cert/ca.crt".to_string()) ); + let (tls_volumes, tls_mounts) = ldap.tls.volumes_and_mounts().unwrap(); assert_eq!( tls_volumes, @@ -300,6 +301,7 @@ mod test { "/stackable/secrets/openldap-bind-credentials/password".to_string() )) ); + let (ldap_volumes, ldap_mounts) = ldap.volumes_and_mounts().unwrap(); assert_eq!( ldap_volumes, diff --git a/crates/stackable-operator/src/commons/authentication/mod.rs b/crates/stackable-operator/src/commons/authentication/mod.rs index b4d87890e..b5356b512 100644 --- a/crates/stackable-operator/src/commons/authentication/mod.rs +++ b/crates/stackable-operator/src/commons/authentication/mod.rs @@ -173,13 +173,13 @@ impl ClientAuthenticationDetails { } #[cfg(test)] -mod test { +mod tests { use crate::commons::authentication::{ tls::AuthenticationProvider, AuthenticationClassProvider, }; #[test] - fn test_authentication_class_provider_to_string() { + fn provider_to_string() { let tls_provider = AuthenticationClassProvider::Tls(AuthenticationProvider { client_cert_secret_class: None, }); diff --git a/crates/stackable-operator/src/commons/authentication/oidc.rs b/crates/stackable-operator/src/commons/authentication/oidc.rs index 94097f05f..a47ef9772 100644 --- a/crates/stackable-operator/src/commons/authentication/oidc.rs +++ b/crates/stackable-operator/src/commons/authentication/oidc.rs @@ -243,7 +243,7 @@ mod test { use super::*; #[test] - fn test_oidc_minimal() { + fn minimal() { let oidc = serde_yaml::from_str::( " hostname: my.keycloak.server @@ -255,7 +255,7 @@ mod test { } #[test] - fn test_oidc_full() { + fn full() { let oidc = serde_yaml::from_str::( " hostname: my.keycloak.server @@ -269,7 +269,7 @@ mod test { } #[test] - fn test_oidc_http_endpoint_url() { + fn http_endpoint_url() { let oidc = serde_yaml::from_str::( " hostname: my.keycloak.server @@ -288,7 +288,7 @@ mod test { } #[test] - fn test_oidc_https_endpoint_url() { + fn https_endpoint_url() { let oidc = serde_yaml::from_str::( " hostname: my.keycloak.server @@ -314,7 +314,7 @@ mod test { } #[test] - fn test_oidc_ipv6_endpoint_url() { + fn ipv6_endpoint_url() { let oidc = serde_yaml::from_str::( " hostname: '[2606:2800:220:1:248:1893:25c8:1946]' @@ -333,7 +333,7 @@ mod test { } #[test] - fn test_oidc_client_env_vars() { + fn client_env_vars() { let secret_name = "my-keycloak-client"; let env_names = AuthenticationProvider::client_credentials_env_names(secret_name); assert_eq!( diff --git a/crates/stackable-operator/src/commons/opa.rs b/crates/stackable-operator/src/commons/opa.rs index 5339e0148..cedcec45e 100644 --- a/crates/stackable-operator/src/commons/opa.rs +++ b/crates/stackable-operator/src/commons/opa.rs @@ -264,11 +264,12 @@ impl OpaConfig { #[cfg(test)] mod tests { - use super::*; use kube::CustomResource; use schemars::{self, JsonSchema}; use serde::{Deserialize, Serialize}; + use super::*; + const CLUSTER_NAME: &str = "simple-cluster"; const PACKAGE_NAME: &str = "my-package"; const RULE_NAME: &str = "allow"; @@ -278,7 +279,7 @@ mod tests { const V1: OpaApiVersion = OpaApiVersion::V1; #[test] - fn test_document_url_with_package_name() { + fn document_url_with_package_name() { let cluster = build_test_cluster(); let opa_config = build_opa_config(Some(PACKAGE_NAME)); @@ -294,7 +295,7 @@ mod tests { } #[test] - fn test_document_url_without_package_name() { + fn document_url_without_package_name() { let cluster = build_test_cluster(); let opa_config = build_opa_config(None); @@ -310,7 +311,7 @@ mod tests { } #[test] - fn test_full_document_url() { + fn full_document_url() { let cluster = build_test_cluster(); let opa_config = build_opa_config(None); @@ -365,7 +366,7 @@ mod tests { } #[test] - fn test_opa_package_name_sanitizer() { + fn sanitize_package_name() { // No sanitization needed assert_eq!( OpaConfig::sanitize_opa_package_name("kafka/authz"), @@ -386,7 +387,7 @@ mod tests { } #[test] - fn test_opa_document_url_sanitization() { + fn sanitize_document_url() { let opa_config = OpaConfig { config_map_name: "simple-opa".to_owned(), package: Some("///kafka.authz".to_owned()), diff --git a/crates/stackable-operator/src/commons/product_image_selection.rs b/crates/stackable-operator/src/commons/product_image_selection.rs index 93f0f3f47..d5e02de3d 100644 --- a/crates/stackable-operator/src/commons/product_image_selection.rs +++ b/crates/stackable-operator/src/commons/product_image_selection.rs @@ -414,7 +414,7 @@ mod tests { pull_secrets: Some(vec![LocalObjectReference{name: "myPullSecrets1".to_string()}, LocalObjectReference{name: "myPullSecrets2".to_string()}]), } )] - fn test_correct_resolved_image( + fn resolved_image_pass( #[case] image_base_name: String, #[case] operator_version: String, #[case] input: String, @@ -443,7 +443,7 @@ mod tests { "{}", "data did not match any variant of untagged enum ProductImageSelection" )] - fn test_invalid_image(#[case] input: String, #[case] expected: String) { + fn resolved_image_fail(#[case] input: String, #[case] expected: String) { let err = serde_yaml::from_str::(&input).expect_err("Must be error"); assert_eq!(err.to_string(), expected); diff --git a/crates/stackable-operator/src/commons/rbac.rs b/crates/stackable-operator/src/commons/rbac.rs index 5907417cb..1b7ef2d85 100644 --- a/crates/stackable-operator/src/commons/rbac.rs +++ b/crates/stackable-operator/src/commons/rbac.rs @@ -124,7 +124,7 @@ mod tests { } #[test] - fn test_build_rbac() { + fn build() { let cluster = build_test_resource(); let (rbac_sa, rbac_rolebinding) = build_rbac_resources(&cluster, RESOURCE_NAME, Labels::new()).unwrap(); diff --git a/crates/stackable-operator/src/commons/resources.rs b/crates/stackable-operator/src/commons/resources.rs index 0013add7e..101dd288e 100644 --- a/crates/stackable-operator/src/commons/resources.rs +++ b/crates/stackable-operator/src/commons/resources.rs @@ -643,7 +643,7 @@ mod tests { matchLabels: nodeType: directstorage"# )] - fn test_build_pvc( + fn build_pvc( #[case] name: String, #[case] access_modes: Option>, #[case] input: String, @@ -699,7 +699,7 @@ mod tests { memory: 20Gi cpu: 1000"# )] - fn test_into_resourcelimits(#[case] input: String, #[case] expected: String) { + fn into_resourcelimits(#[case] input: String, #[case] expected: String) { let input_resources_fragment: ResourcesFragment = serde_yaml::from_str(&input).expect("illegal test input"); let input_resources: Resources = @@ -717,7 +717,7 @@ mod tests { #[case::cpu_ratio_invalid("100m", "1", "4Gi", "4Gi", false, true)] #[case::memory_ratio_invalid("1", "1", "2Gi", "4Gi", true, false)] #[case::both_ratios_invalid("100m", "1", "2Gi", "4Gi", false, false)] - fn test_resource_requirements_checks( + fn resource_requirements_checks( #[case] cr: String, #[case] cl: String, #[case] mr: String, diff --git a/crates/stackable-operator/src/commons/s3.rs b/crates/stackable-operator/src/commons/s3.rs index fd2bb8711..796c6859a 100644 --- a/crates/stackable-operator/src/commons/s3.rs +++ b/crates/stackable-operator/src/commons/s3.rs @@ -251,15 +251,14 @@ pub enum S3AccessStyle { } #[cfg(test)] -mod test { - use std::str; - - use crate::commons::s3::{S3AccessStyle, S3ConnectionDef}; - use crate::commons::s3::{S3BucketSpec, S3ConnectionSpec}; - use crate::yaml; +mod tests { + use crate::{ + commons::s3::{S3AccessStyle, S3BucketSpec, S3ConnectionDef, S3ConnectionSpec}, + yaml::serialize_to_explicit_document, + }; #[test] - fn test_ser_inline() { + fn serialize_inline() { let bucket = S3BucketSpec { bucket_name: Some("test-bucket-name".to_owned()), connection: Some(S3ConnectionDef::Inline(S3ConnectionSpec { @@ -272,8 +271,8 @@ mod test { }; let mut buf = Vec::new(); - yaml::serialize_to_explicit_document(&mut buf, &bucket).expect("serializable value"); - let actual_yaml = str::from_utf8(&buf).expect("UTF-8 encoded document"); + serialize_to_explicit_document(&mut buf, &bucket).expect("serializable value"); + let actual_yaml = std::str::from_utf8(&buf).expect("UTF-8 encoded document"); let expected_yaml = "--- bucketName: test-bucket-name diff --git a/crates/stackable-operator/src/commons/secret_class.rs b/crates/stackable-operator/src/commons/secret_class.rs index 4f82790e9..71a2195ac 100644 --- a/crates/stackable-operator/src/commons/secret_class.rs +++ b/crates/stackable-operator/src/commons/secret_class.rs @@ -100,7 +100,7 @@ mod tests { use std::collections::BTreeMap; #[test] - fn test_secret_class_volume_to_csi_volume_source() { + fn volume_to_csi_volume_source() { let secret_class_volume_source = SecretClassVolume { secret_class: "myclass".to_string(), // pragma: allowlist secret scope: Some(SecretClassVolumeScope { diff --git a/crates/stackable-operator/src/cpu.rs b/crates/stackable-operator/src/cpu.rs index 92a7a83d6..45bb421c9 100644 --- a/crates/stackable-operator/src/cpu.rs +++ b/crates/stackable-operator/src/cpu.rs @@ -228,7 +228,7 @@ impl Sum for CpuQuantity { } #[cfg(test)] -mod test { +mod tests { use super::*; use rstest::*; @@ -240,9 +240,9 @@ mod test { #[case("0.2", 200)] #[case("0.02", 20)] #[case("0.002", 2)] - fn test_from_str(#[case] s: &str, #[case] millis: usize) { - let result = CpuQuantity::from_str(s).unwrap(); - assert_eq!(millis, result.as_milli_cpus()) + fn from_str_pass(#[case] input: &str, #[case] expected: usize) { + let got = CpuQuantity::from_str(input).unwrap(); + assert_eq!(got.as_milli_cpus(), expected); } #[rstest] @@ -250,8 +250,8 @@ mod test { #[case("1000.1m")] #[case("500k")] #[case("0.0002")] - fn test_from_str_err(#[case] s: &str) { - let result = CpuQuantity::from_str(s); + fn from_str_fail(#[case] input: &str) { + let result = CpuQuantity::from_str(input); assert!(result.is_err()); } @@ -263,7 +263,7 @@ mod test { #[case(CpuQuantity::from_millis(100), "100m")] #[case(CpuQuantity::from_millis(2000), "2")] #[case(CpuQuantity::from_millis(1000), "1")] - fn test_display_to_string(#[case] cpu: CpuQuantity, #[case] expected: &str) { + fn to_string(#[case] cpu: CpuQuantity, #[case] expected: &str) { assert_eq!(cpu.to_string(), expected) } @@ -275,7 +275,7 @@ mod test { #[case(CpuQuantity::from_millis(100), "cpu: 100m\n")] #[case(CpuQuantity::from_millis(2000), "cpu: '2'\n")] #[case(CpuQuantity::from_millis(1000), "cpu: '1'\n")] - fn test_serialize(#[case] cpu: CpuQuantity, #[case] expected: &str) { + fn serialize(#[case] cpu: CpuQuantity, #[case] expected: &str) { #[derive(Serialize)] struct Cpu { cpu: CpuQuantity, @@ -295,7 +295,7 @@ mod test { #[case("cpu: 100m", CpuQuantity::from_millis(100))] #[case("cpu: 2", CpuQuantity::from_millis(2000))] #[case("cpu: 1", CpuQuantity::from_millis(1000))] - fn test_deserialize(#[case] input: &str, #[case] expected: CpuQuantity) { + fn deserialize(#[case] input: &str, #[case] expected: CpuQuantity) { #[derive(Deserialize)] struct Cpu { cpu: CpuQuantity, diff --git a/crates/stackable-operator/src/helm/mod.rs b/crates/stackable-operator/src/helm/mod.rs index fba5d7a44..f5bf85c0b 100644 --- a/crates/stackable-operator/src/helm/mod.rs +++ b/crates/stackable-operator/src/helm/mod.rs @@ -74,7 +74,7 @@ pub struct ServiceAccountValues { } #[cfg(test)] -mod test { +mod tests { use std::path::PathBuf; use rstest::rstest; @@ -84,14 +84,14 @@ mod test { use super::*; #[rstest] - fn test_deserialize(#[files("fixtures/helm/input-*.yaml")] path: PathBuf) { + fn deserialize(#[files("fixtures/helm/input-*.yaml")] path: PathBuf) { let contents = std::fs::read_to_string(path).unwrap(); let values: DynamicValues = serde_yaml::from_str(&contents).unwrap(); assert_eq!(values.labels().len(), 2); } #[rstest] - fn test_serialize(#[files("fixtures/helm/input-required.yaml")] input: PathBuf) { + fn serialize(#[files("fixtures/helm/input-required.yaml")] input: PathBuf) { let contents = std::fs::read_to_string(input).unwrap(); let mut values: DynamicValues = serde_yaml::from_str(&contents).unwrap(); diff --git a/crates/stackable-operator/src/kvp/label/selector.rs b/crates/stackable-operator/src/kvp/label/selector.rs index 5ab187b97..a8f99d89a 100644 --- a/crates/stackable-operator/src/kvp/label/selector.rs +++ b/crates/stackable-operator/src/kvp/label/selector.rs @@ -116,7 +116,7 @@ mod tests { use std::collections::BTreeMap; #[test] - fn test_label_selector() { + fn label_selector() { let mut match_labels = BTreeMap::new(); match_labels.insert("foo".to_string(), "bar".to_string()); match_labels.insert("hui".to_string(), "buh".to_string()); @@ -173,7 +173,7 @@ mod tests { #[test] #[should_panic] - fn test_invalid_label_in_selector() { + fn invalid_label_in_selector() { let match_expressions = vec![LabelSelectorRequirement { key: "foo".to_string(), operator: "In".to_string(), @@ -190,7 +190,7 @@ mod tests { #[test] #[should_panic] - fn test_invalid_operator_in_selector() { + fn invalid_operator_in_selector() { let match_expressions = vec![LabelSelectorRequirement { key: "foo".to_string(), operator: "IllegalOperator".to_string(), @@ -207,7 +207,7 @@ mod tests { #[test] #[should_panic] - fn test_invalid_exists_operator_in_selector() { + fn invalid_exists_operator_in_selector() { let match_expressions = vec![LabelSelectorRequirement { key: "foo".to_string(), operator: "Exists".to_string(), diff --git a/crates/stackable-operator/src/logging/mod.rs b/crates/stackable-operator/src/logging/mod.rs index e9c5eb5b4..861edfa51 100644 --- a/crates/stackable-operator/src/logging/mod.rs +++ b/crates/stackable-operator/src/logging/mod.rs @@ -80,7 +80,7 @@ pub fn initialize_logging(env: &str, app_name: &str, tracing_target: TracingTarg } #[cfg(test)] -mod test { +mod tests { use tracing::{debug, error, info}; @@ -94,7 +94,7 @@ mod test { // NOT_SET=debug cargo test default_tracing -- --nocapture // to see them all. #[test] - pub fn test_default_tracing_level_is_set_to_info() { + fn default_tracing_level_is_set_to_info() { super::initialize_logging("NOT_SET", "test", TracingTarget::None); error!("ERROR level messages should be seen."); diff --git a/crates/stackable-operator/src/memory.rs b/crates/stackable-operator/src/memory.rs index 4217a2a90..8dfef7bee 100644 --- a/crates/stackable-operator/src/memory.rs +++ b/crates/stackable-operator/src/memory.rs @@ -514,7 +514,7 @@ impl From<&MemoryQuantity> for Quantity { } #[cfg(test)] -mod test { +mod tests { use k8s_openapi::apimachinery::pkg::api::resource::Quantity; use super::*; @@ -528,9 +528,9 @@ mod test { #[case("0.8Ti", MemoryQuantity { value: 0.8, unit: BinaryMultiple::Tebi })] #[case("3.2Pi", MemoryQuantity { value: 3.2, unit: BinaryMultiple::Pebi })] #[case("0.2Ei", MemoryQuantity { value: 0.2, unit: BinaryMultiple::Exbi })] - fn test_memory_parse(#[case] input: &str, #[case] output: MemoryQuantity) { - let got = input.parse::().unwrap(); - assert_eq!(got, output); + fn from_str_pass(#[case] input: &str, #[case] expected: MemoryQuantity) { + let got = MemoryQuantity::from_str(input).unwrap(); + assert_eq!(got, expected); } #[rstest] @@ -539,22 +539,10 @@ mod test { #[case("1.2Gi")] #[case("1.6Gi")] #[case("1Gi")] - fn test_try_from_quantity(#[case] q: String) { - let m = MemoryQuantity::try_from(Quantity(q.clone())).unwrap(); - let actual = format!("{m}"); - assert_eq!(q, actual); - } - - #[rstest] - #[case("256Ki", 1.0, "-Xmx256k")] - #[case("256Ki", 0.8, "-Xmx205k")] - #[case("2Mi", 0.8, "-Xmx1638k")] - #[case("1.5Gi", 0.8, "-Xmx1229m")] - #[case("2Gi", 0.8, "-Xmx1638m")] - fn test_to_java_heap(#[case] q: &str, #[case] factor: f32, #[case] heap: &str) { - #[allow(deprecated)] // allow use of the deprecated 'to_java_heap' function to test it - let actual = to_java_heap(&Quantity(q.to_owned()), factor).unwrap(); - assert_eq!(heap, actual); + fn try_from_quantity(#[case] input: String) { + let quantity = MemoryQuantity::try_from(Quantity(input.clone())).unwrap(); + let actual = format!("{quantity}"); + assert_eq!(input, actual); } #[rstest] @@ -563,8 +551,8 @@ mod test { #[case("1.2Gi", "1228m")] #[case("1.6Gi", "1638m")] #[case("1Gi", "1g")] - fn test_format_java(#[case] q: String, #[case] expected: String) { - let m = MemoryQuantity::try_from(Quantity(q)).unwrap(); + fn format_java(#[case] input: String, #[case] expected: String) { + let m = MemoryQuantity::try_from(Quantity(input)).unwrap(); let actual = m.format_for_java().unwrap(); assert_eq!(expected, actual); } @@ -578,7 +566,7 @@ mod test { #[case(2000f32, BinaryMultiple::Pebi, BinaryMultiple::Mebi, 2000f32*1024f32*1024f32*1024f32)] #[case(2000f32, BinaryMultiple::Pebi, BinaryMultiple::Kibi, 2000f32*1024f32*1024f32*1024f32*1024f32)] #[case(2000f32, BinaryMultiple::Exbi, BinaryMultiple::Pebi, 2000f32*1024f32)] - fn test_scale_to( + fn scale_to( #[case] value: f32, #[case] unit: BinaryMultiple, #[case] target_unit: BinaryMultiple, @@ -602,7 +590,7 @@ mod test { #[case("2000Ki", 1.0, BinaryMultiple::Mebi, 1)] #[case("4000Mi", 1.0, BinaryMultiple::Gibi, 3)] #[case("4000Mi", 0.8, BinaryMultiple::Gibi, 3)] - fn test_to_java_heap_value( + fn to_java_heap_value_pass( #[case] q: &str, #[case] factor: f32, #[case] target_unit: BinaryMultiple, @@ -620,7 +608,7 @@ mod test { #[case("1000Mi", 1.0, BinaryMultiple::Gibi)] #[case("1023Mi", 1.0, BinaryMultiple::Gibi)] #[case("1024Mi", 0.8, BinaryMultiple::Gibi)] - fn test_to_java_heap_value_failure( + fn to_java_heap_value_fail( #[case] q: &str, #[case] factor: f32, #[case] target_unit: BinaryMultiple, @@ -635,7 +623,7 @@ mod test { #[case("1Mi", "512Ki", "512Ki")] #[case("2Mi", "512Ki", "1536Ki")] #[case("2048Ki", "1Mi", "1024Ki")] - fn test_subtraction(#[case] lhs: &str, #[case] rhs: &str, #[case] res: &str) { + fn subtraction(#[case] lhs: &str, #[case] rhs: &str, #[case] res: &str) { let lhs = MemoryQuantity::try_from(Quantity(lhs.to_owned())).unwrap(); let rhs = MemoryQuantity::try_from(Quantity(rhs.to_owned())).unwrap(); let expected = MemoryQuantity::try_from(Quantity(res.to_owned())).unwrap(); @@ -652,7 +640,7 @@ mod test { #[case("1Mi", "512Ki", "1536Ki")] #[case("2Mi", "512Ki", "2560Ki")] #[case("2048Ki", "1Mi", "3072Ki")] - fn test_addition(#[case] lhs: &str, #[case] rhs: &str, #[case] res: &str) { + fn addition(#[case] lhs: &str, #[case] rhs: &str, #[case] res: &str) { let lhs = MemoryQuantity::try_from(Quantity(lhs.to_owned())).unwrap(); let rhs = MemoryQuantity::try_from(Quantity(rhs.to_owned())).unwrap(); let expected = MemoryQuantity::try_from(Quantity(res.to_owned())).unwrap(); @@ -673,7 +661,7 @@ mod test { #[case("100Ki", "101Ki", false)] #[case("1Mi", "100Ki", true)] #[case("2000Ki", "1Mi", true)] - fn test_comparison(#[case] lhs: &str, #[case] rhs: &str, #[case] res: bool) { + fn partial_ord(#[case] lhs: &str, #[case] rhs: &str, #[case] res: bool) { let lhs = MemoryQuantity::try_from(Quantity(lhs.to_owned())).unwrap(); let rhs = MemoryQuantity::try_from(Quantity(rhs.to_owned())).unwrap(); assert_eq!(lhs > rhs, res) @@ -684,7 +672,7 @@ mod test { #[case("100Ki", "200Ki", false)] #[case("1Mi", "1024Ki", true)] #[case("1024Ki", "1Mi", true)] - fn test_eq(#[case] lhs: &str, #[case] rhs: &str, #[case] res: bool) { + fn partial_eq(#[case] lhs: &str, #[case] rhs: &str, #[case] res: bool) { let lhs = MemoryQuantity::try_from(Quantity(lhs.to_owned())).unwrap(); let rhs = MemoryQuantity::try_from(Quantity(rhs.to_owned())).unwrap(); assert_eq!(lhs == rhs, res) @@ -695,7 +683,7 @@ mod test { #[case(MemoryQuantity::from_mebi(100.0), "memory: 100Mi\n")] #[case(MemoryQuantity::from_gibi(10.0), "memory: 10Gi\n")] #[case(MemoryQuantity::from_gibi(1.0), "memory: 1Gi\n")] - fn test_serialize(#[case] memory: MemoryQuantity, #[case] expected: &str) { + fn serialize(#[case] memory: MemoryQuantity, #[case] expected: &str) { #[derive(Serialize)] struct Memory { memory: MemoryQuantity, @@ -712,7 +700,7 @@ mod test { #[case("memory: 100Mi", MemoryQuantity::from_mebi(100.0))] #[case("memory: 10Gi", MemoryQuantity::from_gibi(10.0))] #[case("memory: 1Gi", MemoryQuantity::from_gibi(1.0))] - fn test_deserialize(#[case] input: &str, #[case] expected: MemoryQuantity) { + fn deserialize(#[case] input: &str, #[case] expected: MemoryQuantity) { #[derive(Deserialize)] struct Memory { memory: MemoryQuantity, diff --git a/crates/stackable-operator/src/product_config_utils.rs b/crates/stackable-operator/src/product_config_utils.rs index 47f281614..1d1a68c6a 100644 --- a/crates/stackable-operator/src/product_config_utils.rs +++ b/crates/stackable-operator/src/product_config_utils.rs @@ -1041,7 +1041,7 @@ mod tests { } } )] - fn test_transform_role_to_config( + fn role_to_config( #[case] role_config: bool, #[case] group_config: bool, #[case] role_overrides: bool, @@ -1149,7 +1149,7 @@ mod tests { } } )] - fn test_order_in_transform_role_to_config( + fn order_in_transform_role_to_config( #[case] role_env_override: HashMap, #[case] group_env_override: HashMap, #[case] role_cli_override: BTreeMap, @@ -1192,7 +1192,7 @@ mod tests { } #[test] - fn test_transform_role_to_config_overrides() { + fn role_to_config_overrides() { let role_group = "role_group"; let file_name = "foo.bar"; let role = Role { @@ -1248,7 +1248,7 @@ mod tests { } #[test] - fn test_transform_all_roles_to_config() { + fn all_roles_to_config() { let role_1 = "role_1"; let role_2 = "role_2"; let role_group_1 = "role_group_1"; diff --git a/crates/stackable-operator/src/product_logging/framework.rs b/crates/stackable-operator/src/product_logging/framework.rs index 18795f7f3..d9de94672 100644 --- a/crates/stackable-operator/src/product_logging/framework.rs +++ b/crates/stackable-operator/src/product_logging/framework.rs @@ -1505,7 +1505,7 @@ mod tests { #[case("5Mi", &["1.5Mi"])] #[case("1Mi", &["100Ki"])] #[case("3076Mi", &["1Ki", "1Mi", "1Gi"])] - fn test_calculate_log_volume_size_limit( + fn log_volume_size_limit( #[case] expected_log_volume_size_limit: &str, #[case] max_log_files_sizes: &[&str], ) { @@ -1521,7 +1521,7 @@ mod tests { } #[test] - fn test_create_log4j2_config() { + fn log4j2_config() { let log_config = AutomaticContainerLogConfig { loggers: vec![( "ROOT".to_string(), @@ -1555,7 +1555,7 @@ mod tests { } #[test] - fn test_create_log4j2_config_with_additional_loggers() { + fn log4j2_config_with_additional_loggers() { let log_config = AutomaticContainerLogConfig { loggers: vec![ ( diff --git a/crates/stackable-operator/src/status/condition/daemonset.rs b/crates/stackable-operator/src/status/condition/daemonset.rs index 6bdc39b1b..ac4e5234d 100644 --- a/crates/stackable-operator/src/status/condition/daemonset.rs +++ b/crates/stackable-operator/src/status/condition/daemonset.rs @@ -87,12 +87,13 @@ impl DaemonSetConditionBuilder { } #[cfg(test)] -mod test { - use crate::status::condition::daemonset::DaemonSetConditionBuilder; +mod tests { + use k8s_openapi::api::apps::v1::{DaemonSet, DaemonSetStatus}; + use crate::status::condition::{ - ClusterCondition, ClusterConditionStatus, ClusterConditionType, ConditionBuilder, + daemonset::DaemonSetConditionBuilder, ClusterCondition, ClusterConditionStatus, + ClusterConditionType, ConditionBuilder, }; - use k8s_openapi::api::apps::v1::{DaemonSet, DaemonSetStatus}; fn build_ds(number_ready: i32) -> DaemonSet { DaemonSet { @@ -105,7 +106,7 @@ mod test { } #[test] - fn test_daemon_set_available_true() { + fn daemon_set_available() { let ds = build_ds(1); assert_eq!( @@ -115,7 +116,7 @@ mod test { } #[test] - fn test_daemon_set_available_false() { + fn daemon_set_unavailable() { let ds = build_ds(0); assert_eq!( DaemonSetConditionBuilder::daemon_set_available(&ds), @@ -124,7 +125,7 @@ mod test { } #[test] - fn test_daemon_set_available_condition_true() { + fn daemon_set_condition_available() { let mut ds_condition_builder = DaemonSetConditionBuilder::default(); ds_condition_builder.add(build_ds(1)); @@ -148,7 +149,7 @@ mod test { } #[test] - fn test_daemon_set_available_condition_false() { + fn daemon_set_condition_unavailable() { let mut ds_condition_builder = DaemonSetConditionBuilder::default(); ds_condition_builder.add(build_ds(0)); diff --git a/crates/stackable-operator/src/status/condition/mod.rs b/crates/stackable-operator/src/status/condition/mod.rs index a356c323e..c22b3028e 100644 --- a/crates/stackable-operator/src/status/condition/mod.rs +++ b/crates/stackable-operator/src/status/condition/mod.rs @@ -410,7 +410,7 @@ impl From> for ClusterConditionSet { } #[cfg(test)] -mod test { +mod tests { use super::*; struct TestClusterCondition {} @@ -491,7 +491,7 @@ mod test { } #[test] - pub fn test_compute_conditions_with_transition() { + fn compute_conditions_with_transition() { let resource = TestClusterCondition {}; let condition_builders = &[&AvailableTrueConditionBuilder1 {} as &dyn ConditionBuilder]; @@ -515,7 +515,7 @@ mod test { } #[test] - pub fn test_compute_conditions_message_concatenation() { + fn compute_conditions_message_concatenation() { let resource = TestClusterCondition {}; let condition_builders = &[ &AvailableTrueConditionBuilder1 {} as &dyn ConditionBuilder, @@ -542,7 +542,7 @@ mod test { } #[test] - pub fn test_compute_conditions_message_concatenation_with_different_status() { + fn compute_conditions_message_concatenation_with_different_status() { let resource = TestClusterCondition {}; let condition_builders = &[ &AvailableFalseConditionBuilder1 {} as &dyn ConditionBuilder, @@ -571,7 +571,7 @@ mod test { } #[test] - pub fn test_compute_conditions_status_priority() { + fn compute_conditions_status_priority() { let resource = TestClusterCondition {}; let condition_builders = &[ &AvailableUnknownConditionBuilder {} as &dyn ConditionBuilder, @@ -597,7 +597,7 @@ mod test { } #[test] - fn test_display_short() { + fn display_short() { let condition = ClusterCondition { type_: ClusterConditionType::Available, status: ClusterConditionStatus::False, @@ -620,7 +620,7 @@ mod test { } #[test] - fn test_display_long() { + fn display_long() { let condition = ClusterCondition { type_: ClusterConditionType::Available, status: ClusterConditionStatus::False, @@ -649,7 +649,7 @@ mod test { } #[test] - fn test_display_short_or_long() { + fn display_short_or_long() { let condition = ClusterCondition { type_: ClusterConditionType::Available, status: ClusterConditionStatus::False, diff --git a/crates/stackable-operator/src/status/condition/operations.rs b/crates/stackable-operator/src/status/condition/operations.rs index 55d747fbf..d90e0e0e3 100644 --- a/crates/stackable-operator/src/status/condition/operations.rs +++ b/crates/stackable-operator/src/status/condition/operations.rs @@ -86,7 +86,7 @@ impl<'a> ClusterOperationsConditionBuilder<'a> { } #[cfg(test)] -mod test { +mod tests { use super::*; use rstest::*; @@ -115,7 +115,7 @@ mod test { ClusterConditionStatus::True, ClusterConditionStatus::Unknown )] - fn test_cluster_operation_condition( + fn cluster_operation_condition( #[case] reconciliation_paused: bool, #[case] stopped: bool, #[case] expected_paused_status: ClusterConditionStatus, diff --git a/crates/stackable-operator/src/status/condition/statefulset.rs b/crates/stackable-operator/src/status/condition/statefulset.rs index 6a6d62a9f..baa79b41d 100644 --- a/crates/stackable-operator/src/status/condition/statefulset.rs +++ b/crates/stackable-operator/src/status/condition/statefulset.rs @@ -91,12 +91,13 @@ impl StatefulSetConditionBuilder { } #[cfg(test)] -mod test { - use crate::status::condition::statefulset::StatefulSetConditionBuilder; +mod tests { + use k8s_openapi::api::apps::v1::{StatefulSet, StatefulSetSpec, StatefulSetStatus}; + use crate::status::condition::{ - ClusterCondition, ClusterConditionStatus, ClusterConditionType, ConditionBuilder, + statefulset::StatefulSetConditionBuilder, ClusterCondition, ClusterConditionStatus, + ClusterConditionType, ConditionBuilder, }; - use k8s_openapi::api::apps::v1::{StatefulSet, StatefulSetSpec, StatefulSetStatus}; fn build_sts(spec_replicas: i32, available_replicas: i32) -> StatefulSet { StatefulSet { @@ -113,7 +114,7 @@ mod test { } #[test] - fn test_stateful_set_available_true() { + fn available() { let sts = build_sts(3, 3); assert_eq!( @@ -123,7 +124,7 @@ mod test { } #[test] - fn test_stateful_set_available_false() { + fn unavailable() { let sts = build_sts(3, 2); assert_eq!( @@ -140,7 +141,7 @@ mod test { } #[test] - fn test_stateful_set_available_condition_true() { + fn condition_available() { let mut sts_condition_builder = StatefulSetConditionBuilder::default(); sts_condition_builder.add(build_sts(3, 3)); @@ -164,7 +165,7 @@ mod test { } #[test] - fn test_stateful_set_available_condition_false() { + fn condition_unavailable() { let mut sts_condition_builder = StatefulSetConditionBuilder::default(); sts_condition_builder.add(build_sts(3, 2)); diff --git a/crates/stackable-operator/src/utils/crds.rs b/crates/stackable-operator/src/utils/crds.rs index 6994bc607..faed4cfdb 100644 --- a/crates/stackable-operator/src/utils/crds.rs +++ b/crates/stackable-operator/src/utils/crds.rs @@ -44,7 +44,7 @@ mod tests { } #[test] - fn test_valid_pod_override_with_tolerations() { + fn valid_pod_override_with_tolerations() { let input = r#" podOverrides: spec: @@ -59,7 +59,7 @@ mod tests { } #[test] - fn test_valid_pod_override_with_labels() { + fn valid_pod_override_with_labels() { let input = r#" podOverrides: metadata: @@ -71,7 +71,7 @@ mod tests { } #[test] - fn test_valid_pod_override_with_containers() { + fn valid_pod_override_with_containers() { let input = r#" podOverrides: spec: @@ -87,7 +87,7 @@ mod tests { } #[test] - fn test_valid_pod_override_with_containers_and_volumes() { + fn valid_pod_override_with_containers_and_volumes() { let input = r#" podOverrides: spec: @@ -111,7 +111,7 @@ mod tests { } #[test] - fn test_invalid_pod_override_missing_container_name() { + fn invalid_pod_override_missing_container_name() { let input = r#" podOverrides: spec: diff --git a/crates/stackable-operator/src/utils/option.rs b/crates/stackable-operator/src/utils/option.rs index 19baff332..e851644b1 100644 --- a/crates/stackable-operator/src/utils/option.rs +++ b/crates/stackable-operator/src/utils/option.rs @@ -48,10 +48,10 @@ impl OptionExt for Option { mod tests { use std::borrow::Cow; - use crate::utils::OptionExt as _; + use super::*; #[test] - fn test_as_ref_or_else() { + fn as_ref_or_else() { let maybe: Option = None; let defaulted: Cow = maybe.as_ref_or_else(|| "foo".to_string()); assert_eq!(defaulted, Cow::::Owned("foo".to_string())); @@ -62,7 +62,7 @@ mod tests { } #[test] - fn test_as_deref_or_else() { + fn as_deref_or_else() { let maybe: Option = None; let defaulted: Cow = maybe.as_deref_or_else(|| "foo".to_string()); assert_eq!(defaulted, Cow::::Owned("foo".to_string())); diff --git a/crates/stackable-operator/src/validation.rs b/crates/stackable-operator/src/validation.rs index 6cf4dbaaa..0b2e2b3f3 100644 --- a/crates/stackable-operator/src/validation.rs +++ b/crates/stackable-operator/src/validation.rs @@ -344,7 +344,7 @@ mod tests { #[case("a?b")] #[case("a$b")] #[case(&"a".repeat(254))] - fn test_bad_values_is_rfc_1123_subdomain(#[case] value: &str) { + fn is_rfc_1123_subdomain_fail(#[case] value: &str) { assert!(is_rfc_1123_subdomain(value).is_err()); } @@ -390,7 +390,7 @@ mod tests { #[case("1.2.3.4.5")] #[case("11.22.33.44.55")] #[case(&"a".repeat(253))] - fn test_good_values_is_rfc_1123_subdomain(#[case] value: &str) { + fn is_rfc_1123_subdomain_pass(#[case] value: &str) { assert!(is_rfc_1123_subdomain(value).is_ok()); } @@ -443,7 +443,7 @@ mod tests { #[case(" 1")] #[case("1 2")] #[case(&"a".repeat(64))] - fn test_bad_values_is_rfc_1035_label(#[case] value: &str) { + fn is_rfc_1035_label_fail(#[case] value: &str) { assert!(is_rfc_1035_label(value).is_err()); } @@ -455,7 +455,7 @@ mod tests { #[case("a-1")] #[case("a--1--2--b")] #[case(&"a".repeat(63))] - fn test_good_values_is_rfc_1035_label(#[case] value: &str) { + fn is_rfc_1035_label_pass(#[case] value: &str) { assert!(is_rfc_1035_label(value).is_ok()); } }