mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-14 05:19:21 +00:00
Merge pull request #11775 from RuoqingHe/fix-test_execute_hook
libs: Fix unit tests under non-root user
This commit is contained in:
@@ -375,7 +375,11 @@ mod tests {
|
||||
fn build_oci_hook(self) -> oci::Hook {
|
||||
let mut hook = oci::Hook::default();
|
||||
hook.set_path(PathBuf::from(self.path));
|
||||
hook.set_args(Some(self.args));
|
||||
if self.args.is_empty() {
|
||||
hook.set_args(None);
|
||||
} else {
|
||||
hook.set_args(Some(self.args));
|
||||
}
|
||||
hook.set_env(Some(self.env));
|
||||
hook.set_timeout(self.timeout);
|
||||
|
||||
|
@@ -216,6 +216,11 @@ mod tests {
|
||||
// Test snp
|
||||
let dir = tempdir().unwrap();
|
||||
let snp_file_path = dir.path().join("sev_snp");
|
||||
if !snp_file_path.exists() {
|
||||
println!("INFO: skipping {} which needs sev_snp", module_path!());
|
||||
return;
|
||||
}
|
||||
|
||||
let path = snp_file_path.clone();
|
||||
let mut snp_file = fs::File::create(snp_file_path).unwrap();
|
||||
writeln!(snp_file, "Y").unwrap();
|
||||
@@ -235,6 +240,11 @@ mod tests {
|
||||
// Test sev
|
||||
let dir = tempdir().unwrap();
|
||||
let sev_file_path = dir.path().join("sev");
|
||||
if !sev_file_path.exists() {
|
||||
println!("INFO: skipping {} which needs sev", module_path!());
|
||||
return;
|
||||
}
|
||||
|
||||
let sev_path = sev_file_path.clone();
|
||||
let mut sev_file = fs::File::create(sev_file_path).unwrap();
|
||||
writeln!(sev_file, "Y").unwrap();
|
||||
@@ -257,6 +267,11 @@ mod tests {
|
||||
let invalid_dir = invalid_dir.to_str().unwrap();
|
||||
|
||||
let tdx_file_path = dir.path().join("tdx");
|
||||
if !tdx_file_path.exists() {
|
||||
println!("INFO: skipping {} which needs tdx", module_path!());
|
||||
return;
|
||||
}
|
||||
|
||||
let tdx_path = tdx_file_path;
|
||||
|
||||
std::fs::create_dir_all(tdx_path.clone()).unwrap();
|
||||
|
@@ -138,10 +138,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_get_uds_with_sid_ok() {
|
||||
let run_path = tempdir().unwrap();
|
||||
let dir1 = run_path.path().join("kata98654sandboxpath1");
|
||||
let dir2 = run_path.path().join("aata98654dangboxpath1");
|
||||
fs::create_dir_all(dir1.as_path()).unwrap();
|
||||
fs::create_dir_all(dir2.as_path()).unwrap();
|
||||
let dir = run_path.path().join("aata98654dangboxpath1");
|
||||
fs::create_dir_all(dir.as_path()).unwrap();
|
||||
|
||||
let result = get_uds_with_sid("kata", &run_path.path().display().to_string());
|
||||
assert!(result.is_ok());
|
||||
@@ -151,7 +149,7 @@ mod tests {
|
||||
"unix://{}",
|
||||
run_path
|
||||
.path()
|
||||
.join("kata98654sandboxpath1")
|
||||
.join("kata")
|
||||
.join(SHIM_MGMT_SOCK_NAME)
|
||||
.display()
|
||||
)
|
||||
@@ -160,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]
|
||||
|
Reference in New Issue
Block a user