I am using actix-web to write a small service. I'm adding integration tests to assess the functionality and have noticed that on every test I have to repeat the same definitions that in my main App except that it's wrapped by the test service:
let app = test::init_service(App::new().service(health_check)).await;
This can be easily extended if you have simple services but then when middleware and more configuration starts to be added tests start to get bulky, in addition it might be easy to miss something and not be assessing the same specs as the main App.
I've been trying to extract the App from the main thread to be able to reuse it my tests without success. Specifically what I'd like is to create a "factory" for the App:
pub fn get_app() -> App<????> {
App::new()
.wrap(Logger::default())
.wrap(IdentityService::new(policy))
.service(health_check)
.service(login)
}
So that I can write this in my tests
let app = get_app();
let service = test::init_service(app).await;
But the compiler needs the specific return type which seems to be a chorizo composed of several traits and structs, some private.
Has anyone experience with this?
Thanks!