2 years ago
#209790

mcfly
Rollback integration test
I'm currently trying to create a simple integration test that for example try the signup endpoint. Coming from many other backend languages I'm used to rollback database after each test.
How can I do this using sqlx? Is there any way to start sqlx with some kind of test transaction ?
I don't find anything on this.
    #[actix_rt::test]
    async fn signup_test() {
        let params = SignupRequest {
            login: "bruce8@wayne.com".into(),
            password: "testtest123".into(),
        };
        let app_state = AppState::init().await;
        let mut app = test::init_service(
            App::new()
                .app_data(web::Data::new(app_state.clone()))
                .configure(configure),
        )
        .await;
        let req = test::TestRequest::post() //
            .insert_header(("content-type", "application/json"))
            .set_json(params)
            .uri("/auth")
            .to_request();
        let resp = test::call_service(&mut app, req).await;
        log::info!("----> {}", resp.status());
        assert!(resp.status().is_success());
    }
postgresql
rust
rust-actix
rust-sqlx
0 Answers
Your Answer