You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/10/06 10:07:54 UTC

[GitHub] [flink] alpinegizmo commented on a diff in pull request #20970: [FLINK-29510] Add tests for NoticeFileChecker

alpinegizmo commented on code in PR #20970:
URL: https://github.com/apache/flink/pull/20970#discussion_r988842857


##########
tools/ci/flink-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/NoticeFileCheckerTest.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.tools.ci.licensecheck;
+
+import org.apache.flink.tools.ci.utils.notice.NoticeContents;
+import org.apache.flink.tools.ci.utils.shared.Dependency;
+
+import com.google.common.collect.ArrayListMultimap;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class NoticeFileCheckerTest {
+    @Test
+    void testRunHappyPath() throws IOException {
+        final String moduleName = "test";
+        final Dependency bundledDependency = Dependency.create("a", "b", "c");
+        final ArrayListMultimap<String, Dependency> bundleDependencies = ArrayListMultimap.create();
+        bundleDependencies.put(moduleName, bundledDependency);
+
+        assertThat(
+                        NoticeFileChecker.run(
+                                bundleDependencies,
+                                Collections.singleton(moduleName),
+                                Collections.singletonMap(
+                                        moduleName,
+                                        Optional.of(
+                                                new NoticeContents(
+                                                        moduleName,
+                                                        Collections.singletonList(
+                                                                bundledDependency))))))
+                .isEqualTo(0);
+    }
+
+    @Test
+    void testRunRejectsMissingNotice() throws IOException {
+        final String moduleName = "test";
+        final Dependency bundledDependency = Dependency.create("a", "b", "c");
+        final ArrayListMultimap<String, Dependency> bundleDependencies = ArrayListMultimap.create();
+        bundleDependencies.put(moduleName, bundledDependency);
+
+        assertThat(
+                        NoticeFileChecker.run(
+                                bundleDependencies,
+                                Collections.singleton(moduleName),
+                                Collections.singletonMap(moduleName, Optional.empty())))
+                .isEqualTo(1);
+    }
+
+    @Test
+    void testRunRejectsIncorrectNotice() throws IOException {
+        final String moduleName = "test";
+        final Dependency bundledDependency = Dependency.create("a", "b", "c");
+        final ArrayListMultimap<String, Dependency> bundleDependencies = ArrayListMultimap.create();
+        bundleDependencies.put(moduleName, bundledDependency);
+
+        assertThat(
+                        NoticeFileChecker.run(
+                                bundleDependencies,
+                                Collections.singleton(moduleName),
+                                Collections.singletonMap(
+                                        moduleName,
+                                        Optional.of(
+                                                new NoticeContents(
+                                                        moduleName, Collections.emptyList())))))
+                .isEqualTo(1);
+    }
+
+    @Test
+    void testRunSkipsNonDeployedModules() throws IOException {
+        final String moduleName = "test";
+        final Dependency bundledDependency = Dependency.create("a", "b", "c");
+        final ArrayListMultimap<String, Dependency> bundleDependencies = ArrayListMultimap.create();
+        bundleDependencies.put(moduleName, bundledDependency);
+
+        assertThat(
+                        NoticeFileChecker.run(
+                                bundleDependencies,
+                                Collections.emptySet(),
+                                Collections.singletonMap(
+                                        moduleName,
+                                        Optional.of(
+                                                new NoticeContents(
+                                                        moduleName, Collections.emptyList())))))
+                .isEqualTo(0);
+    }

Review Comment:
   I feel like these tests should be more transparent about what's going on. E.g., something more like this:
   
   ```
       void testRunSkipsNonDeployedModules() throws IOException {
           final String moduleName = "test";
           final Dependency bundledDependency = Dependency.create("a", "b", "c");
           final ArrayListMultimap<String, Dependency> moduleWithBundledDependencies = ArrayListMultimap.create();
           bundleDependencies.put(moduleName, bundledDependency);
           Set<String> noDeployedModules = Collections.emptySet();
           Map<String, Optional<NoticeContents>> incorrectNotice = Collections.singletonMap(
                           moduleName,
                           Optional.of(new NoticeContents(moduleName, Collections.emptyList())));
   
           assertThat(
                           NoticeFileChecker.run(
                                   moduleWithBundledDependencies,
                                   noDeployedModules,
                                   incorrectNotice))
                   .isEqualTo(0);
       }
   ```



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org