diff --git a/crates/integration-tests/tests/integration/versioned.rs b/crates/integration-tests/tests/integration/versioned.rs index 9f622f7..691fef3 100644 --- a/crates/integration-tests/tests/integration/versioned.rs +++ b/crates/integration-tests/tests/integration/versioned.rs @@ -617,6 +617,85 @@ fn test_removing_api_version_fails_check() -> Result<()> { Ok(()) } +/// Test that removing an API version whose document is unparseable fails +/// the check. +#[test] +fn test_removing_api_version_unparseable_doc_fails_check() -> Result<()> { + let env = TestEnvironment::new_git()?; + let apis = versioned_health_apis()?; + + env.generate_documents(&apis)?; + env.commit_documents()?; + + // Conflict markers make the v3 document unparseable. + let v3_orphan_path = env + .find_versioned_document_path("versioned-health", "3.0.0")? + .expect("v3 document exists"); + let conflict_content = r#"<<<<<<< HEAD +{ + "openapi": "3.0.3", + "info": { + "title": "Versioned Health API", + "version": "3.0.0" + } +} +======= +{ + "openapi": "3.0.3", + "info": { + "title": "Versioned Health API Modified", + "version": "3.0.0" + } +} +>>>>>>> branch +"#; + env.create_file(&v3_orphan_path, conflict_content)?; + + // With the reduced set of API versions, v3 is both orphaned and + // unparseable. + let reduced_apis = versioned_health_reduced_apis()?; + + let (result, summaries, rendered) = + check_apis_with_render(env.environment(), &reduced_apis)?; + assert_eq!(result, CheckResult::NeedsUpdate); + crate::snapshot::assert_render_snapshot( + &env, + "orphaned_unparseable_doc.txt", + &rendered, + ); + assert_eq!( + summaries, + [ + ProblemSummary::new( + "versioned-health", + "3.0.0", + ProblemKind::LocalDocFileOrphaned { + basename: v3_orphan_path + .file_name() + .expect("v3_orphan_path has a file name") + .to_owned() + }, + ), + ProblemSummary::for_api( + "versioned-health", + ProblemKind::LatestLinkStale, + ), + ], + ); + + // The fix deletes the unparseable orphaned document. + env.generate_documents(&reduced_apis)?; + assert!( + !env.file_exists(&v3_orphan_path), + "unparseable orphaned document should have been deleted" + ); + + let result = check_apis_up_to_date(env.environment(), &reduced_apis)?; + assert_eq!(result, CheckResult::Success); + + Ok(()) +} + /// Test that adding new API versions passes the check. #[test] fn test_adding_new_api_version_passes_check() -> Result<()> { diff --git a/crates/integration-tests/tests/output/integration/orphaned_unparseable_doc.txt b/crates/integration-tests/tests/output/integration/orphaned_unparseable_doc.txt new file mode 100644 index 0000000..6850cb8 --- /dev/null +++ b/crates/integration-tests/tests/output/integration/orphaned_unparseable_doc.txt @@ -0,0 +1,35 @@ + ------- + Generating OpenAPI documents from API definitions ... + Loading local OpenAPI documents from "" ... + Warning skipping unparseable file: file "versioned-health/versioned-health-3.0.0-05def5.json": parsing as JSON: expected value at line 1 column 1 + Loading blessed OpenAPI documents from VCS revision "main" path "documents" + ------- + Checking 2 OpenAPI documents... + Fresh versioned-health (versioned v1.0.0 (blessed)): Versioned Health API + Fresh versioned-health (versioned v2.0.0 (blessed)): Versioned Health API + Stale versioned-health "latest" symlink + problem: "Latest" symlink for versioned API "versioned-health" is stale: + points to versioned-health-3.0.0-05def5.json, but should be + versioned-health-2.0.0-511899.json + fix: will update symlink to point to versioned-health-2.0.0-511899.json + + Other problems not associated with a specific supported API version: + problem: A local OpenAPI document was found that does not correspond to a + supported version of this API: versioned-health/versioned-health- + 3.0.0-05def5.json. This is unusual, but it could happen if you're + either retiring an older version of this API or if you created + this version in this branch and later merged with upstream and had + to change your local version number. In either case, this tool + can remove the unused file for you. + fix: will delete file: versioned-health/versioned-health-3.0.0- + 05def5.json + + Note API versioned-health version 3.0.0: formerly blessed version has + been removed. This version will no longer be supported! This will + break upgrade from software that still uses this version. If this + is unexpected, check the list of supported versions in Rust for a + possible mismerge. + + ------- + Stale 2 documents checked: 2 fresh, 0 stale, 0 failed, 2 other problems + (run test-openapi-manager generate to update)