初始化 Panda RPKI v0.1.0 开源候选版本
This commit is contained in:
52
src/repository/storage/tests.rs
Normal file
52
src/repository/storage/tests.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
// Storage tests are grouped by the public storage surface they protect.
|
||||
use super::*;
|
||||
use rocksdb::{DB, Options};
|
||||
use sha2::Digest;
|
||||
|
||||
fn sha256_hex(bytes: &[u8]) -> String {
|
||||
hex::encode(sha2::Sha256::digest(bytes))
|
||||
}
|
||||
|
||||
fn pack_time(seconds: i64) -> PackTime {
|
||||
PackTime::from_utc_offset_datetime(
|
||||
time::OffsetDateTime::UNIX_EPOCH + time::Duration::seconds(seconds),
|
||||
)
|
||||
}
|
||||
|
||||
fn sample_repository_view_entry(uri: &str, bytes: &[u8]) -> RepositoryViewEntry {
|
||||
RepositoryViewEntry {
|
||||
rsync_uri: uri.to_string(),
|
||||
current_hash: Some(sha256_hex(bytes)),
|
||||
repository_source: Some("fixture".to_string()),
|
||||
object_type: Some("roa".to_string()),
|
||||
state: RepositoryViewState::Present,
|
||||
}
|
||||
}
|
||||
|
||||
fn sample_raw_by_hash_entry(bytes: Vec<u8>) -> RawByHashEntry {
|
||||
RawByHashEntry::from_bytes(sha256_hex(&bytes), bytes)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_an_unsupported_state_schema_fails_without_rewriting() {
|
||||
let td = tempfile::tempdir().expect("tempdir");
|
||||
let mut options = Options::default();
|
||||
options.create_if_missing(true);
|
||||
options.create_missing_column_families(true);
|
||||
let legacy = DB::open_cf(&options, td.path(), ["legacy_private_state"])
|
||||
.expect("create legacy state database");
|
||||
drop(legacy);
|
||||
|
||||
match RocksStore::open(td.path()) {
|
||||
Err(StorageError::InvalidData {
|
||||
entity: "state_schema",
|
||||
detail,
|
||||
}) => assert!(detail.contains("legacy_private_state")),
|
||||
Err(error) => panic!("unexpected schema error: {error}"),
|
||||
Ok(_) => panic!("legacy schema must be rejected"),
|
||||
}
|
||||
}
|
||||
|
||||
include!("tests_parts/repository.rs");
|
||||
include!("tests_parts/rrdp.rs");
|
||||
include!("tests_parts/object_loading.rs");
|
||||
Reference in New Issue
Block a user