|
| 1 | +use etl_api::routes::pipelines::{ |
| 2 | + CreatePipelineRequest, CreatePipelineResponse, RollbackTableStateRequest, RollbackType, |
| 3 | +}; |
| 4 | +use etl_config::shared::PgConnectionConfig; |
| 5 | +use etl_postgres::sqlx::test_utils::drop_pg_database; |
| 6 | +use etl_telemetry::tracing::init_test_tracing; |
| 7 | +use reqwest::StatusCode; |
| 8 | +use sqlx::PgPool; |
| 9 | + |
| 10 | +use crate::common::database::create_test_source_database; |
| 11 | +use crate::common::test_app::{TestApp, spawn_test_app}; |
| 12 | +use crate::integration::destination_test::create_destination; |
| 13 | +use crate::integration::images_test::create_default_image; |
| 14 | +use crate::integration::tenants_test::create_tenant; |
| 15 | + |
| 16 | +async fn create_pipeline_with_unmigrated_source_db( |
| 17 | + app: &TestApp, |
| 18 | + tenant_id: &str, |
| 19 | +) -> (i64, PgPool, PgConnectionConfig) { |
| 20 | + let (source_pool, source_id, source_db_config) = |
| 21 | + create_test_source_database(app, tenant_id).await; |
| 22 | + let destination_id = create_destination(app, tenant_id).await; |
| 23 | + create_default_image(app).await; |
| 24 | + |
| 25 | + let req = CreatePipelineRequest { |
| 26 | + source_id, |
| 27 | + destination_id, |
| 28 | + config: crate::integration::pipelines_test::new_pipeline_config(), |
| 29 | + }; |
| 30 | + |
| 31 | + let response = app.create_pipeline(tenant_id, &req).await; |
| 32 | + let response: CreatePipelineResponse = response |
| 33 | + .json() |
| 34 | + .await |
| 35 | + .expect("failed to deserialize response"); |
| 36 | + |
| 37 | + (response.id, source_pool, source_db_config) |
| 38 | +} |
| 39 | + |
| 40 | +#[tokio::test(flavor = "multi_thread")] |
| 41 | +async fn replication_status_fails_when_etl_tables_missing() { |
| 42 | + init_test_tracing(); |
| 43 | + let app = spawn_test_app().await; |
| 44 | + let tenant_id = create_tenant(&app).await; |
| 45 | + |
| 46 | + let (pipeline_id, _source_pool, source_db_config) = |
| 47 | + create_pipeline_with_unmigrated_source_db(&app, &tenant_id).await; |
| 48 | + |
| 49 | + let response = app |
| 50 | + .get_pipeline_replication_status(&tenant_id, pipeline_id) |
| 51 | + .await; |
| 52 | + assert_eq!(response.status(), StatusCode::NOT_FOUND); |
| 53 | + assert!( |
| 54 | + response |
| 55 | + .text() |
| 56 | + .await |
| 57 | + .unwrap() |
| 58 | + .contains("The ETL table state has not been initialized first") |
| 59 | + ); |
| 60 | + |
| 61 | + drop_pg_database(&source_db_config).await; |
| 62 | +} |
| 63 | + |
| 64 | +#[tokio::test(flavor = "multi_thread")] |
| 65 | +async fn rollback_fails_when_etl_tables_missing() { |
| 66 | + init_test_tracing(); |
| 67 | + let app = spawn_test_app().await; |
| 68 | + let tenant_id = create_tenant(&app).await; |
| 69 | + |
| 70 | + let (pipeline_id, _source_pool, source_db_config) = |
| 71 | + create_pipeline_with_unmigrated_source_db(&app, &tenant_id).await; |
| 72 | + |
| 73 | + let req = RollbackTableStateRequest { |
| 74 | + table_id: 1, |
| 75 | + rollback_type: RollbackType::Individual, |
| 76 | + }; |
| 77 | + let response = app |
| 78 | + .rollback_table_state(&tenant_id, pipeline_id, &req) |
| 79 | + .await; |
| 80 | + assert_eq!(response.status(), StatusCode::NOT_FOUND); |
| 81 | + assert!( |
| 82 | + response |
| 83 | + .text() |
| 84 | + .await |
| 85 | + .unwrap() |
| 86 | + .contains("The ETL table state has not been initialized first") |
| 87 | + ); |
| 88 | + |
| 89 | + drop_pg_database(&source_db_config).await; |
| 90 | +} |
| 91 | + |
| 92 | +#[tokio::test(flavor = "multi_thread")] |
| 93 | +async fn deleting_pipeline_succeeds_when_etl_tables_missing() { |
| 94 | + init_test_tracing(); |
| 95 | + let app = spawn_test_app().await; |
| 96 | + let tenant_id = create_tenant(&app).await; |
| 97 | + |
| 98 | + let (pipeline_id, _source_pool, source_db_config) = |
| 99 | + create_pipeline_with_unmigrated_source_db(&app, &tenant_id).await; |
| 100 | + |
| 101 | + let response = app.delete_pipeline(&tenant_id, pipeline_id).await; |
| 102 | + assert_eq!(response.status(), StatusCode::OK); |
| 103 | + |
| 104 | + let response = app.read_pipeline(&tenant_id, pipeline_id).await; |
| 105 | + assert_eq!(response.status(), StatusCode::NOT_FOUND); |
| 106 | + |
| 107 | + drop_pg_database(&source_db_config).await; |
| 108 | +} |
0 commit comments