Skip to content

Commit 4a63d74

Browse files
authored
Merge pull request #31 from SakaDream/downgrade-actix-rt
Downgrade actix-rt and add some startup unit tests
2 parents c43b207 + 80760e0 commit 4a63d74

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66

77
[dependencies]
88
actix-web = "3.3.2"
9-
actix-rt = "2.0.2"
9+
actix-rt = "1.1.1"
1010
actix-service = "1.0.6"
1111
actix-cors = "0.5.4"
1212
log = "0.4.14"

src/main.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,61 @@ async fn main() -> io::Result<()> {
7373
.run()
7474
.await
7575
}
76+
77+
#[cfg(test)]
78+
mod tests {
79+
use crate::config;
80+
use actix_web::{http, HttpServer, App};
81+
use futures::FutureExt;
82+
use actix_service::Service;
83+
use actix_cors::Cors;
84+
85+
#[actix_rt::test]
86+
async fn test_startup_ok() {
87+
HttpServer::new(move || {
88+
App::new()
89+
.wrap(Cors::default() // allowed_origin return access-control-allow-origin: * by default
90+
// .allowed_origin("http://127.0.0.1:8080")
91+
.send_wildcard()
92+
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE"])
93+
.allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
94+
.allowed_header(http::header::CONTENT_TYPE)
95+
.max_age(3600))
96+
.data(config::db::migrate_and_config_db(":memory:"))
97+
.wrap(actix_web::middleware::Logger::default())
98+
.wrap(crate::middleware::authen_middleware::Authentication)
99+
.wrap_fn(|req, srv| {
100+
srv.call(req).map(|res| res)
101+
})
102+
.configure(config::app::config_services)
103+
})
104+
.bind("localhost:8000".to_string()).unwrap()
105+
.run();
106+
107+
assert_eq!(true, true);
108+
}
109+
110+
#[actix_rt::test]
111+
async fn test_startup_without_auth_middleware_ok() {
112+
HttpServer::new(move || {
113+
App::new()
114+
.wrap(Cors::default() // allowed_origin return access-control-allow-origin: * by default
115+
// .allowed_origin("http://127.0.0.1:8080")
116+
.send_wildcard()
117+
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE"])
118+
.allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
119+
.allowed_header(http::header::CONTENT_TYPE)
120+
.max_age(3600))
121+
.data(config::db::migrate_and_config_db(":memory:"))
122+
.wrap(actix_web::middleware::Logger::default())
123+
.wrap_fn(|req, srv| {
124+
srv.call(req).map(|res| res)
125+
})
126+
.configure(config::app::config_services)
127+
})
128+
.bind("localhost:8001".to_string()).unwrap()
129+
.run();
130+
131+
assert_eq!(true, true);
132+
}
133+
}

0 commit comments

Comments
 (0)