mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 08:22:59 +01:00
Add json2 tests
This commit is contained in:
parent
7a11c2eac1
commit
7c8dc4c201
@ -1193,6 +1193,30 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_json2() {
|
||||||
|
let resp = HttpResponse::build(StatusCode::OK).json2(&vec!["v1", "v2", "v3"]);
|
||||||
|
let ct = resp.headers().get(CONTENT_TYPE).unwrap();
|
||||||
|
assert_eq!(ct, HeaderValue::from_static("application/json"));
|
||||||
|
assert_eq!(
|
||||||
|
*resp.body(),
|
||||||
|
Body::from(Bytes::from_static(b"[\"v1\",\"v2\",\"v3\"]"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_json2_ct() {
|
||||||
|
let resp = HttpResponse::build(StatusCode::OK)
|
||||||
|
.header(CONTENT_TYPE, "text/json")
|
||||||
|
.json2(&vec!["v1", "v2", "v3"]);
|
||||||
|
let ct = resp.headers().get(CONTENT_TYPE).unwrap();
|
||||||
|
assert_eq!(ct, HeaderValue::from_static("text/json"));
|
||||||
|
assert_eq!(
|
||||||
|
*resp.body(),
|
||||||
|
Body::from(Bytes::from_static(b"[\"v1\",\"v2\",\"v3\"]"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
impl Body {
|
impl Body {
|
||||||
pub(crate) fn bin_ref(&self) -> &Binary {
|
pub(crate) fn bin_ref(&self) -> &Binary {
|
||||||
match *self {
|
match *self {
|
||||||
|
Loading…
Reference in New Issue
Block a user