From f6e93c20944ee9d8f6bab99f21834d6b13c600c1 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Wed, 10 Sep 2025 08:13:01 +0000 Subject: [PATCH] libs: Fix test_get_uds_with_sid_with_zero Test case for `get_uds_with_sid` with an empty run directory would not hit the 0 match arm, i.e. "sandbox with the provided prefix {short_id:?} is not found", because `get_uds_with_sid` will try to create the directory with provided short id before detecting `target_id`. Signed-off-by: Ruoqing He --- src/libs/shim-interface/src/lib.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libs/shim-interface/src/lib.rs b/src/libs/shim-interface/src/lib.rs index 9bc607442a..2863b84e2b 100644 --- a/src/libs/shim-interface/src/lib.rs +++ b/src/libs/shim-interface/src/lib.rs @@ -158,21 +158,20 @@ mod tests { #[test] fn test_get_uds_with_sid_with_zero() { - let result = get_uds_with_sid("acdsdfe", KATA_PATH); - assert!(result.is_err()); - if let Err(err) = result { - let left = format!("{:?}", err.to_string()); - let left_unquoted = &left[1..left.len() - 1]; - let left_unescaped = left_unquoted.replace("\\\"", "\""); - - assert_eq!( - left_unescaped, - format!( - "sandbox with the provided prefix {:?} is not found", - "acdsdfe" - ) + let run_path = tempdir().unwrap(); + let result = get_uds_with_sid("acdsdfe", &run_path.path().display().to_string()); + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + format!( + "unix://{}", + run_path + .path() + .join("acdsdfe") + .join(SHIM_MGMT_SOCK_NAME) + .display() ) - } + ) } #[test]