Skip to content

Commit

Permalink
cdh/kms: add unit test for offline-fs-kbc
Browse files Browse the repository at this point in the history
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
  • Loading branch information
Xynnn007 committed Feb 21, 2024
1 parent 5bdab54 commit c78fd35
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions confidential-data-hub/kms/src/plugins/kbs/offline_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,29 @@ impl OfflineFsKbc {
Ok(())
}
}

#[cfg(test)]
mod tests {
use resource_uri::ResourceUri;
use rstest::rstest;

use crate::plugins::kbs::{offline_fs::OfflineFsKbc, Kbc};

#[rstest]
#[tokio::test]
#[case("default/key/1", b"key1")]
async fn test_get_key(#[case] key: &str, #[case] value: &[u8]) {
let mut kbc = OfflineFsKbc {
resources: [(key.to_string(), value.to_vec())]
.iter()
.cloned()
.collect(),
};

let rid = ResourceUri::try_from(&format!("kbs:///{key}")[..]).unwrap();
assert_eq!(
kbc.get_resource(rid).await.expect("get key failed")[..],
*value
);
}
}

0 comments on commit c78fd35

Please sign in to comment.