actix / actix/actix-web

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

Offen
#1,629 8 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
needs-investigation
Vorherrschende Sprache
Rust
Sterne
24.8k
Forks
1.9k
Ø Merge
23 Std. 10 Min.
Gemergte PRs (30 T.)
26

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.