actix / actix/actix-web

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

オープン
#1,629 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る
needs-investigation
主要言語
Rust
スター
24.8k
フォーク
1.9k
平均マージ
23時間 10分
マージ済み PR(30日)
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 を短くまとめたダイジェスト。