54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
// 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");
|
|
include!("tests_parts/manifest_history.rs");
|