Skip to content

Commit dc59585

Browse files
authored
cleanup(integration-tests): dedup code (googleapis#3413)
1 parent 12d0ec8 commit dc59585

File tree

16 files changed

+48
-429
lines changed

16 files changed

+48
-429
lines changed

src/integration-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ publish = false
2020
version = "0.0.0"
2121

2222
[features]
23-
log-integration-tests = ["dep:tracing-subscriber"]
23+
log-integration-tests = []
2424
# These are normally disabled because they run against production.
2525
run-integration-tests = []
2626
# These are normally disabled because they require installing the golang
@@ -43,7 +43,7 @@ rand = { workspace = true, features = ["thread_rng"] }
4343
serde_json.workspace = true
4444
tokio = { workspace = true, features = ["process"] }
4545
tracing.workspace = true
46-
tracing-subscriber = { workspace = true, optional = true, features = ["fmt", "std"] }
46+
tracing-subscriber = { workspace = true, features = ["fmt", "std"] }
4747
uuid = { workspace = true, features = ["std", "v4"] }
4848
wkt.workspace = true
4949

src/integration-tests/src/aiplatform.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@
1515
use crate::Result;
1616

1717
pub async fn locational_endpoint() -> Result<()> {
18-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
19-
// verify tracing is doing something.
20-
#[cfg(feature = "log-integration-tests")]
21-
let _guard = {
22-
use tracing_subscriber::fmt::format::FmtSpan;
23-
let subscriber = tracing_subscriber::fmt()
24-
.with_level(true)
25-
.with_thread_ids(true)
26-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
27-
.finish();
28-
29-
tracing::subscriber::set_default(subscriber)
30-
};
31-
3218
let project_id = crate::project_id()?;
3319
let location_id = "us-central1";
3420
let client = aiplatform::client::ModelService::builder()

src/integration-tests/src/bigquery.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ use rand::{Rng, distr::Alphanumeric};
2020
const INSTANCE_LABEL: &str = "rust-sdk-integration-test";
2121

2222
pub async fn dataset_admin() -> Result<()> {
23-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
24-
// verify tracing is doing something.
25-
#[cfg(feature = "log-integration-tests")]
26-
let _guard = {
27-
use tracing_subscriber::fmt::format::FmtSpan;
28-
let subscriber = tracing_subscriber::fmt()
29-
.with_level(true)
30-
.with_thread_ids(true)
31-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
32-
.finish();
33-
34-
tracing::subscriber::set_default(subscriber)
35-
};
36-
3723
let project_id = crate::project_id()?;
3824
let client = bigquery::client::DatasetService::builder()
3925
.with_tracing()
@@ -189,20 +175,6 @@ fn extract_dataset_id(project_id: &str, id: &str) -> Option<String> {
189175
}
190176

191177
pub async fn job_service() -> Result<()> {
192-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
193-
// verify tracing is doing something.
194-
#[cfg(feature = "log-integration-tests")]
195-
let _guard = {
196-
use tracing_subscriber::fmt::format::FmtSpan;
197-
let subscriber = tracing_subscriber::fmt()
198-
.with_level(true)
199-
.with_thread_ids(true)
200-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
201-
.finish();
202-
203-
tracing::subscriber::set_default(subscriber)
204-
};
205-
206178
let project_id = crate::project_id()?;
207179
let client = bigquery::client::JobService::builder()
208180
.with_tracing()

src/integration-tests/src/compute.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ use compute::client::Zones;
1717
use gax::paginator::ItemPaginator as _;
1818

1919
pub async fn zones() -> Result<()> {
20-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
21-
// verify tracing is doing something.
22-
#[cfg(feature = "log-integration-tests")]
23-
let _guard = {
24-
use tracing_subscriber::fmt::format::FmtSpan;
25-
let subscriber = tracing_subscriber::fmt()
26-
.with_level(true)
27-
.with_thread_ids(true)
28-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
29-
.finish();
30-
31-
tracing::subscriber::set_default(subscriber)
32-
};
33-
3420
let client = Zones::builder().with_tracing().build().await?;
3521
let project_id = crate::project_id()?;
3622

src/integration-tests/src/error_details.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ use gax::retry_policy::{AlwaysRetry, RetryPolicyExt};
1717
use storage::client::StorageControl;
1818

1919
pub async fn error_details_http() -> Result<()> {
20-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
21-
// verify tracing is doing something.
22-
#[cfg(feature = "log-integration-tests")]
23-
let _guard = {
24-
use tracing_subscriber::fmt::format::FmtSpan;
25-
let subscriber = tracing_subscriber::fmt()
26-
.with_level(true)
27-
.with_thread_ids(true)
28-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
29-
.finish();
30-
31-
tracing::subscriber::set_default(subscriber)
32-
};
33-
3420
let project_id = crate::project_id()?;
3521
let region_id = crate::region_id();
3622
let client = ta::client::TelcoAutomation::builder()
@@ -55,18 +41,6 @@ pub async fn error_details_http() -> Result<()> {
5541
}
5642

5743
pub async fn error_details_grpc() -> Result<()> {
58-
#[cfg(feature = "log-integration-tests")]
59-
let _guard = {
60-
use tracing_subscriber::fmt::format::FmtSpan;
61-
let subscriber = tracing_subscriber::fmt()
62-
.with_level(true)
63-
.with_thread_ids(true)
64-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
65-
.finish();
66-
67-
tracing::subscriber::set_default(subscriber)
68-
};
69-
7044
let client = StorageControl::builder().with_tracing().build().await?;
7145
let err = client
7246
.get_bucket()
@@ -83,18 +57,6 @@ pub async fn error_details_grpc() -> Result<()> {
8357
}
8458

8559
pub async fn check_code_for_http() -> Result<()> {
86-
#[cfg(feature = "log-integration-tests")]
87-
let _guard = {
88-
use tracing_subscriber::fmt::format::FmtSpan;
89-
let subscriber = tracing_subscriber::fmt()
90-
.with_level(true)
91-
.with_thread_ids(true)
92-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
93-
.finish();
94-
95-
tracing::subscriber::set_default(subscriber)
96-
};
97-
9860
let project_id = crate::project_id()?;
9961
let location_id = crate::region_id();
10062
let workflow_id = crate::random_workflow_id();
@@ -121,18 +83,6 @@ pub async fn check_code_for_http() -> Result<()> {
12183
}
12284

12385
pub async fn check_code_for_grpc() -> Result<()> {
124-
#[cfg(feature = "log-integration-tests")]
125-
let _guard = {
126-
use tracing_subscriber::fmt::format::FmtSpan;
127-
let subscriber = tracing_subscriber::fmt()
128-
.with_level(true)
129-
.with_thread_ids(true)
130-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
131-
.finish();
132-
133-
tracing::subscriber::set_default(subscriber)
134-
};
135-
13686
let bucket_id = crate::random_bucket_id();
13787
let bucket_name = format!("projects/_/buckets/{bucket_id}");
13888
let client = StorageControl::builder().with_tracing().build().await?;

src/integration-tests/src/firestore.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,6 @@ fn new_collection_id() -> String {
3131
}
3232

3333
pub async fn basic() -> Result<()> {
34-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
35-
// verify tracing is doing something.
36-
#[cfg(feature = "log-integration-tests")]
37-
let _guard = {
38-
use tracing_subscriber::fmt::format::FmtSpan;
39-
let subscriber = tracing_subscriber::fmt()
40-
.with_level(true)
41-
.with_thread_ids(true)
42-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
43-
.finish();
44-
45-
tracing::subscriber::set_default(subscriber)
46-
};
47-
4834
let client = Firestore::builder().with_tracing().build().await?;
4935
cleanup_stale_documents(&client).await?;
5036

src/integration-tests/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,17 @@ pub(crate) fn random_workflow_id() -> String {
7777
.collect();
7878
format!("{PREFIX}{workflow_id}")
7979
}
80+
81+
pub fn enable_tracing() -> tracing::subscriber::DefaultGuard {
82+
use tracing_subscriber::fmt::format::FmtSpan;
83+
let builder = tracing_subscriber::fmt()
84+
.with_level(true)
85+
.with_thread_ids(true)
86+
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
87+
.with_max_level(tracing::Level::WARN);
88+
#[cfg(feature = "log-integration-tests")]
89+
let builder = builder.with_max_level(tracing::Level::INFO);
90+
let subscriber = builder.finish();
91+
92+
tracing::subscriber::set_default(subscriber)
93+
}

src/integration-tests/src/pubsub.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@ use pubsub::{client::TopicAdmin, model::Topic};
1919
use rand::{Rng, distr::Alphanumeric};
2020

2121
pub async fn basic_topic() -> Result<()> {
22-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
23-
// verify tracing is doing something.
24-
#[cfg(feature = "log-integration-tests")]
25-
let _guard = {
26-
use tracing_subscriber::fmt::format::FmtSpan;
27-
let subscriber = tracing_subscriber::fmt()
28-
.with_level(true)
29-
.with_thread_ids(true)
30-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
31-
.finish();
32-
33-
tracing::subscriber::set_default(subscriber)
34-
};
35-
3622
let (client, topic) = create_test_topic().await?;
3723

3824
tracing::info!("testing get_topic()");

src/integration-tests/src/secret_manager/openapi.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ use gax::paginator::Paginator;
1717
use rand::{Rng, distr::Alphanumeric};
1818

1919
pub async fn run() -> Result<()> {
20-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
21-
// verify tracing is doing something.
22-
#[cfg(feature = "log-integration-tests")]
23-
let _guard = {
24-
use tracing_subscriber::fmt::format::FmtSpan;
25-
let subscriber = tracing_subscriber::fmt()
26-
.with_level(true)
27-
.with_thread_ids(true)
28-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
29-
.finish();
30-
31-
tracing::subscriber::set_default(subscriber)
32-
};
3320
let project_id = crate::project_id()?;
3421
let secret_id: String = rand::rng()
3522
.sample_iter(&Alphanumeric)

src/integration-tests/src/secret_manager/openapi_locational.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ use crate::Result;
1616
use rand::{Rng, distr::Alphanumeric};
1717

1818
pub async fn run() -> Result<()> {
19-
// Enable a basic subscriber. Useful to troubleshoot problems and visually
20-
// verify tracing is doing something.
21-
#[cfg(feature = "log-integration-tests")]
22-
let _guard = {
23-
use tracing_subscriber::fmt::format::FmtSpan;
24-
let subscriber = tracing_subscriber::fmt()
25-
.with_level(true)
26-
.with_thread_ids(true)
27-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
28-
.finish();
29-
30-
tracing::subscriber::set_default(subscriber)
31-
};
32-
3319
let project_id = crate::project_id()?;
3420
let secret_id: String = rand::rng()
3521
.sample_iter(&Alphanumeric)

0 commit comments

Comments
 (0)