pub struct MockHttpResponse {
pub status: u16,
pub headers: Vec<(String, String)>,
pub body: String,
}Expand description
Canned response of a mocked HTTP step.
A non-2xx status is not an error, exactly like the real
HttpExecutor: the status lands in the
step output. A transport failure is expressed by returning
Err(OperationError::Http { status: None, .. }) from the mock closure.
§Examples
use ironflow_engine::testing::MockHttpResponse;
use serde_json::json;
let created = MockHttpResponse::json(201, &json!({"id": 7}))
.header("location", "/things/7");
assert_eq!(created.status, 201);
assert_eq!(created.headers, vec![("location".to_string(), "/things/7".to_string())]);Fields§
§status: u16HTTP status code the step reports.
headers: Vec<(String, String)>Response headers, in insertion order.
body: StringRaw response body.
Implementations§
Source§impl MockHttpResponse
impl MockHttpResponse
Sourcepub fn ok(body: &Value) -> Self
pub fn ok(body: &Value) -> Self
A 200 OK carrying body serialized as JSON.
§Examples
use ironflow_engine::testing::MockHttpResponse;
use serde_json::json;
let response = MockHttpResponse::ok(&json!({"ok": true}));
assert_eq!(response.status, 200);
assert_eq!(response.body, r#"{"ok":true}"#);Sourcepub fn json(status: u16, body: &Value) -> Self
pub fn json(status: u16, body: &Value) -> Self
A response with the given status carrying body serialized as JSON.
§Examples
use ironflow_engine::testing::MockHttpResponse;
use serde_json::json;
let response = MockHttpResponse::json(404, &json!({"error": "not found"}));
assert_eq!(response.status, 404);Trait Implementations§
Source§impl Clone for MockHttpResponse
impl Clone for MockHttpResponse
Source§impl Debug for MockHttpResponse
impl Debug for MockHttpResponse
Source§impl Default for MockHttpResponse
impl Default for MockHttpResponse
impl Eq for MockHttpResponse
Source§impl PartialEq for MockHttpResponse
impl PartialEq for MockHttpResponse
impl StructuralPartialEq for MockHttpResponse
Auto Trait Implementations§
impl Freeze for MockHttpResponse
impl RefUnwindSafe for MockHttpResponse
impl Send for MockHttpResponse
impl Sync for MockHttpResponse
impl Unpin for MockHttpResponse
impl UnsafeUnpin for MockHttpResponse
impl UnwindSafe for MockHttpResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.