31 lines
1.7 KiB
Rust
31 lines
1.7 KiB
Rust
// file: crates/ksp-app-config-desk/unit_tests/documents.rs
|
|
// version: 2
|
|
|
|
#[test]
|
|
fn diagnostic_classifier_distinguishes_json_schema_semantic_and_effective_errors() {
|
|
let json = ksp_core_lib::Error::new(ksp_config_lib::ERROR_CODE_JSON_SYNTAX_INVALID, "json");
|
|
assert_eq!(super::classify_error(&json), super::STAGE_JSON);
|
|
let schema = ksp_core_lib::Error::new(ksp_config_lib::ERROR_CODE_SCHEMA_VALIDATION_FAILED, "schema");
|
|
assert_eq!(super::classify_error(&schema), super::STAGE_SCHEMA);
|
|
let semantic = ksp_core_lib::Error::new(ksp_config_lib::ERROR_CODE_DOCUMENT_SEMANTIC_INVALID, "semantic");
|
|
assert_eq!(super::classify_error(&semantic), super::STAGE_SEMANTIC);
|
|
let effective = ksp_core_lib::Error::new(ksp_config_lib::ERROR_CODE_EFFECTIVE_CONFIG_INVALID, "effective");
|
|
assert_eq!(super::classify_error(&effective), super::STAGE_EFFECTIVE);
|
|
}
|
|
|
|
#[test]
|
|
fn schema_source_read_errors_are_classified_as_schema_failures() {
|
|
let error = ksp_core_lib::Error::new(ksp_config_lib::ERROR_CODE_JSON_FILE_READ_FAILED, "missing schema").with_context("file_id", "schema.std.logging");
|
|
assert_eq!(super::classify_error(&error), super::STAGE_SCHEMA);
|
|
}
|
|
|
|
#[test]
|
|
fn document_error_projection_does_not_expose_arbitrary_error_context() {
|
|
let error = ksp_core_lib::Error::new(ksp_config_lib::ERROR_CODE_JSON_SYNTAX_INVALID, "invalid source").with_context("detail", "sensitive-canary");
|
|
let projection = crate::ConfigDocumentErrorDto::from_error(&error);
|
|
assert_eq!(projection.diagnostic_stage, super::STAGE_JSON);
|
|
assert_eq!(projection.error.domain, "config");
|
|
assert_eq!(projection.error.code, "json_syntax_invalid");
|
|
assert_eq!(projection.error.message, "invalid source");
|
|
}
|