Skip to content

Commit 07e27b5

Browse files
authored
ref(tests): Rework integration tests structure (#313)
* ref(tests): Rework structure of integration tests * Improve * Improve * Improve * Improve * Improve * Improve * Improve * Improve * Improve * Improve * Improve
1 parent a521abd commit 07e27b5

File tree

57 files changed

+442
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+442
-388
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,22 @@ jobs:
8888
8989
- name: Run tests
9090
run: |
91-
cargo test --workspace --no-fail-fast \
92-
--all-features -- --skip integration::bigquery_test
91+
cargo test \
92+
--workspace \
93+
--all-features \
94+
--no-fail-fast \
95+
--exclude etl-destinations \
96+
&& \
97+
cargo test \
98+
-p etl-destinations \
99+
--no-default-features \
100+
--no-fail-fast \
101+
--features iceberg
93102
94103
test-full:
95104
name: Test Full
96105
runs-on: ubuntu-latest
97-
# Run on non forks.
106+
# Run on non-forks.
98107
if: github.event.pull_request.head.repo.fork == false
99108
permissions:
100109
contents: read

etl-api/tests/common/mod.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

etl-api/tests/integration/destination_test.rs renamed to etl-api/tests/destinations.rs

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,24 @@
1-
use etl_api::configs::destination::FullApiDestinationConfig;
21
use etl_api::routes::destinations::{
32
CreateDestinationRequest, CreateDestinationResponse, ReadDestinationResponse,
43
ReadDestinationsResponse, UpdateDestinationRequest,
54
};
65
use etl_api::routes::pipelines::{CreatePipelineRequest, CreatePipelineResponse};
7-
use etl_config::SerializableSecretString;
86
use etl_telemetry::tracing::init_test_tracing;
97
use reqwest::StatusCode;
108

119
use crate::{
12-
common::test_app::{TestApp, spawn_test_app},
13-
integration::{
14-
images_test::create_default_image, pipelines_test::new_pipeline_config,
15-
sources_test::create_source, tenants_test::create_tenant,
10+
support::mocks::create_default_image,
11+
support::mocks::destinations::{
12+
create_destination, create_destination_with_config, new_destination_config, new_name,
13+
updated_destination_config, updated_name,
1614
},
15+
support::mocks::pipelines::new_pipeline_config,
16+
support::mocks::sources::create_source,
17+
support::mocks::tenants::create_tenant,
18+
support::test_app::spawn_test_app,
1719
};
1820

19-
pub fn new_name() -> String {
20-
"BigQuery Destination".to_string()
21-
}
22-
23-
pub fn new_destination_config() -> FullApiDestinationConfig {
24-
FullApiDestinationConfig::BigQuery {
25-
project_id: "project-id".to_string(),
26-
dataset_id: "dataset-id".to_string(),
27-
service_account_key: SerializableSecretString::from("service-account-key".to_string()),
28-
max_staleness_mins: None,
29-
max_concurrent_streams: Some(1),
30-
}
31-
}
32-
33-
pub fn updated_name() -> String {
34-
"BigQuery Destination (Updated)".to_string()
35-
}
36-
37-
pub fn updated_destination_config() -> FullApiDestinationConfig {
38-
FullApiDestinationConfig::BigQuery {
39-
project_id: "project-id-updated".to_string(),
40-
dataset_id: "dataset-id-updated".to_string(),
41-
service_account_key: SerializableSecretString::from(
42-
"service-account-key-updated".to_string(),
43-
),
44-
max_staleness_mins: Some(10),
45-
max_concurrent_streams: Some(1),
46-
}
47-
}
48-
49-
pub async fn create_destination_with_config(
50-
app: &TestApp,
51-
tenant_id: &str,
52-
name: String,
53-
config: FullApiDestinationConfig,
54-
) -> i64 {
55-
let destination = CreateDestinationRequest { name, config };
56-
let response = app.create_destination(tenant_id, &destination).await;
57-
let response: CreateDestinationResponse = response
58-
.json()
59-
.await
60-
.expect("failed to deserialize response");
61-
response.id
62-
}
63-
64-
pub async fn create_destination(app: &TestApp, tenant_id: &str) -> i64 {
65-
create_destination_with_config(app, tenant_id, new_name(), new_destination_config()).await
66-
}
21+
mod support;
6722

6823
#[tokio::test(flavor = "multi_thread")]
6924
async fn destination_can_be_created() {
@@ -122,7 +77,7 @@ async fn an_existing_destination_can_be_read() {
12277
}
12378

12479
#[tokio::test(flavor = "multi_thread")]
125-
async fn a_non_existing_destination_cant_be_read() {
80+
async fn non_existing_destination_cannot_be_read() {
12681
init_test_tracing();
12782
// Arrange
12883
let app = spawn_test_app().await;
@@ -176,7 +131,7 @@ async fn an_existing_destination_can_be_updated() {
176131
}
177132

178133
#[tokio::test(flavor = "multi_thread")]
179-
async fn a_non_existing_destination_cant_be_updated() {
134+
async fn non_existing_destination_cannot_be_updated() {
180135
init_test_tracing();
181136
// Arrange
182137
let app = spawn_test_app().await;
@@ -221,7 +176,7 @@ async fn an_existing_destination_can_be_deleted() {
221176
}
222177

223178
#[tokio::test(flavor = "multi_thread")]
224-
async fn a_non_existing_destination_cant_be_deleted() {
179+
async fn non_existing_destination_cannot_be_deleted() {
225180
init_test_tracing();
226181
// Arrange
227182
let app = spawn_test_app().await;

etl-api/tests/integration/destinations_pipelines_test.rs renamed to etl-api/tests/destinations_pipelines.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ use etl_api::routes::pipelines::{CreatePipelineRequest, ReadPipelineResponse};
77
use etl_telemetry::tracing::init_test_tracing;
88
use reqwest::StatusCode;
99

10-
use crate::common::database::{create_test_source_database, run_etl_migrations_on_source_database};
10+
use crate::support::database::{
11+
create_test_source_database, run_etl_migrations_on_source_database,
12+
};
1113
use crate::{
12-
common::test_app::spawn_test_app,
13-
integration::destination_test::{
14+
support::mocks::create_default_image,
15+
support::mocks::destinations::{
1416
create_destination, new_destination_config, new_name, updated_destination_config,
1517
updated_name,
1618
},
17-
integration::images_test::create_default_image,
18-
integration::pipelines_test::{new_pipeline_config, updated_pipeline_config},
19-
integration::sources_test::create_source,
20-
integration::tenants_test::{create_tenant, create_tenant_with_id_and_name},
19+
support::mocks::pipelines::{new_pipeline_config, updated_pipeline_config},
20+
support::mocks::sources::create_source,
21+
support::mocks::tenants::{create_tenant, create_tenant_with_id_and_name},
22+
support::test_app::spawn_test_app,
2123
};
2224

25+
mod support;
26+
2327
#[tokio::test(flavor = "multi_thread")]
2428
async fn destination_and_pipeline_can_be_created() {
2529
init_test_tracing();
@@ -75,7 +79,7 @@ async fn destination_and_pipeline_can_be_created() {
7579
}
7680

7781
#[tokio::test(flavor = "multi_thread")]
78-
async fn destination_and_pipeline_with_another_tenants_source_cant_be_created() {
82+
async fn destination_and_pipeline_with_another_tenants_source_cannot_be_created() {
7983
init_test_tracing();
8084
// Arrange
8185
let app = spawn_test_app().await;
@@ -177,7 +181,7 @@ async fn an_existing_destination_and_pipeline_can_be_updated() {
177181
}
178182

179183
#[tokio::test(flavor = "multi_thread")]
180-
async fn destination_and_pipeline_with_another_tenants_source_cant_be_updated() {
184+
async fn destination_and_pipeline_with_another_tenants_source_cannot_be_updated() {
181185
init_test_tracing();
182186
// Arrange
183187
let app = spawn_test_app().await;
@@ -236,7 +240,7 @@ async fn destination_and_pipeline_with_another_tenants_source_cant_be_updated()
236240
}
237241

238242
#[tokio::test(flavor = "multi_thread")]
239-
async fn destination_and_pipeline_with_another_tenants_destination_cant_be_updated() {
243+
async fn destination_and_pipeline_with_another_tenants_destination_cannot_be_updated() {
240244
init_test_tracing();
241245
// Arrange
242246
let app = spawn_test_app().await;
@@ -292,7 +296,7 @@ async fn destination_and_pipeline_with_another_tenants_destination_cant_be_updat
292296
}
293297

294298
#[tokio::test(flavor = "multi_thread")]
295-
async fn destination_and_pipeline_with_another_tenants_pipeline_cant_be_updated() {
299+
async fn destination_and_pipeline_with_another_tenants_pipeline_cannot_be_updated() {
296300
init_test_tracing();
297301
// Arrange
298302
let app = spawn_test_app().await;
@@ -369,7 +373,7 @@ async fn destination_and_pipeline_with_another_tenants_pipeline_cant_be_updated(
369373
}
370374

371375
#[tokio::test(flavor = "multi_thread")]
372-
async fn duplicate_destination_pipeline_with_same_source_cant_be_created() {
376+
async fn duplicate_destination_pipeline_with_same_source_cannot_be_created() {
373377
init_test_tracing();
374378
// Arrange
375379
let app = spawn_test_app().await;

etl-api/tests/integration/health_check_test.rs renamed to etl-api/tests/health_check.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use etl_telemetry::tracing::init_test_tracing;
22

3-
use crate::common::test_app::spawn_test_app;
3+
use crate::support::test_app::spawn_test_app;
4+
5+
mod support;
46

57
#[tokio::test(flavor = "multi_thread")]
6-
async fn health_check_works() {
8+
async fn health_check_returns_200() {
79
init_test_tracing();
810
// Arrange
911
let app = spawn_test_app().await;

etl-api/tests/integration/images_test.rs renamed to etl-api/tests/images.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,10 @@ use etl_api::routes::images::{
55
use etl_telemetry::tracing::init_test_tracing;
66
use reqwest::StatusCode;
77

8-
use crate::common::test_app::{TestApp, spawn_test_app};
8+
use crate::support::mocks::create_image_with_name;
9+
use crate::support::test_app::spawn_test_app;
910

10-
pub async fn create_default_image(app: &TestApp) -> i64 {
11-
create_image_with_name(app, "some/image".to_string(), true).await
12-
}
13-
14-
pub async fn create_image_with_name(app: &TestApp, name: String, is_default: bool) -> i64 {
15-
let image = CreateImageRequest { name, is_default };
16-
let response = app.create_image(&image).await;
17-
let response: CreateImageResponse = response
18-
.json()
19-
.await
20-
.expect("failed to deserialize response");
21-
response.id
22-
}
11+
mod support;
2312

2413
#[tokio::test(flavor = "multi_thread")]
2514
async fn image_can_be_created() {
@@ -77,7 +66,7 @@ async fn an_existing_image_can_be_read() {
7766
}
7867

7968
#[tokio::test(flavor = "multi_thread")]
80-
async fn a_non_existing_image_cant_be_read() {
69+
async fn non_existing_image_cannot_be_read() {
8170
init_test_tracing();
8271
// Arrange
8372
let app = spawn_test_app().await;
@@ -130,7 +119,7 @@ async fn an_existing_image_can_be_updated() {
130119
}
131120

132121
#[tokio::test(flavor = "multi_thread")]
133-
async fn a_non_existing_source_cant_be_updated() {
122+
async fn non_existing_image_cannot_be_updated() {
134123
init_test_tracing();
135124
// Arrange
136125
let app = spawn_test_app().await;
@@ -177,7 +166,7 @@ async fn an_existing_image_can_be_deleted() {
177166
}
178167

179168
#[tokio::test(flavor = "multi_thread")]
180-
async fn a_non_existing_image_cant_be_deleted() {
169+
async fn non_existing_image_cannot_be_deleted() {
181170
init_test_tracing();
182171
// Arrange
183172
let app = spawn_test_app().await;

etl-api/tests/integration/mod.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

etl-api/tests/integration/snapshots/r#mod__integration__pipelines_test__an_existing_pipeline_can_be_updated_without_config.snap

Lines changed: 0 additions & 20 deletions
This file was deleted.

etl-api/tests/integration/metrics_test.rs renamed to etl-api/tests/metrics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use etl_telemetry::tracing::init_test_tracing;
22

3-
use crate::common::test_app::spawn_test_app;
3+
use crate::support::test_app::spawn_test_app;
4+
5+
mod support;
46

57
#[tokio::test(flavor = "multi_thread")]
6-
async fn metrics_endpoint_works() {
8+
async fn metrics_endpoint_returns_200() {
79
init_test_tracing();
810
// Arrange
911
let app = spawn_test_app().await;

etl-api/tests/integration/etl_tables_missing_test.rs renamed to etl-api/tests/missing_etl_tables.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ use etl_telemetry::tracing::init_test_tracing;
77
use reqwest::StatusCode;
88
use sqlx::PgPool;
99

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;
10+
use crate::support::database::create_test_source_database;
11+
use crate::support::mocks::create_default_image;
12+
use crate::support::mocks::destinations::create_destination;
13+
use crate::support::mocks::tenants::create_tenant;
14+
use crate::support::test_app::{TestApp, spawn_test_app};
15+
16+
mod support;
1517

1618
async fn create_pipeline_with_unmigrated_source_db(
1719
app: &TestApp,
@@ -25,7 +27,7 @@ async fn create_pipeline_with_unmigrated_source_db(
2527
let req = CreatePipelineRequest {
2628
source_id,
2729
destination_id,
28-
config: crate::integration::pipelines_test::new_pipeline_config(),
30+
config: crate::support::mocks::pipelines::new_pipeline_config(),
2931
};
3032

3133
let response = app.create_pipeline(tenant_id, &req).await;

0 commit comments

Comments
 (0)