mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
add test for returning App from function
This commit is contained in:
parent
b41b346c00
commit
cea44be670
21
src/app.rs
21
src/app.rs
@ -706,4 +706,25 @@ mod tests {
|
|||||||
let body = read_body(resp).await;
|
let body = read_body(resp).await;
|
||||||
assert_eq!(body, Bytes::from_static(b"https://youtube.com/watch/12345"));
|
assert_eq!(body, Bytes::from_static(b"https://youtube.com/watch/12345"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// compile-only test for returning app type from function
|
||||||
|
pub fn foreign_app_type() -> App<
|
||||||
|
impl ServiceFactory<
|
||||||
|
ServiceRequest,
|
||||||
|
Response = ServiceResponse<impl MessageBody>,
|
||||||
|
Config = (),
|
||||||
|
InitError = (),
|
||||||
|
Error = Error,
|
||||||
|
>,
|
||||||
|
> {
|
||||||
|
App::new()
|
||||||
|
// logger can be removed without affecting the return type
|
||||||
|
.wrap(crate::middleware::Logger::default())
|
||||||
|
.route("/", web::to(|| async { "hello" }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn return_foreign_app_type() {
|
||||||
|
let _app = foreign_app_type();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,13 @@ use std::{
|
|||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_http::header::{
|
use actix_web::{
|
||||||
|
dev::BodyEncoding,
|
||||||
|
http::header::{
|
||||||
ContentEncoding, ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH, TRANSFER_ENCODING,
|
ContentEncoding, ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH, TRANSFER_ENCODING,
|
||||||
|
},
|
||||||
|
middleware::{Compress, NormalizePath, TrailingSlash},
|
||||||
|
web, App, Error, HttpResponse,
|
||||||
};
|
};
|
||||||
use brotli2::write::{BrotliDecoder, BrotliEncoder};
|
use brotli2::write::{BrotliDecoder, BrotliEncoder};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@ -31,10 +36,6 @@ use openssl::{
|
|||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use zstd::stream::{read::Decoder as ZstdDecoder, write::Encoder as ZstdEncoder};
|
use zstd::stream::{read::Decoder as ZstdDecoder, write::Encoder as ZstdEncoder};
|
||||||
|
|
||||||
use actix_web::dev::BodyEncoding;
|
|
||||||
use actix_web::middleware::{Compress, NormalizePath, TrailingSlash};
|
|
||||||
use actix_web::{web, App, Error, HttpResponse};
|
|
||||||
|
|
||||||
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
||||||
Hello World Hello World Hello World Hello World Hello World \
|
Hello World Hello World Hello World Hello World Hello World \
|
||||||
Hello World Hello World Hello World Hello World Hello World \
|
Hello World Hello World Hello World Hello World Hello World \
|
||||||
|
Loading…
Reference in New Issue
Block a user