use crate::core::HandlerFn;
#[derive(Debug, Clone, Copy)]
pub struct GrpcHandlerRegistration {
pub method: &'static str,
pub handler: HandlerFn,
pub body_param: Option<&'static str>,
}
inventory::collect!(GrpcHandlerRegistration);
#[cfg(test)]
mod tests {
use super::*;
use crate::core::{HandlerArgs, HandlerFuture, HandlerState};
use serde_json::Value;
fn assert_copy_clone<T: Copy + Clone>() {}
fn dummy_handler(_args: HandlerArgs, _state: HandlerState) -> HandlerFuture {
Box::pin(async { Ok(Value::Null) })
}
#[test]
fn grpc_handler_registration_is_copy() {
assert_copy_clone::<GrpcHandlerRegistration>();
}
inventory::submit! {
GrpcHandlerRegistration {
method: "test_probe",
handler: dummy_handler,
body_param: None,
}
}
#[test]
fn grpc_handler_registration_collected() {
let count = inventory::iter::<GrpcHandlerRegistration>().count();
assert!(count >= 1, "GrpcHandlerRegistration inventory empty");
let names: Vec<_> = inventory::iter::<GrpcHandlerRegistration>()
.map(|r| r.method)
.collect();
assert!(
names.contains(&"test_probe"),
"test_probe missing in {names:?}"
);
}
}