From 65bac217a333ac9d807c59df31515ff241527b32 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Mon, 26 Jan 2026 19:23:37 -0500 Subject: [PATCH] refactor: split enum query parameters test 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. --- Cargo.lock | 18 ++++++++- Cargo.toml | 4 ++ src/test-utils/src/resource_names.rs | 32 ++++++++++++++- tests/enums-query-parameters/Cargo.toml | 39 +++++++++++++++++++ tests/enums-query-parameters/README.md | 6 +++ .../src/lib.rs} | 38 +++++++++--------- tests/enums-query-parameters/tests/driver.rs | 21 ++++++++++ tests/integration/Cargo.toml | 4 -- tests/integration/src/lib.rs | 17 +------- tests/integration/tests/driver.rs | 8 ---- 10 files changed, 138 insertions(+), 49 deletions(-) create mode 100644 tests/enums-query-parameters/Cargo.toml create mode 100644 tests/enums-query-parameters/README.md rename tests/{integration/src/workflows_executions.rs => enums-query-parameters/src/lib.rs} (77%) create mode 100644 tests/enums-query-parameters/tests/driver.rs diff --git a/Cargo.lock b/Cargo.lock index e3796a1221..c0583e7051 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5831,7 +5831,6 @@ dependencies = [ "google-cloud-telcoautomation-v1", "google-cloud-test-utils", "google-cloud-wkt", - "google-cloud-workflows-executions-v1", "google-cloud-workflows-v1", "http", "httptest", @@ -5891,6 +5890,23 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "integration-tests-enums-query-parameters" +version = "0.0.0" +dependencies = [ + "anyhow", + "chrono", + "futures", + "google-cloud-gax", + "google-cloud-lro", + "google-cloud-test-utils", + "google-cloud-workflows-executions-v1", + "google-cloud-workflows-v1", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "integration-tests-o11y" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index db781e8bb6..7aebf3da9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -292,6 +292,7 @@ members = [ "tests/crypto-providers/test-storage", "tests/dns", "tests/endurance", + "tests/enums-query-parameters", "tests/integration", "tests/integration-auth", "tests/o11y", @@ -472,6 +473,9 @@ language = { default-features = false, version = "1", pat google-cloud-dns-v1 = { default-features = false, path = "src/generated/cloud/dns/v1" } google-cloud-showcase-v1beta1 = { default-features = false, path = "src/generated/showcase" } google-cloud-trace-v1 = { default-features = false, path = "src/generated/devtools/cloudtrace/v1" } +# The names on these are too long, I do not want to reformat the whole file for them. +google-cloud-workflows-v1 = { default-features = false, path = "src/generated/cloud/workflows/v1" } +google-cloud-workflows-executions-v1 = { default-features = false, path = "src/generated/cloud/workflows/executions/v1" } # Local test packages (never add a version) google-cloud-test-utils = { default-features = false, path = "src/test-utils" } diff --git a/src/test-utils/src/resource_names.rs b/src/test-utils/src/resource_names.rs index df1f6ded26..36e2ed8900 100644 --- a/src/test-utils/src/resource_names.rs +++ b/src/test-utils/src/resource_names.rs @@ -16,7 +16,7 @@ use rand::{ Rng, - distr::{Distribution, Uniform}, + distr::{Alphanumeric, Distribution, Uniform}, }; /// A common prefix for resource ids. @@ -26,12 +26,24 @@ pub const PREFIX: &str = "rust-sdk-testing-"; const BUCKET_ID_LENGTH: usize = 63; -/// Generate a random bucket id +const WORKFLOW_ID_LENGTH: usize = 64; + +/// Generate a random bucket id. pub fn random_bucket_id() -> String { let id = LowercaseAlphanumeric.random_string(BUCKET_ID_LENGTH - PREFIX.len()); format!("{PREFIX}{id}") } +/// Generate a random workflow id. +pub fn random_workflow_id() -> String { + let id: String = rand::rng() + .sample_iter(&Alphanumeric) + .take(WORKFLOW_ID_LENGTH - PREFIX.len()) + .map(char::from) + .collect(); + format!("{PREFIX}{id}") +} + const LOWERCASE_ALPHANUMERIC_CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789"; /// Sample a `u8`, uniformly distributed over ASCII lowercase letters and numbers: a-z and 0-9. @@ -83,6 +95,22 @@ mod tests { assert!(test.is_ok(), "{test:?}"); } + #[test] + fn workflow_id() { + let got = random_workflow_id(); + assert!( + got.len() <= WORKFLOW_ID_LENGTH, + "{got} has more than {WORKFLOW_ID_LENGTH} characters" + ); + let suffix = got + .strip_prefix(PREFIX) + .expect("{got} should start with {PREFIX}"); + assert!( + suffix.chars().all(|c| c.is_alphanumeric()), + "the suffix should be alphanumeric: {suffix}" + ); + } + #[test] fn lowercase() { let got: String = rand::rng() diff --git a/tests/enums-query-parameters/Cargo.toml b/tests/enums-query-parameters/Cargo.toml new file mode 100644 index 0000000000..06391b78c6 --- /dev/null +++ b/tests/enums-query-parameters/Cargo.toml @@ -0,0 +1,39 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[package] +description = "Integration tests for enums in query parameters." +edition.workspace = true +name = "integration-tests-enums-query-parameters" +publish = false +version = "0.0.0" + +[features] +# These are normally disabled because they run against production. +run-integration-tests = [] +# Logging enables more verbose output for the tests. +log-integration-tests = [] + +[dependencies] +anyhow.workspace = true +chrono = { workspace = true, features = ["now"] } +futures.workspace = true +google-cloud-workflows-v1 = { workspace = true, features = ["default"] } +google-cloud-workflows-executions-v1 = { workspace = true, features = ["default"] } +google-cloud-gax.workspace = true +google-cloud-test-utils = { workspace = true } +google-cloud-lro.workspace = true +tokio.workspace = true +tracing.workspace = true +tracing-subscriber = { workspace = true, features = ["fmt"] } diff --git a/tests/enums-query-parameters/README.md b/tests/enums-query-parameters/README.md new file mode 100644 index 0000000000..adb0a1a5fc --- /dev/null +++ b/tests/enums-query-parameters/README.md @@ -0,0 +1,6 @@ +# Integration tests for enum query parameters + +This is an integration test for enum values in query parameters. We use the +`google-cloud-workflow-executions-v1` library because it uses the feature. We +also use the `google-cloud-workflow-v1` library to create data (workflow +executions) for the tests. diff --git a/tests/integration/src/workflows_executions.rs b/tests/enums-query-parameters/src/lib.rs similarity index 77% rename from tests/integration/src/workflows_executions.rs rename to tests/enums-query-parameters/src/lib.rs index aa11e62a16..907b3a30d3 100644 --- a/tests/integration/src/workflows_executions.rs +++ b/tests/enums-query-parameters/src/lib.rs @@ -13,30 +13,32 @@ // limitations under the License. use anyhow::Result; -use gax::exponential_backoff::{ExponentialBackoff, ExponentialBackoffBuilder}; -use gax::options::RequestOptionsBuilder; -use gax::paginator::ItemPaginator as _; -use gax::retry_policy::{AlwaysRetry, RetryPolicyExt}; +use google_cloud_gax::exponential_backoff::{ExponentialBackoff, ExponentialBackoffBuilder}; +use google_cloud_gax::options::RequestOptionsBuilder; +use google_cloud_gax::paginator::ItemPaginator as _; +use google_cloud_gax::retry_policy::{AlwaysRetry, RetryPolicyExt}; +use google_cloud_lro::Poller; +use google_cloud_test_utils::resource_names::random_workflow_id; use google_cloud_test_utils::runtime_config::{project_id, region_id, test_service_account}; -use lro::Poller; +use google_cloud_workflows_executions_v1::{ + client::Executions, model::Execution, model::ExecutionView, +}; +use google_cloud_workflows_v1::{client::Workflows, model::Workflow, model::workflow::SourceCode}; use std::time::Duration; // Verify enum query parameters are serialized correctly. -pub async fn list() -> Result<()> { +pub async fn run() -> Result<()> { // Create a workflow so we can list its executions. We rely on the other // workflows integration tests to delete it if something fails or crashes // in this test. let parent = create_test_workflow().await?; - let client = wfe::client::Executions::builder() - .with_tracing() - .build() - .await?; + let client = Executions::builder().with_tracing().build().await?; // Create an execution with a label. The label is not returned for the `BASIC` view. let start = client .create_execution() .set_parent(&parent) - .set_execution(wfe::model::Execution::new().set_labels([("test-label", "test-value")])) + .set_execution(Execution::new().set_labels([("test-label", "test-value")])) .send() .await?; tracing::info!("start was successful={start:?}"); @@ -45,7 +47,7 @@ pub async fn list() -> Result<()> { let mut executions = client .list_executions() .set_parent(&parent) - .set_view(wfe::model::ExecutionView::Basic) + .set_view(ExecutionView::Basic) .by_item(); while let Some(execution) = executions.next().await { @@ -58,7 +60,7 @@ pub async fn list() -> Result<()> { let mut executions = client .list_executions() .set_parent(&parent) - .set_view(wfe::model::ExecutionView::Full) + .set_view(ExecutionView::Full) .by_item(); while let Some(execution) = executions.next().await { @@ -93,8 +95,8 @@ main: - sayHello: return: Hello World "###; - let source_code = wf::model::workflow::SourceCode::SourceContents(source_contents.to_string()); - let workflow_id = crate::random_workflow_id(); + let source_code = SourceCode::SourceContents(source_contents.to_string()); + let workflow_id = random_workflow_id(); tracing::info!("Start create_workflow() LRO and poll it to completion"); let response = client @@ -102,7 +104,7 @@ main: .set_parent(format!("projects/{project_id}/locations/{location_id}")) .set_workflow_id(&workflow_id) .set_workflow( - wf::model::Workflow::new() + Workflow::new() .set_labels([("integration-test", "true")]) .set_service_account(&workflows_runner) .set_source_code(source_code), @@ -116,8 +118,8 @@ main: Ok(response.name) } -async fn workflow_client() -> Result { - let client = wf::client::Workflows::builder() +async fn workflow_client() -> Result { + let client = Workflows::builder() .with_retry_policy( AlwaysRetry .with_time_limit(Duration::from_secs(15)) diff --git a/tests/enums-query-parameters/tests/driver.rs b/tests/enums-query-parameters/tests/driver.rs new file mode 100644 index 0000000000..dfbf454d76 --- /dev/null +++ b/tests/enums-query-parameters/tests/driver.rs @@ -0,0 +1,21 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[cfg(all(test, feature = "run-integration-tests"))] +mod enums_query_parameters { + #[tokio::test] + async fn run() -> anyhow::Result<()> { + integration_tests_enums_query_parameters::run().await + } +} diff --git a/tests/integration/Cargo.toml b/tests/integration/Cargo.toml index df4504492d..b776faa815 100644 --- a/tests/integration/Cargo.toml +++ b/tests/integration/Cargo.toml @@ -102,10 +102,6 @@ path = "../../src/generated/cloud/telcoautomation/v1" package = "google-cloud-workflows-v1" path = "../../src/generated/cloud/workflows/v1" -[dependencies.wfe] -package = "google-cloud-workflows-executions-v1" -path = "../../src/generated/cloud/workflows/executions/v1" - [dev-dependencies] anyhow.workspace = true httptest.workspace = true diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index adfb609368..ba34754f0d 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -14,7 +14,7 @@ use google_cloud_test_utils::resource_names::LowercaseAlphanumeric; use google_cloud_test_utils::resource_names::random_bucket_id; -use rand::{Rng, distr::Alphanumeric}; +pub(crate) use google_cloud_test_utils::resource_names::random_workflow_id; pub type Result = anyhow::Result; pub mod aiplatform; @@ -26,32 +26,17 @@ pub mod secret_manager; pub mod showcase; pub mod storage; pub mod workflows; -pub mod workflows_executions; pub const SECRET_ID_LENGTH: usize = 64; pub const VM_ID_LENGTH: usize = 63; -pub const WORKFLOW_ID_LENGTH: usize = 64; - pub fn report_error(e: anyhow::Error) -> anyhow::Error { eprintln!("\n\nERROR {e:?}\n"); tracing::error!("ERROR {e:?}"); e } -pub(crate) fn random_workflow_id() -> String { - // Workflow ids must start with a letter, we use `wf-` as a prefix to - // meet this requirement. - const PREFIX: &str = "wf-"; - let workflow_id: String = rand::rng() - .sample_iter(&Alphanumeric) - .take(WORKFLOW_ID_LENGTH - PREFIX.len()) - .map(char::from) - .collect(); - format!("{PREFIX}{workflow_id}") -} - pub(crate) fn random_image_name() -> String { const PREFIX: &str = "img-"; let image_id = LowercaseAlphanumeric.random_string(VM_ID_LENGTH - PREFIX.len()); diff --git a/tests/integration/tests/driver.rs b/tests/integration/tests/driver.rs index 13126f527c..23e12b846e 100644 --- a/tests/integration/tests/driver.rs +++ b/tests/integration/tests/driver.rs @@ -329,12 +329,4 @@ mod driver { .await .map_err(integration_tests::report_error) } - - #[tokio::test(flavor = "multi_thread", worker_threads = 1)] - async fn workflows_executions() -> integration_tests::Result<()> { - let _guard = enable_tracing(); - integration_tests::workflows_executions::list() - .await - .map_err(integration_tests::report_error) - } }