136 lines
8.2 KiB
Rust
136 lines
8.2 KiB
Rust
// file: crates/ksp-config-lib/tests/public_api.rs
|
|
// version: 6
|
|
|
|
//! Integration tests for the public `ksp-config-lib` bootstrap, file registry, validated JSON document, profile-resolution and composite contracts.
|
|
|
|
#[test]
|
|
fn bootstrap_contract_is_available_from_crate_root() {
|
|
let result = ksp_config_lib::ConfigBootstrapOptions::defaults();
|
|
assert!(result.is_ok(), "default bootstrap options should be available: {result:?}");
|
|
if let std::result::Result::Ok(options) = result {
|
|
assert_eq!(options.cfg_path(), std::path::Path::new(ksp_config_lib::DEFAULT_CFG_PATH));
|
|
assert_eq!(options.schema_path(), std::path::Path::new(ksp_config_lib::DEFAULT_SCHEMA_PATH));
|
|
assert_eq!(ksp_config_lib::ARG_CFG_PATH, "--cfgpath");
|
|
assert_eq!(ksp_config_lib::ARG_SCHEMA_PATH, "--schemapath");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn programmatic_bootstrap_paths_are_independent() {
|
|
let result = ksp_config_lib::ConfigBootstrapOptions::from_paths("runtime-config", "runtime-schemas");
|
|
assert!(result.is_ok(), "programmatic bootstrap paths should be valid: {result:?}");
|
|
if let std::result::Result::Ok(options) = result {
|
|
assert_eq!(options.cfg_path(), std::path::Path::new("runtime-config"));
|
|
assert_eq!(options.schema_path(), std::path::Path::new("runtime-schemas"));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn cli_bootstrap_parser_is_available_from_crate_root() {
|
|
let args = [
|
|
std::ffi::OsString::from("consumer"),
|
|
std::ffi::OsString::from("--cfgpath=consumer-config"),
|
|
std::ffi::OsString::from("--schemapath"),
|
|
std::ffi::OsString::from("consumer-schemas"),
|
|
];
|
|
let result = ksp_config_lib::ConfigBootstrapOptions::from_args(&args);
|
|
assert!(result.is_ok(), "public bootstrap parser should accept KSP path arguments: {result:?}");
|
|
if let std::result::Result::Ok(options) = result {
|
|
assert_eq!(options.cfg_path(), std::path::Path::new("consumer-config"));
|
|
assert_eq!(options.schema_path(), std::path::Path::new("consumer-schemas"));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn logical_file_registry_is_available_from_crate_root() {
|
|
let args = [
|
|
std::ffi::OsString::from("consumer"),
|
|
std::ffi::OsString::from("--filemap=cfg.std.logging=consumer.logging.json"),
|
|
std::ffi::OsString::from("--filemap=schema.std.logging=consumer.logging.schema.json"),
|
|
];
|
|
let registry = ksp_config_lib::ConfigFileRegistry::from_args(&args);
|
|
let bootstrap = ksp_config_lib::ConfigBootstrapOptions::from_paths("consumer-config", "consumer-schemas");
|
|
let logging_id = ksp_config_lib::ConfigFileId::new(ksp_config_lib::FILE_ID_STD_LOGGING);
|
|
let schema_id = ksp_config_lib::ConfigFileId::new(ksp_config_lib::FILE_ID_SCHEMA_STD_LOGGING);
|
|
assert!(registry.is_ok(), "public registry should accept known filemap overrides: {registry:?}");
|
|
assert!(bootstrap.is_ok(), "bootstrap paths should remain available: {bootstrap:?}");
|
|
assert!(logging_id.is_ok(), "public logging file_id should be valid: {logging_id:?}");
|
|
assert!(schema_id.is_ok(), "public schema file_id should be valid: {schema_id:?}");
|
|
if let (std::result::Result::Ok(registry), std::result::Result::Ok(bootstrap), std::result::Result::Ok(logging_id), std::result::Result::Ok(schema_id)) =
|
|
(registry, bootstrap, logging_id, schema_id)
|
|
{
|
|
let logging = registry.resolve_path(&bootstrap, &logging_id);
|
|
let schema = registry.resolve_path(&bootstrap, &schema_id);
|
|
assert!(logging.is_ok(), "public logging path should resolve: {logging:?}");
|
|
assert!(schema.is_ok(), "public schema path should resolve: {schema:?}");
|
|
if let std::result::Result::Ok(logging) = logging {
|
|
assert_eq!(logging, std::path::PathBuf::from("consumer-config/consumer.logging.json"));
|
|
}
|
|
if let std::result::Result::Ok(schema) = schema {
|
|
assert_eq!(schema, std::path::PathBuf::from("consumer-schemas/consumer.logging.schema.json"));
|
|
}
|
|
assert_eq!(ksp_config_lib::ARG_FILE_MAP, "--filemap");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn validated_json_document_engine_is_available_from_crate_root() {
|
|
let workspace = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..");
|
|
let bootstrap = ksp_config_lib::ConfigBootstrapOptions::from_paths(workspace.join("config"), workspace.join("config/schemas"));
|
|
let registry = ksp_config_lib::ConfigFileRegistry::defaults();
|
|
let file_id = ksp_config_lib::ConfigFileId::new(ksp_config_lib::FILE_ID_STD_LOGGING);
|
|
assert!(bootstrap.is_ok(), "public bootstrap should accept committed Config roots: {bootstrap:?}");
|
|
assert!(registry.is_ok(), "public registry should remain constructible: {registry:?}");
|
|
assert!(file_id.is_ok(), "public Logging file_id should remain constructible: {file_id:?}");
|
|
if let (std::result::Result::Ok(bootstrap), std::result::Result::Ok(registry), std::result::Result::Ok(file_id)) = (bootstrap, registry, file_id) {
|
|
let engine = ksp_config_lib::ConfigDocumentEngine::new(bootstrap, registry);
|
|
let document = engine.load_validated_document(&file_id);
|
|
assert!(document.is_ok(), "public document engine should validate committed Logging configuration: {document:?}");
|
|
if let std::result::Result::Ok(document) = document {
|
|
assert_eq!(document.file_id(), &file_id);
|
|
assert_eq!(document.value().get("format_version"), std::option::Option::Some(&serde_json::Value::from(1)));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn resolved_profile_contract_is_available_from_crate_root() {
|
|
let workspace = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..");
|
|
let bootstrap = ksp_config_lib::ConfigBootstrapOptions::from_paths(workspace.join("config"), workspace.join("config/schemas"));
|
|
let registry = ksp_config_lib::ConfigFileRegistry::defaults();
|
|
let file_id = ksp_config_lib::ConfigFileId::new(ksp_config_lib::FILE_ID_STD_LOGGING);
|
|
assert!(bootstrap.is_ok(), "public bootstrap should accept committed Config roots: {bootstrap:?}");
|
|
assert!(registry.is_ok(), "public registry should remain constructible: {registry:?}");
|
|
assert!(file_id.is_ok(), "public Logging file_id should remain constructible: {file_id:?}");
|
|
if let (std::result::Result::Ok(bootstrap), std::result::Result::Ok(registry), std::result::Result::Ok(file_id)) = (bootstrap, registry, file_id) {
|
|
let engine = ksp_config_lib::ConfigDocumentEngine::new(bootstrap, registry);
|
|
let resolved = engine.load_resolved_profile(&file_id, std::option::Option::None);
|
|
assert!(resolved.is_ok(), "public profile resolver should resolve committed default profile: {resolved:?}");
|
|
if let std::result::Result::Ok(resolved) = resolved {
|
|
assert_eq!(resolved.profile_id(), "local_dev");
|
|
assert_eq!(resolved.selection_source(), ksp_config_lib::ConfigProfileSelectionSource::DefaultProfile);
|
|
assert_eq!(resolved.origin("logs_directory"), std::option::Option::Some(ksp_config_lib::ConfigValueOrigin::Global));
|
|
assert_eq!(resolved.origin("default_filter"), std::option::Option::Some(ksp_config_lib::ConfigValueOrigin::Profile));
|
|
assert!(!resolved.effective().contains_key("default_profile"));
|
|
assert!(!resolved.effective().contains_key("profiles"));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn composite_schema_and_provenance_contracts_are_available_from_crate_root() {
|
|
let registry = ksp_config_lib::ConfigFileRegistry::defaults();
|
|
let schema_id = ksp_config_lib::ConfigFileId::new(ksp_config_lib::FILE_ID_SCHEMA_COMPOSITE);
|
|
assert!(registry.is_ok(), "public registry should remain constructible: {registry:?}");
|
|
assert!(schema_id.is_ok(), "public composite schema file_id should be valid: {schema_id:?}");
|
|
if let (std::result::Result::Ok(registry), std::result::Result::Ok(schema_id)) = (registry, schema_id) {
|
|
let descriptor = registry.descriptor(&schema_id);
|
|
assert!(descriptor.is_ok(), "public composite schema descriptor should exist: {descriptor:?}");
|
|
if let std::result::Result::Ok(descriptor) = descriptor {
|
|
assert_eq!(descriptor.filename(), std::path::Path::new(ksp_config_lib::DEFAULT_COMPOSITE_SCHEMA_FILENAME));
|
|
assert_eq!(descriptor.kind(), ksp_config_lib::ConfigFileKind::Schema);
|
|
}
|
|
}
|
|
assert_ne!(ksp_config_lib::ConfigProfileSelectionSource::Composite, ksp_config_lib::ConfigProfileSelectionSource::Explicit);
|
|
}
|