pub struct TestResponse {
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Bytes,
/* private fields */
}Expand description
HTTP 响应
包含 HTTP 响应的状态码、响应头和响应体。
Fields§
§status: StatusCode响应状态码
headers: HeaderMap响应头
body: Bytes响应体
Implementations§
Source§impl TestResponse
impl TestResponse
Sourcepub fn new(status: StatusCode, headers: HeaderMap, body: Bytes) -> Self
pub fn new(status: StatusCode, headers: HeaderMap, body: Bytes) -> Self
创建新的测试响应
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
获取响应状态码
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
检查响应状态码是否成功 (200-299)
Sourcepub fn header<K: TryInto<HeaderName>>(&self, key: K) -> Option<&HeaderValue>
pub fn header<K: TryInto<HeaderName>>(&self, key: K) -> Option<&HeaderValue>
获取指定响应头
Sourcepub fn text(&self) -> TestingResult<String>
pub fn text(&self) -> TestingResult<String>
将响应体解析为字符串
Sourcepub fn json<T: DeserializeOwned>(&self) -> TestingResult<T>
pub fn json<T: DeserializeOwned>(&self) -> TestingResult<T>
将响应体解析为 JSON
Sourcepub fn assert_status(&self, status: StatusCode) -> TestingResult<&Self>
pub fn assert_status(&self, status: StatusCode) -> TestingResult<&Self>
断言响应状态码
Sourcepub fn assert_success(&self) -> TestingResult<&Self>
pub fn assert_success(&self) -> TestingResult<&Self>
断言响应是成功状态码 (200-299)
Sourcepub fn assert_header<K: TryInto<HeaderName>>(
&self,
key: K,
) -> TestingResult<&Self>
pub fn assert_header<K: TryInto<HeaderName>>( &self, key: K, ) -> TestingResult<&Self>
断言响应头存在
Sourcepub fn assert_header_eq<K, V>(&self, key: K, value: V) -> TestingResult<&Self>
pub fn assert_header_eq<K, V>(&self, key: K, value: V) -> TestingResult<&Self>
断言响应头值
Sourcepub fn assert_body_contains(&self, text: &str) -> TestingResult<&Self>
pub fn assert_body_contains(&self, text: &str) -> TestingResult<&Self>
断言响应体包含指定文本
Sourcepub fn request_method(&self) -> &Method
pub fn request_method(&self) -> &Method
获取请求方法(用于测试追踪)
Sourcepub fn request_url(&self) -> &str
pub fn request_url(&self) -> &str
获取请求 URL(用于测试追踪)
Trait Implementations§
Source§impl Clone for TestResponse
impl Clone for TestResponse
Source§fn clone(&self) -> TestResponse
fn clone(&self) -> TestResponse
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !Freeze for TestResponse
impl RefUnwindSafe for TestResponse
impl Send for TestResponse
impl Sync for TestResponse
impl Unpin for TestResponse
impl UnsafeUnpin for TestResponse
impl UnwindSafe for TestResponse
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