protocols: Fix the noise caused by non-formatted codes in protocols

```
-            decoded.strip_prefix("CAP_").unwrap_or(decoded)
+            decoded
+                .strip_prefix("CAP_")
+                .unwrap_or(decoded)
                 .parse::<oci::Capability>()
                 .unwrap_or_else(|_| panic!("Failed to parse {:?} to
Enum Capability", cap))
         })
@@ -1318,8 +1320,6 @@ mod tests {
     #[test]
     #[should_panic]
     fn test_cap_vec2hashset_bad() {
-        cap_vec2hashset(vec![
-            "CAP_DOES_NOT_EXIST".to_string(),
-        ]);
+        cap_vec2hashset(vec!["CAP_DOES_NOT_EXIST".to_string()]);
```

Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
alex.lyn 2025-05-30 17:54:50 +08:00
parent 9488ce822d
commit 65931fb75f
2 changed files with 9 additions and 9 deletions

View File

@ -9,6 +9,7 @@ pub mod agent;
pub mod agent_ttrpc;
#[cfg(feature = "async")]
pub mod agent_ttrpc_async;
pub mod api;
pub mod csi;
pub mod empty;
mod gogo;
@ -17,15 +18,14 @@ pub mod health_ttrpc;
#[cfg(feature = "async")]
pub mod health_ttrpc_async;
pub mod oci;
#[cfg(feature = "with-serde")]
mod serde_config;
pub mod trans;
pub mod types;
pub mod remote;
pub mod remote_ttrpc;
#[cfg(feature = "async")]
pub mod remote_ttrpc_async;
pub mod api;
#[cfg(feature = "with-serde")]
mod serde_config;
pub mod trans;
pub mod types;
#[cfg(feature = "with-serde")]
pub use serde_config::{

View File

@ -42,7 +42,9 @@ fn cap_vec2hashset(caps: Vec<String>) -> HashSet<oci::Capability> {
.map(|cap: &String| {
// cap might be JSON-encoded
let decoded: &str = serde_json::from_str(cap).unwrap_or(cap);
decoded.strip_prefix("CAP_").unwrap_or(decoded)
decoded
.strip_prefix("CAP_")
.unwrap_or(decoded)
.parse::<oci::Capability>()
.unwrap_or_else(|_| panic!("Failed to parse {:?} to Enum Capability", cap))
})
@ -1318,8 +1320,6 @@ mod tests {
#[test]
#[should_panic]
fn test_cap_vec2hashset_bad() {
cap_vec2hashset(vec![
"CAP_DOES_NOT_EXIST".to_string(),
]);
cap_vec2hashset(vec!["CAP_DOES_NOT_EXIST".to_string()]);
}
}