77 lines
2.5 KiB
Rust
77 lines
2.5 KiB
Rust
use std::path::Path;
|
|
|
|
use rpki::storage::{FetchCachePpKey, RocksStore};
|
|
|
|
#[test]
|
|
fn storage_opens_and_creates_column_families() {
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
let _store = RocksStore::open(dir.path()).expect("open rocksdb");
|
|
}
|
|
|
|
#[test]
|
|
fn raw_objects_roundtrip_by_rsync_uri() {
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
let store = RocksStore::open(dir.path()).expect("open rocksdb");
|
|
|
|
let key = "rsync://example.invalid/repo/a.cer";
|
|
let value = b"hello";
|
|
store.put_raw(key, value).expect("put raw");
|
|
let got = store.get_raw(key).expect("get raw");
|
|
assert_eq!(got.as_deref(), Some(value.as_slice()));
|
|
|
|
store.delete_raw(key).expect("delete raw");
|
|
let got = store.get_raw(key).expect("get raw after delete");
|
|
assert!(got.is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn fetch_cache_pp_roundtrip_by_manifest_uri() {
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
let store = RocksStore::open(dir.path()).expect("open rocksdb");
|
|
|
|
let manifest_uri = "rsync://example.invalid/repo/manifest.mft";
|
|
let key = FetchCachePpKey::from_manifest_rsync_uri(manifest_uri);
|
|
assert_eq!(
|
|
key.as_str(),
|
|
"fetch_cache_pp:rsync://example.invalid/repo/manifest.mft"
|
|
);
|
|
|
|
let bytes = b"pack";
|
|
store
|
|
.put_fetch_cache_pp(&key, bytes)
|
|
.expect("put fetch_cache_pp");
|
|
let got = store.get_fetch_cache_pp(&key).expect("get fetch_cache_pp");
|
|
assert_eq!(got.as_deref(), Some(bytes.as_slice()));
|
|
}
|
|
|
|
#[test]
|
|
fn rrdp_state_roundtrip_by_notification_uri() {
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
let store = RocksStore::open(dir.path()).expect("open rocksdb");
|
|
|
|
let notif = "https://example.invalid/rrdp/notification.xml";
|
|
let state = b"{\"session_id\":\"00000000-0000-0000-0000-000000000000\",\"last_serial\":1}";
|
|
store.put_rrdp_state(notif, state).expect("put rrdp_state");
|
|
|
|
let got = store.get_rrdp_state(notif).expect("get rrdp_state");
|
|
assert_eq!(got.as_deref(), Some(state.as_slice()));
|
|
}
|
|
|
|
#[test]
|
|
fn store_is_reopenable() {
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
let path: &Path = dir.path();
|
|
|
|
let store = RocksStore::open(path).expect("open rocksdb");
|
|
store
|
|
.put_raw("rsync://example.invalid/repo/x", b"x")
|
|
.expect("put");
|
|
drop(store);
|
|
|
|
let store = RocksStore::open(path).expect("reopen rocksdb");
|
|
let got = store
|
|
.get_raw("rsync://example.invalid/repo/x")
|
|
.expect("get after reopen");
|
|
assert_eq!(got.as_deref(), Some(b"x".as_slice()));
|
|
}
|