Rollback integration test

316 Views Asked by At

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: "[email protected]".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());
    }
0

There are 0 best solutions below