From 0544204734f396766e81e2c3420a93ebe2f802fd Mon Sep 17 00:00:00 2001 From: Niladri Halder Date: Wed, 25 Sep 2024 14:30:34 +0000 Subject: [PATCH] fix: use heck instead of covert_case for Train-Case The Train-Case implementation on the covert_case crate seems to convert 'ma8' to 'Ma-8'. This isn't the expected result. Heck seems to get it right, 'Ma8'. Signed-off-by: Niladri Halder --- Cargo.lock | 4 ++-- call-home/Cargo.toml | 2 +- call-home/src/common/constants.rs | 7 +++++-- constants/Cargo.toml | 2 +- constants/src/lib.rs | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66363aeef..ba605bb69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -581,9 +581,9 @@ dependencies = [ "chrono", "clap", "constants", - "convert_case", "events-api", "futures", + "heck", "humantime", "jsonpath_lib", "k8s-openapi", @@ -705,7 +705,7 @@ checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" name = "constants" version = "0.1.0" dependencies = [ - "convert_case", + "heck", "utils", ] diff --git a/call-home/Cargo.toml b/call-home/Cargo.toml index 12490cdd7..f9b0196c2 100644 --- a/call-home/Cargo.toml +++ b/call-home/Cargo.toml @@ -19,7 +19,6 @@ path = "src/bin/stats/main.rs" [dependencies] constants = { path = "../constants" } -convert_case = "0.4.0" openapi = {path = "../dependencies/control-plane/openapi"} kube = { version = "0.85.0", features = ["runtime", "derive"] } k8s-openapi = { version = "0.19.0", features = ["v1_20"] } @@ -56,3 +55,4 @@ mime = "0.3.17" # parse prometheus output prometheus-parse = "0.2.4" +heck = "0.4.1" diff --git a/call-home/src/common/constants.rs b/call-home/src/common/constants.rs index 4e3c6cb34..91f27cc11 100644 --- a/call-home/src/common/constants.rs +++ b/call-home/src/common/constants.rs @@ -1,4 +1,4 @@ -use convert_case::{Case::Train, Casing}; +use heck::ToTrainCase; use std::{ env, path::{Path, PathBuf}, @@ -13,7 +13,7 @@ pub fn product() -> String { env::var(CALLHOME_PRODUCT_NAME_ENV) .ok() .filter(|v| !v.is_empty()) - .map(|v| v.to_case(Train)) + .map(|v| v.to_train_case()) .unwrap_or(::constants::product_train()) } @@ -154,6 +154,9 @@ mod tests { use crate::common::constants::{product, CALLHOME_PRODUCT_NAME_ENV}; use std::env::{remove_var as unset, set_var as set}; + set(CALLHOME_PRODUCT_NAME_ENV, "ma8"); + assert_eq!(product(), "Ma8".to_string()); + set(CALLHOME_PRODUCT_NAME_ENV, "foo bar"); assert_eq!(product(), "Foo-Bar".to_string()); diff --git a/constants/Cargo.toml b/constants/Cargo.toml index 53053fbbf..cec9e1a48 100644 --- a/constants/Cargo.toml +++ b/constants/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" [dependencies] utils = {path = "../dependencies/control-plane/utils/utils-lib" } -convert_case = "0.4.0" \ No newline at end of file +heck = "0.4.1" diff --git a/constants/src/lib.rs b/constants/src/lib.rs index d03e3e918..f608b1e39 100644 --- a/constants/src/lib.rs +++ b/constants/src/lib.rs @@ -1,10 +1,10 @@ -use convert_case::Casing; +use heck::ToTrainCase; use utils::constants::PRODUCT_DOMAIN_NAME; pub use utils::PRODUCT_NAME; /// Name of the product. pub fn product_train() -> String { - PRODUCT_NAME.to_case(convert_case::Case::Train) + PRODUCT_NAME.to_train_case() } /// Helm release name label's key.