v0.1.3-pre.008
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-config-lib/unit_tests/document.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
#[test]
|
||||
fn committed_logging_document_passes_registered_schema_and_semantic_validation() {
|
||||
@@ -143,6 +143,85 @@ fn schema_valid_logging_document_can_still_fail_ksp_semantics() {
|
||||
cleanup_fixture(&fixture);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_profile_ids_are_semantically_invalid() {
|
||||
let fixture = fixture_roots("duplicate-profile-id");
|
||||
let workspace = workspace_root();
|
||||
let schema_source = std::fs::read_to_string(workspace.join("config/schemas/std.logging.schema.json"));
|
||||
assert!(schema_source.is_ok(), "committed Logging schema should be readable: {schema_source:?}");
|
||||
if let std::result::Result::Ok(schema_source) = schema_source {
|
||||
let source = valid_logging_source_with_profiles("first", "first", "first");
|
||||
let prepared = prepare_fixture(&fixture, std::option::Option::Some(source.as_str()), schema_source.as_str());
|
||||
assert!(prepared.is_ok(), "duplicate profile fixture should be writable: {prepared:?}");
|
||||
if prepared.is_ok() {
|
||||
let result = load_fixture(&fixture);
|
||||
assert_error_code(result, crate::ERROR_CODE_DOCUMENT_SEMANTIC_INVALID);
|
||||
}
|
||||
}
|
||||
cleanup_fixture(&fixture);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_default_profile_target_is_semantically_invalid() {
|
||||
let fixture = fixture_roots("missing-default-profile");
|
||||
let workspace = workspace_root();
|
||||
let schema_source = std::fs::read_to_string(workspace.join("config/schemas/std.logging.schema.json"));
|
||||
assert!(schema_source.is_ok(), "committed Logging schema should be readable: {schema_source:?}");
|
||||
if let std::result::Result::Ok(schema_source) = schema_source {
|
||||
let source = valid_logging_source_with_profiles("missing", "first", "second");
|
||||
let prepared = prepare_fixture(&fixture, std::option::Option::Some(source.as_str()), schema_source.as_str());
|
||||
assert!(prepared.is_ok(), "missing default profile fixture should be writable: {prepared:?}");
|
||||
if prepared.is_ok() {
|
||||
let result = load_fixture(&fixture);
|
||||
assert_error_code(result, crate::ERROR_CODE_DOCUMENT_SEMANTIC_INVALID);
|
||||
}
|
||||
}
|
||||
cleanup_fixture(&fixture);
|
||||
}
|
||||
|
||||
fn valid_logging_source_with_profiles(default_profile: &str, first_profile: &str, second_profile: &str) -> String {
|
||||
return format!(
|
||||
r#"{{
|
||||
"format_version": 1,
|
||||
"logs_directory": "logs",
|
||||
"default_profile": "{default_profile}",
|
||||
"profiles": [
|
||||
{},
|
||||
{}
|
||||
]
|
||||
}}"#,
|
||||
valid_logging_profile(first_profile, "file.first"),
|
||||
valid_logging_profile(second_profile, "file.second")
|
||||
);
|
||||
}
|
||||
|
||||
fn valid_logging_profile(profile_id: &str, output_id: &str) -> String {
|
||||
return format!(
|
||||
r#"{{
|
||||
"profile_id": "{profile_id}",
|
||||
"default_filter": "info",
|
||||
"span_events": "off",
|
||||
"console": {{
|
||||
"enabled": false,
|
||||
"output": "stderr",
|
||||
"ansi": false,
|
||||
"format": "human",
|
||||
"filter": {{"level": "trace", "targets": ["*"], "domains": ["*"]}}
|
||||
}},
|
||||
"files": [{{
|
||||
"output_id": "{output_id}",
|
||||
"enabled": true,
|
||||
"path": "output.log",
|
||||
"rotation": "daily",
|
||||
"format": "human",
|
||||
"ansi": false,
|
||||
"filter": {{"level": "info", "targets": ["*"], "domains": ["*"]}}
|
||||
}}],
|
||||
"target_filters": []
|
||||
}}"#
|
||||
);
|
||||
}
|
||||
|
||||
fn load_fixture(fixture: &FixtureRoots) -> ksp_core_lib::Result<super::ConfigJsonDocument> {
|
||||
let bootstrap = crate::ConfigBootstrapOptions::from_paths(fixture.config.as_path(), fixture.schemas.as_path());
|
||||
let bootstrap = match bootstrap {
|
||||
@@ -212,7 +291,7 @@ struct FixtureRoots {
|
||||
|
||||
fn fixture_roots(name: &str) -> FixtureRoots {
|
||||
let mut root = std::env::temp_dir();
|
||||
root.push(format!("ksp-config-lib-pre007-{name}-{}", std::process::id()));
|
||||
root.push(format!("ksp-config-lib-pre008-{name}-{}", std::process::id()));
|
||||
return FixtureRoots { config: root.join("config"), schemas: root.join("schemas"), root };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user