Files
khadhroony-solana-project/crates/ksp-config-lib/tests/public_api.rs
2026-08-15 19:17:09 +02:00

75 lines
3.9 KiB
Rust

// file: crates/ksp-config-lib/tests/public_api.rs
// version: 3
//! Integration tests for the public `ksp-config-lib` bootstrap and logical file registry 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");
}
}