From ac841ca907e2e7b9e27d2e90885343fd8c7ed191 Mon Sep 17 00:00:00 2001 From: Rain Date: Tue, 30 Sep 2025 18:25:36 +0000 Subject: [PATCH] [spr] initial version Created using spr 1.3.6-beta.1 --- .../integration-tests/src/common/fixtures.rs | 8 +- crates/integration-tests/src/common/mod.rs | 82 ++++++++++--------- .../tests/integration/lockstep.rs | 6 +- .../tests/integration/versioned.rs | 48 ++++++----- 4 files changed, 74 insertions(+), 70 deletions(-) diff --git a/crates/integration-tests/src/common/fixtures.rs b/crates/integration-tests/src/common/fixtures.rs index 25b1be4..70d980a 100644 --- a/crates/integration-tests/src/common/fixtures.rs +++ b/crates/integration-tests/src/common/fixtures.rs @@ -457,7 +457,7 @@ pub mod versioned_health_reduced { api_versions!([(2, WITH_DETAILED_STATUS), (1, INITIAL)]); - #[dropshot::api_description] + #[dropshot::api_description { module = "api_mod" }] pub trait VersionedHealthApi { type Context; @@ -499,7 +499,7 @@ pub mod versioned_health_skip_middle { api_versions!([(3, WITH_METRICS), (1, INITIAL)]); - #[dropshot::api_description] + #[dropshot::api_description { module = "api_mod" }] pub trait VersionedHealthApi { type Context; @@ -545,13 +545,13 @@ pub mod versioned_health_skip_middle { /// Versioned health API with incompatible changes - this breaks backward /// compatibility by changing the response schema of an existing endpoint. -pub mod versioned_health_incompatible { +pub mod versioned_health_incompat { use super::*; use dropshot_api_manager_types::api_versions; api_versions!([(3, WITH_METRICS), (2, WITH_DETAILED_STATUS), (1, INITIAL)]); - #[dropshot::api_description] + #[dropshot::api_description { module = "api_mod" }] pub trait VersionedHealthApi { type Context; diff --git a/crates/integration-tests/src/common/mod.rs b/crates/integration-tests/src/common/mod.rs index 5879c75..f5aa743 100644 --- a/crates/integration-tests/src/common/mod.rs +++ b/crates/integration-tests/src/common/mod.rs @@ -387,8 +387,7 @@ pub fn rel_path_forward_slashes(path: &str) -> String { path.to_string() } -/// Create a versioned health API test configuration. -pub fn versioned_health_test_api() -> ManagedApiConfig { +pub fn versioned_health_api() -> ManagedApiConfig { ManagedApiConfig { ident: "versioned-health", versions: Versions::Versioned { @@ -404,8 +403,7 @@ pub fn versioned_health_test_api() -> ManagedApiConfig { } } -/// Create a versioned user API test configuration. -pub fn versioned_user_test_api() -> ManagedApiConfig { +pub fn versioned_user_api() -> ManagedApiConfig { ManagedApiConfig { ident: "versioned-user", versions: Versions::Versioned { @@ -421,7 +419,7 @@ pub fn versioned_user_test_api() -> ManagedApiConfig { } } -pub fn health_test_api() -> ManagedApiConfig { +pub fn lockstep_health_api() -> ManagedApiConfig { ManagedApiConfig { ident: "health", versions: Versions::Lockstep { version: Version::new(1, 0, 0) }, @@ -435,7 +433,7 @@ pub fn health_test_api() -> ManagedApiConfig { } } -pub fn counter_test_api() -> ManagedApiConfig { +pub fn lockstep_counter_api() -> ManagedApiConfig { ManagedApiConfig { ident: "counter", versions: Versions::Lockstep { version: Version::new(1, 0, 0) }, @@ -449,7 +447,7 @@ pub fn counter_test_api() -> ManagedApiConfig { } } -pub fn user_test_api() -> ManagedApiConfig { +pub fn lockstep_user_api() -> ManagedApiConfig { ManagedApiConfig { ident: "user", versions: Versions::Lockstep { version: Version::new(1, 0, 0) }, @@ -464,64 +462,67 @@ pub fn user_test_api() -> ManagedApiConfig { } /// Create a health API for basic testing. -pub fn create_health_test_apis() -> Result { - ManagedApis::new(vec![health_test_api()]) +pub fn lockstep_health_apis() -> Result { + ManagedApis::new(vec![lockstep_health_api()]) .context("failed to create ManagedApis") } /// Create a counter test API configuration. -pub fn create_counter_test_apis() -> Result { - ManagedApis::new(vec![counter_test_api()]) +pub fn lockstep_counter_apis() -> Result { + ManagedApis::new(vec![lockstep_counter_api()]) .context("failed to create ManagedApis") } /// Create a user test API configuration. -pub fn create_user_test_apis() -> Result { - ManagedApis::new(vec![user_test_api()]) +pub fn lockstep_user_apis() -> Result { + ManagedApis::new(vec![lockstep_user_api()]) .context("failed to create ManagedApis") } /// Helper to create multiple test APIs. -pub fn create_multi_test_apis() -> Result { - let configs = vec![health_test_api(), counter_test_api(), user_test_api()]; +pub fn lockstep_multi_apis() -> Result { + let configs = vec![ + lockstep_health_api(), + lockstep_counter_api(), + lockstep_user_api(), + ]; ManagedApis::new(configs).context("failed to create ManagedApis") } /// Create a versioned health API for testing. -pub fn create_versioned_health_test_apis() -> Result { - ManagedApis::new(vec![versioned_health_test_api()]) +pub fn versioned_health_apis() -> Result { + ManagedApis::new(vec![versioned_health_api()]) .context("failed to create versioned health ManagedApis") } /// Create a versioned user API for testing. -pub fn create_versioned_user_test_apis() -> Result { - ManagedApis::new(vec![versioned_user_test_api()]) +pub fn versioned_user_apis() -> Result { + ManagedApis::new(vec![versioned_user_api()]) .context("failed to create versioned user ManagedApis") } /// Helper to create multiple versioned test APIs. -pub fn create_multi_versioned_test_apis() -> Result { - let configs = vec![versioned_health_test_api(), versioned_user_test_api()]; +pub fn multi_versioned_apis() -> Result { + let configs = vec![versioned_health_api(), versioned_user_api()]; ManagedApis::new(configs).context("failed to create versioned ManagedApis") } /// Helper to create mixed lockstep and versioned test APIs. pub fn create_mixed_test_apis() -> Result { let configs = vec![ - health_test_api(), - counter_test_api(), - versioned_health_test_api(), - versioned_user_test_api(), + lockstep_health_api(), + lockstep_counter_api(), + versioned_health_api(), + versioned_user_api(), ]; ManagedApis::new(configs).context("failed to create mixed ManagedApis") } /// Create versioned health API with a trivial change (title/metadata updated). -pub fn create_versioned_health_test_apis_with_trivial_change() --> Result { +pub fn versioned_health_trivial_change_apis() -> Result { // Create a modified API config that would produce different OpenAPI // documents. - let mut config = versioned_health_test_api(); + let mut config = versioned_health_api(); // Modify the title to create a different document signature. config.title = "Modified Versioned Health API"; @@ -534,22 +535,23 @@ pub fn create_versioned_health_test_apis_with_trivial_change() /// Create versioned health API with reduced versions (simulating version /// removal). -pub fn create_versioned_health_test_apis_reduced_versions() --> Result { +pub fn versioned_health_reduced_apis() -> Result { // Create a configuration similar to versioned health but with fewer // versions. We'll create a new fixture for this. let config = ManagedApiConfig { ident: "versioned-health", versions: Versions::Versioned { // Use a subset of versions (only 1.0.0 and 2.0.0, not 3.0.0). - supported_versions: fixtures::versioned_health_reduced::supported_versions(), + supported_versions: + fixtures::versioned_health_reduced::supported_versions(), }, title: "Versioned Health API", metadata: ManagedApiMetadata { description: Some("A versioned health API with reduced versions"), ..Default::default() }, - api_description: fixtures::versioned_health_reduced::versioned_health_api_mod::stub_api_description, + api_description: + fixtures::versioned_health_reduced::api_mod::stub_api_description, extra_validation: None, }; @@ -557,7 +559,7 @@ pub fn create_versioned_health_test_apis_reduced_versions() .context("failed to create reduced versioned health ManagedApis") } -pub fn create_versioned_health_test_apis_skip_middle() -> Result { +pub fn versioned_health_skip_middle_apis() -> Result { // Create a configuration similar to versioned health but skipping the // middle version. This has versions 3.0.0 and 1.0.0, simulating retirement // of version 2.0.0. @@ -572,7 +574,7 @@ pub fn create_versioned_health_test_apis_skip_middle() -> Result { description: Some("A versioned health API that skips middle version"), ..Default::default() }, - api_description: fixtures::versioned_health_skip_middle::versioned_health_api_mod::stub_api_description, + api_description: fixtures::versioned_health_skip_middle::api_mod::stub_api_description, extra_validation: None, }; @@ -582,20 +584,24 @@ pub fn create_versioned_health_test_apis_skip_middle() -> Result { /// Create a versioned health API with incompatible changes that break backward /// compatibility. -pub fn create_versioned_health_test_apis_incompatible() -> Result { +pub fn versioned_health_incompat_apis() -> Result { // Create a configuration similar to versioned health but with incompatible // changes that break backward compatibility. let config = ManagedApiConfig { ident: "versioned-health", versions: Versions::Versioned { - supported_versions: fixtures::versioned_health_incompatible::supported_versions(), + supported_versions: + fixtures::versioned_health_incompat::supported_versions(), }, title: "Versioned Health API", metadata: ManagedApiMetadata { - description: Some("A versioned health API with incompatible changes"), + description: Some( + "A versioned health API with incompatible changes", + ), ..Default::default() }, - api_description: fixtures::versioned_health_incompatible::versioned_health_api_mod::stub_api_description, + api_description: + fixtures::versioned_health_incompat::api_mod::stub_api_description, extra_validation: None, }; diff --git a/crates/integration-tests/tests/integration/lockstep.rs b/crates/integration-tests/tests/integration/lockstep.rs index a19fde3..99cee88 100644 --- a/crates/integration-tests/tests/integration/lockstep.rs +++ b/crates/integration-tests/tests/integration/lockstep.rs @@ -18,7 +18,7 @@ use openapiv3::OpenAPI; #[test] fn test_lockstep_generate_basic() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_health_test_apis()?; + let apis = lockstep_health_apis()?; // Initially, no documents should exist. assert!(!env.lockstep_document_exists("health")); @@ -49,7 +49,7 @@ fn test_lockstep_generate_basic() -> Result<()> { #[test] fn test_lockstep_always_up_to_date() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_multi_test_apis()?; + let apis = lockstep_multi_apis()?; // Generate all documents. env.generate_documents(&apis)?; @@ -65,7 +65,7 @@ fn test_lockstep_always_up_to_date() -> Result<()> { #[test] fn test_lockstep_multiple_apis() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_multi_test_apis()?; + let apis = lockstep_multi_apis()?; // Generate all documents. env.generate_documents(&apis)?; diff --git a/crates/integration-tests/tests/integration/versioned.rs b/crates/integration-tests/tests/integration/versioned.rs index d300987..d3b59f2 100644 --- a/crates/integration-tests/tests/integration/versioned.rs +++ b/crates/integration-tests/tests/integration/versioned.rs @@ -9,8 +9,7 @@ use anyhow::{Context, Result}; use dropshot_api_manager::test_util::{CheckResult, check_apis_up_to_date}; use integration_tests::common::{ - create_versioned_health_test_apis_incompatible, - create_versioned_health_test_apis_skip_middle, *, + versioned_health_incompat_apis, versioned_health_skip_middle_apis, *, }; use openapiv3::OpenAPI; @@ -18,7 +17,7 @@ use openapiv3::OpenAPI; #[test] fn test_versioned_generate_basic() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_versioned_health_test_apis()?; + let apis = versioned_health_apis()?; // Initially, no documents should exist. assert!( @@ -76,7 +75,7 @@ fn test_versioned_generate_basic() -> Result<()> { #[test] fn test_versioned_content_by_version() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_versioned_health_test_apis()?; + let apis = versioned_health_apis()?; // Generate documents. env.generate_documents(&apis)?; @@ -116,7 +115,7 @@ fn test_versioned_content_by_version() -> Result<()> { #[test] fn test_versioned_latest_document() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_versioned_health_test_apis()?; + let apis = versioned_health_apis()?; // Generate documents. env.generate_documents(&apis)?; @@ -146,7 +145,7 @@ fn test_versioned_latest_document() -> Result<()> { #[test] fn test_multiple_versioned_apis() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_multi_versioned_test_apis()?; + let apis = multi_versioned_apis()?; // Generate all documents. env.generate_documents(&apis)?; @@ -246,7 +245,7 @@ fn test_mixed_lockstep_and_versioned_apis() -> Result<()> { #[test] fn test_git_commit_documents() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_versioned_health_test_apis()?; + let apis = versioned_health_apis()?; // Initially no uncommitted changes. assert!(!env.has_uncommitted_document_changes()?); @@ -275,7 +274,7 @@ fn test_git_commit_documents() -> Result<()> { #[test] fn test_blessed_document_lifecycle() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_versioned_health_test_apis()?; + let apis = versioned_health_apis()?; // Initially, APIs should fail the up-to-date check (no documents exist). let result = check_apis_up_to_date(env.environment(), &apis)?; @@ -302,7 +301,7 @@ fn test_blessed_document_lifecycle() -> Result<()> { #[test] fn test_blessed_api_changes_should_not_do_trivial_updates() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_versioned_health_test_apis()?; + let apis = versioned_health_apis()?; // Generate and commit initial documents. env.generate_documents(&apis)?; @@ -313,8 +312,7 @@ fn test_blessed_api_changes_should_not_do_trivial_updates() -> Result<()> { assert_eq!(result, CheckResult::Success); // Create a modified API with trivial changes (different title/description). - let modified_apis = - create_versioned_health_test_apis_with_trivial_change()?; + let modified_apis = versioned_health_trivial_change_apis()?; // The check should indicate that *no updates are needed* to the blessed version. let result = check_apis_up_to_date(env.environment(), &modified_apis)?; @@ -329,14 +327,14 @@ fn test_mixed_blessed_document_states() -> Result<()> { let env = TestEnvironment::new()?; // Start with combined APIs to establish the proper context. - let combined_apis = create_multi_versioned_test_apis()?; + let combined_apis = multi_versioned_apis()?; // Initially, combined APIs should need update. let result = check_apis_up_to_date(env.environment(), &combined_apis)?; assert_eq!(result, CheckResult::NeedsUpdate); // Generate only health API documents first. - let health_apis = create_versioned_health_test_apis()?; + let health_apis = versioned_health_apis()?; env.generate_documents(&health_apis)?; env.commit_documents()?; @@ -359,7 +357,7 @@ fn test_mixed_blessed_document_states() -> Result<()> { #[test] fn test_removing_api_version_fails_check() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_versioned_health_test_apis()?; + let apis = versioned_health_apis()?; // Generate and commit initial documents (3 versions). env.generate_documents(&apis)?; @@ -389,7 +387,7 @@ fn test_removing_api_version_fails_check() -> Result<()> { ); // Create API with fewer versions (simulating version removal). - let reduced_apis = create_versioned_health_test_apis_reduced_versions()?; + let reduced_apis = versioned_health_reduced_apis()?; // The check should result in NeedsUpdate when versions are removed. let result = check_apis_up_to_date(env.environment(), &reduced_apis)?; @@ -404,7 +402,7 @@ fn test_adding_new_api_version_passes_check() -> Result<()> { let env = TestEnvironment::new()?; // Start with reduced version API. - let reduced_apis = create_versioned_health_test_apis_reduced_versions()?; + let reduced_apis = versioned_health_reduced_apis()?; env.generate_documents(&reduced_apis)?; env.commit_documents()?; @@ -413,7 +411,7 @@ fn test_adding_new_api_version_passes_check() -> Result<()> { assert_eq!(result, CheckResult::Success); // Add more versions. - let expanded_apis = create_versioned_health_test_apis()?; + let expanded_apis = versioned_health_apis()?; // Adding versions should require update (new documents to generate). let result = check_apis_up_to_date(env.environment(), &expanded_apis)?; @@ -435,7 +433,7 @@ fn test_retiring_latest_blessed_version() -> Result<()> { let env = TestEnvironment::new()?; // Start with the full versioned health API (3 versions). - let full_apis = create_versioned_health_test_apis()?; + let full_apis = versioned_health_apis()?; // Generate and commit the initial "blessed" documents. env.generate_documents(&full_apis)?; @@ -470,7 +468,7 @@ fn test_retiring_latest_blessed_version() -> Result<()> { // Now remove version 3.0.0 by switching to the reduced API. // This simulates a developer deciding to remove a version that was previously blessed. - let reduced_apis = create_versioned_health_test_apis_reduced_versions()?; + let reduced_apis = versioned_health_reduced_apis()?; // This check should return NeedsUpdate because the v3.0.0 document exists // and needs to be removed. @@ -550,7 +548,7 @@ fn test_retiring_older_blessed_version() -> Result<()> { let env = TestEnvironment::new()?; // Start with the full versioned health API (3 versions). - let full_apis = create_versioned_health_test_apis()?; + let full_apis = versioned_health_apis()?; // Generate and commit the initial "blessed" documents. env.generate_documents(&full_apis)?; @@ -585,7 +583,7 @@ fn test_retiring_older_blessed_version() -> Result<()> { // Now remove version 2.0.0 by switching to the skip middle API. // This simulates a developer deciding to retire an older version that was previously blessed. - let skip_middle_apis = create_versioned_health_test_apis_skip_middle()?; + let skip_middle_apis = versioned_health_skip_middle_apis()?; // This check should return NeedsUpdate because the v2.0.0 document exists // and needs to be removed. @@ -665,7 +663,7 @@ fn test_incompatible_blessed_api_change() -> Result<()> { let env = TestEnvironment::new()?; // Start with the original versioned health API (3 versions). - let original_apis = create_versioned_health_test_apis()?; + let original_apis = versioned_health_apis()?; // Generate and commit the initial "blessed" documents. env.generate_documents(&original_apis)?; @@ -700,7 +698,7 @@ fn test_incompatible_blessed_api_change() -> Result<()> { // Now introduce incompatible changes. This adds a new endpoint, which // (while forward-compatible) we treat as a breaking change. - let incompatible_apis = create_versioned_health_test_apis_incompatible()?; + let incompatible_apis = versioned_health_incompat_apis()?; // This check should return Failures. let result = check_apis_up_to_date(env.environment(), &incompatible_apis)?; @@ -719,7 +717,7 @@ fn test_incompatible_blessed_api_change() -> Result<()> { #[test] fn test_blessed_version_extra_local_spec() -> Result<()> { let env = TestEnvironment::new()?; - let apis = create_versioned_health_test_apis()?; + let apis = versioned_health_apis()?; // Generate and commit initial documents to make them blessed. env.generate_documents(&apis)?; @@ -731,7 +729,7 @@ fn test_blessed_version_extra_local_spec() -> Result<()> { // Generate with the incompatible APIs. let env2 = TestEnvironment::new()?; - let incompatible_apis = create_versioned_health_test_apis_incompatible()?; + let incompatible_apis = versioned_health_incompat_apis()?; env2.generate_documents(&incompatible_apis)?;