actix / actix/actix-web

Configured routes passed to `test::init_service()` all failed with code 500, internal server error

未关闭
#1,629 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
needs-investigation
主要语言
Rust
星标
24.8k
派生
1.9k
平均合并
23 小时 10 分钟
30 天内合并 PR
26

描述

So, in my integration test I setup up the app instance like recommended with init_service and configure the routes and the state:
```rust
let mut app = test::init_service(
App::new()
.data(db_pool)
.service(web::scope("/decks").configure(decks::init_routes))
.route("/", web::get().to(index)),
)
.await;
```
whereas `init_routes` is in a separate module & looks like this:
```rust
pub fn init_routes(config: &mut web::ServiceConfig) {
config.service(
web::resource("/")
.route(web::get().to(view_all)) // get all decks from the database
.route(web::post().to(create_deck)), // create a new deck in the database
);
config.service(web::resource("{deck_id}").route(web::get().to(view))); // get a specified deck from the database
config.service(web::resource("/delete/{deck_id}").route(web::delete().to(delete_deck))); // delete a specified deck
config.service(web::resource("/edit/{deck_id}").route(web::patch().to(edit_deck)));
// edit a specified deck
}
```
However, when calling any of my configured routes in init_routes with
```rust
let req = test::TestRequest::get().uri("/decks/").to_request();
let resp = test::call_service(&mut app, req).await;
assert_eq!(resp.status(), 200);
```
All of the routes respond with a HTTP 500 internal server error, instead of delivering the actual data. This is strange, since the same init_routes method is used with HttpServer::new() and it works there. It seems that only the "root route" works and properly responds.

So I am wondering if this is a problem with `init_service` since I am following here the recommended way from the docs.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。