55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
use admin_api::error::{runtime_error_context, runtime_test_failure};
|
|
use crank_runtime::RuntimeError;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn runtime_test_failure_includes_structured_context() {
|
|
let payload = runtime_test_failure(&RuntimeError::InvalidPreparedRequest {
|
|
field: "request.headers".to_owned(),
|
|
reason: "must be an object".to_owned(),
|
|
});
|
|
|
|
assert_eq!(payload["code"], "runtime_request_error");
|
|
assert_eq!(
|
|
payload["context"],
|
|
json!({
|
|
"field": "request.headers",
|
|
"reason": "must be an object"
|
|
})
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn runtime_error_context_includes_secret_crypto_operation() {
|
|
let context = runtime_error_context(&RuntimeError::SecretCrypto {
|
|
operation: "decode secret envelope",
|
|
details: "bad base64".to_owned(),
|
|
})
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
|
context,
|
|
json!({
|
|
"operation": "decode secret envelope",
|
|
"details": "bad base64"
|
|
})
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn runtime_test_failure_includes_runtime_overload_context() {
|
|
let payload = runtime_test_failure(&RuntimeError::ConcurrencyLimitExceeded {
|
|
kind: "window",
|
|
limit: 16,
|
|
});
|
|
|
|
assert_eq!(payload["code"], "runtime_overloaded");
|
|
assert_eq!(
|
|
payload["context"],
|
|
json!({
|
|
"kind": "window",
|
|
"limit": 16
|
|
})
|
|
);
|
|
}
|