RocMarshal commented on code in PR #27884:
URL: https://github.com/apache/flink/pull/27884#discussion_r3032760651


##########
flink-docs/src/test/java/org/apache/flink/docs/rest/RuntimeOpenRestAPIDocsCompletenessITCase.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ *
+ *     http://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 org.apache.flink.docs.rest;
+
+import org.apache.flink.docs.util.Utils;
+import org.apache.flink.runtime.rest.util.DocumentingDispatcherRestEndpoint;
+import org.apache.flink.runtime.rest.versioning.RuntimeRestAPIVersion;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static 
org.apache.flink.docs.rest.RuntimeOpenApiSpecGenerator.RUNTIME_OPEN_API_TITLE;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Verifies that generated Runtime REST and Open API docs (HTML + OpenAPI yml) 
match committed
+ * files.
+ *
+ * <p>This acts as a freshness check to ensure the documentation stays in sync 
with the code.
+ */
+class RuntimeOpenRestAPIDocsCompletenessITCase {
+
+    @Test
+    void testRuntimeRestApiDocsUpToDate(@TempDir Path tempDir) throws 
Exception {
+        final DocumentingDispatcherRestEndpoint endpoint = new 
DocumentingDispatcherRestEndpoint();
+        for (final RuntimeRestAPIVersion apiVersion : 
RuntimeRestAPIVersion.values()) {
+            if (apiVersion == RuntimeRestAPIVersion.V0) {
+                continue;
+            }
+            final String version = apiVersion.getURLVersionPrefix();
+            String targetHtmlName = String.format("rest_%s_dispatcher.html", 
version);
+            final Path pathOfGeneratedHtml = tempDir.resolve(targetHtmlName);
+            RestAPIDocGenerator.createHtmlFile(endpoint, apiVersion, 
pathOfGeneratedHtml);
+            assertFilesEqual(
+                    pathOfGeneratedHtml, 
getPathOfCommittedHtml(targetHtmlName), targetHtmlName);
+
+            String targetYmlName = String.format("rest_%s_dispatcher.yml", 
version);
+            final Path pathOfGeneratedYaml = tempDir.resolve(targetYmlName);
+            OpenApiSpecGenerator.createDocumentationFile(
+                    RUNTIME_OPEN_API_TITLE, endpoint, apiVersion, 
pathOfGeneratedYaml);
+            assertFilesEqual(
+                    pathOfGeneratedYaml, 
getPathOfCommittedYaml(targetYmlName), targetYmlName);
+        }
+    }
+
+    static void assertFilesEqual(
+            Path pathOfGeneratedFile, Path pathOfCommittedFile, String 
description)
+            throws Exception {
+        assertThat(pathOfCommittedFile)
+                .as("Missing committed %s file: %s", description, 
pathOfCommittedFile)
+                .exists();
+        final String generatedContent = readNormalized(pathOfGeneratedFile);
+        final String committedContent = readNormalized(pathOfCommittedFile);
+        assertThat(generatedContent)
+                .as(
+                        "Committed `%s` file is out of date. Please regenerate 
docs under `flink-docs` module based on `README.md`.",
+                        description)
+                .isEqualTo(committedContent);
+    }
+
+    static String readNormalized(Path file) throws Exception {
+        return Files.readString(file, StandardCharsets.UTF_8).replace("\r\n", 
"\n");

Review Comment:
   Thanks @snuyanzin for the reminder.
   You're right.
   Updated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to