Configured routes passed to `test::init_service()` all failed with code 500, internal server error
- Lingua principale
- Rust
- Stelle
- 24.8k
- Fork
- 1.9k
- Merge medio
- 23h 10m
- PR unite (30g)
- 26
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.