Skip to content

Commit a6bb687

Browse files
authored
[integration-tests] add endpoint and param removal scenarios by reversing fixture direction (#94)
1 parent a3dd419 commit a6bb687

2 files changed

Lines changed: 134 additions & 5 deletions

File tree

crates/integration-tests/tests/integration/versioned.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -951,14 +951,41 @@ fn test_retiring_older_blessed_version() -> Result<()> {
951951
/// see exactly how the user-visible output changes.
952952
#[test]
953953
fn test_incompatible_blessed_api_change_render() -> Result<()> {
954+
render_blessed_version_broken_snapshot(
955+
versioned_health_apis()?,
956+
versioned_health_incompat_apis()?,
957+
"blessed_version_broken.txt",
958+
)
959+
}
960+
961+
/// Companion to `test_incompatible_blessed_api_change_render` that runs the
962+
/// fixtures in reverse: the `versioned_health_incompat` shape is blessed, and
963+
/// the current code regresses to the plain `versioned_health` shape. This
964+
/// exercises endpoint and required-parameter removal, the symmetric counterpart
965+
/// of the addition cases the forward direction covers.
966+
#[test]
967+
fn test_blessed_api_endpoint_removed_render() -> Result<()> {
968+
render_blessed_version_broken_snapshot(
969+
versioned_health_incompat_apis()?,
970+
versioned_health_apis()?,
971+
"blessed_version_endpoint_removed.txt",
972+
)
973+
}
974+
975+
/// Shared body for the `BlessedVersionBroken` snapshot tests: commit `blessed`
976+
/// as the upstream shape, then check against `generated` and snapshot the
977+
/// rendered output to `snapshot_name` under `tests/output/integration/`.
978+
fn render_blessed_version_broken_snapshot(
979+
blessed: ManagedApis,
980+
generated: ManagedApis,
981+
snapshot_name: &str,
982+
) -> Result<()> {
954983
let env = TestEnvironment::new_git()?;
955-
let original_apis = versioned_health_apis()?;
956-
env.generate_documents(&original_apis)?;
984+
env.generate_documents(&blessed)?;
957985
env.commit_documents()?;
958986

959-
let incompatible_apis = versioned_health_incompat_apis()?;
960987
let (result, _summaries, rendered) =
961-
check_apis_with_render(env.environment(), &incompatible_apis)?;
988+
check_apis_with_render(env.environment(), &generated)?;
962989
assert_eq!(result, CheckResult::Failures);
963990

964991
// The "Loading local OpenAPI documents from <abs_dir>" line embeds the
@@ -973,7 +1000,8 @@ fn test_incompatible_blessed_api_change_render() -> Result<()> {
9731000
rendered.replace(&documents_dir_debug, "\"<documents dir>\"");
9741001

9751002
let snapshot_path = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR"))
976-
.join("tests/output/integration/blessed_version_broken.txt");
1003+
.join("tests/output/integration")
1004+
.join(snapshot_name);
9771005
expectorate::assert_contents(snapshot_path, &normalized);
9781006
Ok(())
9791007
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
-------
2+
Generating OpenAPI documents from API definitions ...
3+
Loading local OpenAPI documents from "<documents dir>" ...
4+
Loading blessed OpenAPI documents from VCS revision "main" path "documents"
5+
-------
6+
Checking 3 OpenAPI documents...
7+
Fresh versioned-health (versioned v1.0.0 (blessed)): Versioned Health API
8+
Failure versioned-health (versioned v2.0.0 (blessed)): Versioned Health API
9+
error: OpenAPI document generated from the current code is not
10+
compatible with the blessed document (from upstream)
11+
- at .paths."/health/detailed".get: backward-incompatible
12+
change: The parameter 'verbose' was removed
13+
--- a/blessed
14+
+++ b/generated
15+
@@ -1,22 +1,11 @@
16+
{
17+
"get": {
18+
- "description": "Adds a required query parameter `verbose` relative to the blessed shape. See `DetailedFilter` below.",
19+
"operationId": "detailed_health_check",
20+
- "parameters": [
21+
- {
22+
- "in": "query",
23+
- "name": "verbose",
24+
- "required": true,
25+
- "schema": {
26+
- "type": "boolean"
27+
- }
28+
- }
29+
- ],
30+
"responses": {
31+
"200": {
32+
"content": {
33+
"application/json": {
34+
"schema": {
35+
"$ref": "#/components/schemas/DetailedHealthStatus"
36+
}
37+
}
38+
Failure versioned-health (versioned v3.0.0 (blessed)): Versioned Health API
39+
error: OpenAPI document generated from the current code is not
40+
compatible with the blessed document (from upstream)
41+
- at .paths."/health/detailed".get: backward-incompatible
42+
change: The parameter 'verbose' was removed
43+
--- a/blessed
44+
+++ b/generated
45+
@@ -1,22 +1,11 @@
46+
{
47+
"get": {
48+
- "description": "Adds a required query parameter `verbose` relative to the blessed shape. See `DetailedFilter` below.",
49+
"operationId": "detailed_health_check",
50+
- "parameters": [
51+
- {
52+
- "in": "query",
53+
- "name": "verbose",
54+
- "required": true,
55+
- "schema": {
56+
- "type": "boolean"
57+
- }
58+
- }
59+
- ],
60+
"responses": {
61+
"200": {
62+
"content": {
63+
"application/json": {
64+
"schema": {
65+
"$ref": "#/components/schemas/DetailedHealthStatus"
66+
}
67+
}
68+
- at .paths."/system/info".get: backward-incompatible change:
69+
The operation get_system_info was removed
70+
--- a/blessed
71+
+++ b/generated
72+
@@ -1,25 +0,0 @@
73+
-{
74+
- "get": {
75+
- "description": "This breaks backward compatibility by adding a new endpoint to v3.0.0.",
76+
- "operationId": "get_system_info",
77+
- "responses": {
78+
- "200": {
79+
- "content": {
80+
- "application/json": {
81+
- "schema": {
82+
- "$ref": "#/components/schemas/SystemInfo"
83+
- }
84+
- }
85+
- },
86+
- "description": "successful operation"
87+
- },
88+
- "4XX": {
89+
- "$ref": "#/components/responses/Error"
90+
- },
91+
- "5XX": {
92+
- "$ref": "#/components/responses/Error"
93+
- }
94+
- },
95+
- "summary": "Get system info (v3+): new endpoint added to existing version."
96+
- }
97+
-}
98+
Fresh versioned-health "latest" symlink
99+
-------
100+
Failure 3 documents checked: 2 fresh, 0 stale, 2 failed, 0 other problems
101+
(fix failures, then run test-openapi-manager generate to update)

0 commit comments

Comments
 (0)