Skip to main content

oxirs_vec/multi_tenancy/
admission_controller.rs

1//! Compatibility shim — the admission controller has moved to
2//! [`oxirs_core::sla::admission_controller`].
3//!
4//! The `From<AdmissionError> for MultiTenancyError` conversion stays here
5//! (rather than in `oxirs-core`) because [`MultiTenancyError`] is local to
6//! `oxirs-vec` and Rust's orphan rule forbids implementing a foreign trait for
7//! a foreign error.
8
9use crate::multi_tenancy::types::MultiTenancyError;
10
11pub use oxirs_core::sla::{AdmissionController, AdmissionError};
12
13impl From<AdmissionError> for MultiTenancyError {
14    fn from(err: AdmissionError) -> Self {
15        match err {
16            AdmissionError::RateLimitExceeded { tenant_id } => {
17                MultiTenancyError::RateLimitExceeded { tenant_id }
18            }
19            AdmissionError::TenantNotRegistered { tenant_id } => {
20                MultiTenancyError::TenantNotFound { tenant_id }
21            }
22        }
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use oxirs_core::sla::SlaClass;
30
31    #[test]
32    fn test_admission_error_converts_to_multi_tenancy_error() {
33        let err = AdmissionError::RateLimitExceeded {
34            tenant_id: "x".into(),
35        };
36        let mt_err: MultiTenancyError = err.into();
37        assert!(matches!(
38            mt_err,
39            MultiTenancyError::RateLimitExceeded { .. }
40        ));
41
42        let err = AdmissionError::TenantNotRegistered {
43            tenant_id: "y".into(),
44        };
45        let mt_err: MultiTenancyError = err.into();
46        assert!(matches!(mt_err, MultiTenancyError::TenantNotFound { .. }));
47    }
48
49    #[test]
50    fn test_admission_controller_re_exported() {
51        // Smoke test to confirm the re-exported types behave correctly through
52        // the shim path.
53        let ctrl = AdmissionController::new();
54        ctrl.register_tenant("vec_tenant", SlaClass::Silver);
55        assert!(ctrl.try_admit("vec_tenant").is_ok());
56    }
57}