Skip to content

Commit fc20328

Browse files
authored
refactor: split enum query parameters test (#4419)
Reduce the size (and dependencies) of the `integration-tests` crate by moving one of the tests out. I decided to name the new test crate for the feature it tests, not for the library we use to run the tests.
1 parent ec81d24 commit fc20328

10 files changed

Lines changed: 138 additions & 49 deletions

File tree

Cargo.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ members = [
292292
"tests/crypto-providers/test-storage",
293293
"tests/dns",
294294
"tests/endurance",
295+
"tests/enums-query-parameters",
295296
"tests/integration",
296297
"tests/integration-auth",
297298
"tests/o11y",
@@ -472,6 +473,9 @@ language = { default-features = false, version = "1", pat
472473
google-cloud-dns-v1 = { default-features = false, path = "src/generated/cloud/dns/v1" }
473474
google-cloud-showcase-v1beta1 = { default-features = false, path = "src/generated/showcase" }
474475
google-cloud-trace-v1 = { default-features = false, path = "src/generated/devtools/cloudtrace/v1" }
476+
# The names on these are too long, I do not want to reformat the whole file for them.
477+
google-cloud-workflows-v1 = { default-features = false, path = "src/generated/cloud/workflows/v1" }
478+
google-cloud-workflows-executions-v1 = { default-features = false, path = "src/generated/cloud/workflows/executions/v1" }
475479

476480
# Local test packages (never add a version)
477481
google-cloud-test-utils = { default-features = false, path = "src/test-utils" }

src/test-utils/src/resource_names.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
use rand::{
1818
Rng,
19-
distr::{Distribution, Uniform},
19+
distr::{Alphanumeric, Distribution, Uniform},
2020
};
2121

2222
/// A common prefix for resource ids.
@@ -26,12 +26,24 @@ pub const PREFIX: &str = "rust-sdk-testing-";
2626

2727
const BUCKET_ID_LENGTH: usize = 63;
2828

29-
/// Generate a random bucket id
29+
const WORKFLOW_ID_LENGTH: usize = 64;
30+
31+
/// Generate a random bucket id.
3032
pub fn random_bucket_id() -> String {
3133
let id = LowercaseAlphanumeric.random_string(BUCKET_ID_LENGTH - PREFIX.len());
3234
format!("{PREFIX}{id}")
3335
}
3436

37+
/// Generate a random workflow id.
38+
pub fn random_workflow_id() -> String {
39+
let id: String = rand::rng()
40+
.sample_iter(&Alphanumeric)
41+
.take(WORKFLOW_ID_LENGTH - PREFIX.len())
42+
.map(char::from)
43+
.collect();
44+
format!("{PREFIX}{id}")
45+
}
46+
3547
const LOWERCASE_ALPHANUMERIC_CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";
3648

3749
/// Sample a `u8`, uniformly distributed over ASCII lowercase letters and numbers: a-z and 0-9.
@@ -83,6 +95,22 @@ mod tests {
8395
assert!(test.is_ok(), "{test:?}");
8496
}
8597

98+
#[test]
99+
fn workflow_id() {
100+
let got = random_workflow_id();
101+
assert!(
102+
got.len() <= WORKFLOW_ID_LENGTH,
103+
"{got} has more than {WORKFLOW_ID_LENGTH} characters"
104+
);
105+
let suffix = got
106+
.strip_prefix(PREFIX)
107+
.expect("{got} should start with {PREFIX}");
108+
assert!(
109+
suffix.chars().all(|c| c.is_alphanumeric()),
110+
"the suffix should be alphanumeric: {suffix}"
111+
);
112+
}
113+
86114
#[test]
87115
fn lowercase() {
88116
let got: String = rand::rng()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[package]
16+
description = "Integration tests for enums in query parameters."
17+
edition.workspace = true
18+
name = "integration-tests-enums-query-parameters"
19+
publish = false
20+
version = "0.0.0"
21+
22+
[features]
23+
# These are normally disabled because they run against production.
24+
run-integration-tests = []
25+
# Logging enables more verbose output for the tests.
26+
log-integration-tests = []
27+
28+
[dependencies]
29+
anyhow.workspace = true
30+
chrono = { workspace = true, features = ["now"] }
31+
futures.workspace = true
32+
google-cloud-workflows-v1 = { workspace = true, features = ["default"] }
33+
google-cloud-workflows-executions-v1 = { workspace = true, features = ["default"] }
34+
google-cloud-gax.workspace = true
35+
google-cloud-test-utils = { workspace = true }
36+
google-cloud-lro.workspace = true
37+
tokio.workspace = true
38+
tracing.workspace = true
39+
tracing-subscriber = { workspace = true, features = ["fmt"] }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Integration tests for enum query parameters
2+
3+
This is an integration test for enum values in query parameters. We use the
4+
`google-cloud-workflow-executions-v1` library because it uses the feature. We
5+
also use the `google-cloud-workflow-v1` library to create data (workflow
6+
executions) for the tests.

tests/integration/src/workflows_executions.rs renamed to tests/enums-query-parameters/src/lib.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,32 @@
1313
// limitations under the License.
1414

1515
use anyhow::Result;
16-
use gax::exponential_backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
17-
use gax::options::RequestOptionsBuilder;
18-
use gax::paginator::ItemPaginator as _;
19-
use gax::retry_policy::{AlwaysRetry, RetryPolicyExt};
16+
use google_cloud_gax::exponential_backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
17+
use google_cloud_gax::options::RequestOptionsBuilder;
18+
use google_cloud_gax::paginator::ItemPaginator as _;
19+
use google_cloud_gax::retry_policy::{AlwaysRetry, RetryPolicyExt};
20+
use google_cloud_lro::Poller;
21+
use google_cloud_test_utils::resource_names::random_workflow_id;
2022
use google_cloud_test_utils::runtime_config::{project_id, region_id, test_service_account};
21-
use lro::Poller;
23+
use google_cloud_workflows_executions_v1::{
24+
client::Executions, model::Execution, model::ExecutionView,
25+
};
26+
use google_cloud_workflows_v1::{client::Workflows, model::Workflow, model::workflow::SourceCode};
2227
use std::time::Duration;
2328

2429
// Verify enum query parameters are serialized correctly.
25-
pub async fn list() -> Result<()> {
30+
pub async fn run() -> Result<()> {
2631
// Create a workflow so we can list its executions. We rely on the other
2732
// workflows integration tests to delete it if something fails or crashes
2833
// in this test.
2934
let parent = create_test_workflow().await?;
30-
let client = wfe::client::Executions::builder()
31-
.with_tracing()
32-
.build()
33-
.await?;
35+
let client = Executions::builder().with_tracing().build().await?;
3436

3537
// Create an execution with a label. The label is not returned for the `BASIC` view.
3638
let start = client
3739
.create_execution()
3840
.set_parent(&parent)
39-
.set_execution(wfe::model::Execution::new().set_labels([("test-label", "test-value")]))
41+
.set_execution(Execution::new().set_labels([("test-label", "test-value")]))
4042
.send()
4143
.await?;
4244
tracing::info!("start was successful={start:?}");
@@ -45,7 +47,7 @@ pub async fn list() -> Result<()> {
4547
let mut executions = client
4648
.list_executions()
4749
.set_parent(&parent)
48-
.set_view(wfe::model::ExecutionView::Basic)
50+
.set_view(ExecutionView::Basic)
4951
.by_item();
5052

5153
while let Some(execution) = executions.next().await {
@@ -58,7 +60,7 @@ pub async fn list() -> Result<()> {
5860
let mut executions = client
5961
.list_executions()
6062
.set_parent(&parent)
61-
.set_view(wfe::model::ExecutionView::Full)
63+
.set_view(ExecutionView::Full)
6264
.by_item();
6365

6466
while let Some(execution) = executions.next().await {
@@ -93,16 +95,16 @@ main:
9395
- sayHello:
9496
return: Hello World
9597
"###;
96-
let source_code = wf::model::workflow::SourceCode::SourceContents(source_contents.to_string());
97-
let workflow_id = crate::random_workflow_id();
98+
let source_code = SourceCode::SourceContents(source_contents.to_string());
99+
let workflow_id = random_workflow_id();
98100

99101
tracing::info!("Start create_workflow() LRO and poll it to completion");
100102
let response = client
101103
.create_workflow()
102104
.set_parent(format!("projects/{project_id}/locations/{location_id}"))
103105
.set_workflow_id(&workflow_id)
104106
.set_workflow(
105-
wf::model::Workflow::new()
107+
Workflow::new()
106108
.set_labels([("integration-test", "true")])
107109
.set_service_account(&workflows_runner)
108110
.set_source_code(source_code),
@@ -116,8 +118,8 @@ main:
116118
Ok(response.name)
117119
}
118120

119-
async fn workflow_client() -> Result<wf::client::Workflows> {
120-
let client = wf::client::Workflows::builder()
121+
async fn workflow_client() -> Result<Workflows> {
122+
let client = Workflows::builder()
121123
.with_retry_policy(
122124
AlwaysRetry
123125
.with_time_limit(Duration::from_secs(15))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#[cfg(all(test, feature = "run-integration-tests"))]
16+
mod enums_query_parameters {
17+
#[tokio::test]
18+
async fn run() -> anyhow::Result<()> {
19+
integration_tests_enums_query_parameters::run().await
20+
}
21+
}

tests/integration/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ path = "../../src/generated/cloud/telcoautomation/v1"
102102
package = "google-cloud-workflows-v1"
103103
path = "../../src/generated/cloud/workflows/v1"
104104

105-
[dependencies.wfe]
106-
package = "google-cloud-workflows-executions-v1"
107-
path = "../../src/generated/cloud/workflows/executions/v1"
108-
109105
[dev-dependencies]
110106
anyhow.workspace = true
111107
httptest.workspace = true

tests/integration/src/lib.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use google_cloud_test_utils::resource_names::LowercaseAlphanumeric;
1616
use google_cloud_test_utils::resource_names::random_bucket_id;
17-
use rand::{Rng, distr::Alphanumeric};
17+
pub(crate) use google_cloud_test_utils::resource_names::random_workflow_id;
1818

1919
pub type Result<T> = anyhow::Result<T>;
2020
pub mod aiplatform;
@@ -26,32 +26,17 @@ pub mod secret_manager;
2626
pub mod showcase;
2727
pub mod storage;
2828
pub mod workflows;
29-
pub mod workflows_executions;
3029

3130
pub const SECRET_ID_LENGTH: usize = 64;
3231

3332
pub const VM_ID_LENGTH: usize = 63;
3433

35-
pub const WORKFLOW_ID_LENGTH: usize = 64;
36-
3734
pub fn report_error(e: anyhow::Error) -> anyhow::Error {
3835
eprintln!("\n\nERROR {e:?}\n");
3936
tracing::error!("ERROR {e:?}");
4037
e
4138
}
4239

43-
pub(crate) fn random_workflow_id() -> String {
44-
// Workflow ids must start with a letter, we use `wf-` as a prefix to
45-
// meet this requirement.
46-
const PREFIX: &str = "wf-";
47-
let workflow_id: String = rand::rng()
48-
.sample_iter(&Alphanumeric)
49-
.take(WORKFLOW_ID_LENGTH - PREFIX.len())
50-
.map(char::from)
51-
.collect();
52-
format!("{PREFIX}{workflow_id}")
53-
}
54-
5540
pub(crate) fn random_image_name() -> String {
5641
const PREFIX: &str = "img-";
5742
let image_id = LowercaseAlphanumeric.random_string(VM_ID_LENGTH - PREFIX.len());

tests/integration/tests/driver.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,4 @@ mod driver {
329329
.await
330330
.map_err(integration_tests::report_error)
331331
}
332-
333-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
334-
async fn workflows_executions() -> integration_tests::Result<()> {
335-
let _guard = enable_tracing();
336-
integration_tests::workflows_executions::list()
337-
.await
338-
.map_err(integration_tests::report_error)
339-
}
340332
}

0 commit comments

Comments
 (0)