Skip to main content

execution_engine_core/framework/
assertions.rs

1// Copyright 2024 Vincents AI
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Plugin assertion utilities for testing
5//!
6//! This module provides assertion helpers for testing plugin behavior.
7
8use super::service::MockPlugin;
9
10/// Trait for plugin assertions
11pub trait PluginAssertions {
12    /// Assert the plugin is in a specific state
13    fn assert_state(&self, expected_state: &str);
14
15    /// Assert the plugin has a specific capability
16    fn assert_has_capability(&self, capability: &str);
17
18    /// Assert the plugin's health status
19    fn assert_health_status(&self, expected_status: &str);
20}
21
22impl PluginAssertions for MockPlugin {
23    fn assert_state(&self, _expected_state: &str) {
24        // For mock plugins, we just verify the plugin exists
25        // Real state tracking would require a state field
26    }
27
28    fn assert_has_capability(&self, capability: &str) {
29        assert!(
30            self.has_capability(capability),
31            "Plugin '{}' does not have capability '{}'",
32            self.name(),
33            capability
34        );
35    }
36
37    fn assert_health_status(&self, _expected_status: &str) {
38        // For mock plugins, we just verify the plugin exists
39        // Real health status tracking would require a health field
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_assert_has_capability_passes() {
49        let plugin = MockPlugin::builder("test")
50            .with_capability("test.action")
51            .build();
52        plugin.assert_has_capability("test.action"); // Should not panic
53    }
54
55    #[test]
56    #[should_panic(expected = "does not have capability")]
57    fn test_assert_has_capability_fails() {
58        let plugin = MockPlugin::builder("test").build();
59        plugin.assert_has_capability("missing.action"); // Should panic
60    }
61
62    #[test]
63    fn test_assert_state() {
64        let plugin = MockPlugin::builder("test").build();
65        plugin.assert_state("any"); // For mock, this always passes
66    }
67
68    #[test]
69    fn test_assert_health_status() {
70        let plugin = MockPlugin::builder("test").build();
71        plugin.assert_health_status("healthy"); // For mock, this always passes
72    }
73}