Skip to main content

camel_component_mock/
expectations.rs

1//! Expectations recorded on a mock endpoint for batch-style assertion.
2
3/// Expectations set on a mock endpoint for batch-style assertion.
4///
5/// Use [`crate::MockEndpointInner::expect_body`] and
6/// [`crate::MockEndpointInner::expect_header`] to populate expectations, then
7/// call [`crate::MockEndpointInner::assert_satisfied`] after exchanges have
8/// been received.
9pub struct MockExpectations {
10    pub(crate) expected_bodies: Vec<camel_component_api::Body>,
11    pub(crate) expected_headers: Vec<(String, serde_json::Value)>,
12    pub(crate) expected_header_regexes: Vec<(String, String)>,
13    /// Exact exchange-count expectation enforced by
14    /// [`crate::MockEndpointInner::assert_satisfied`].
15    pub(crate) expected_count: Option<usize>,
16    /// Minimum exchange-count expectation enforced by
17    /// [`crate::MockEndpointInner::assert_satisfied`].
18    pub(crate) minimum_count: Option<usize>,
19}
20
21impl Default for MockExpectations {
22    fn default() -> Self {
23        Self::new()
24    }
25}
26
27impl MockExpectations {
28    /// Create an empty set of expectations.
29    pub fn new() -> Self {
30        Self {
31            expected_bodies: Vec::new(),
32            expected_headers: Vec::new(),
33            expected_header_regexes: Vec::new(),
34            expected_count: None,
35            minimum_count: None,
36        }
37    }
38
39    /// Add an expected body value.
40    pub fn push_body(&mut self, body: camel_component_api::Body) {
41        self.expected_bodies.push(body);
42    }
43
44    /// Add an expected header key-value pair.
45    pub fn push_header(&mut self, key: String, value: serde_json::Value) {
46        self.expected_headers.push((key, value));
47    }
48
49    /// Add an expected header regex pattern.
50    pub fn push_header_regex(&mut self, key: String, pattern: String) {
51        self.expected_header_regexes.push((key, pattern));
52    }
53
54    /// Set the exact expected exchange count.
55    pub(crate) fn set_expected_count(&mut self, n: usize) {
56        self.expected_count = Some(n);
57    }
58
59    /// Set the minimum expected exchange count.
60    pub(crate) fn set_minimum_count(&mut self, n: usize) {
61        self.minimum_count = Some(n);
62    }
63}