oxidite_testing/
response.rs1use serde::de::DeserializeOwned;
2use http::StatusCode;
3
4pub struct TestResponse {
6 status: StatusCode,
7 body: Vec<u8>,
8}
9
10impl TestResponse {
11 pub fn new(status: StatusCode, body: Vec<u8>) -> Self {
13 Self { status, body }
14 }
15
16 pub fn status(&self) -> StatusCode {
18 self.status
19 }
20
21 pub fn body(&self) -> &[u8] {
23 &self.body
24 }
25
26 pub fn text(&self) -> Result<String, std::string::FromUtf8Error> {
28 String::from_utf8(self.body.clone())
29 }
30
31 pub fn json<T: DeserializeOwned>(&self) -> Result<T, serde_json::Error> {
33 serde_json::from_slice(&self.body)
34 }
35
36 pub fn is_success(&self) -> bool {
38 self.status.is_success()
39 }
40}