gharris1727 commented on code in PR #14995:
URL: https://github.com/apache/kafka/pull/14995#discussion_r1481872234


##########
clients/src/test/java/org/apache/kafka/common/config/provider/MockFileConfigProvider.java:
##########
@@ -42,10 +43,12 @@ public void configure(Map<String, ?> configs) {
         }
         this.id = id.toString();
         INSTANCES.put(id.toString(), this);
+
+        super.configure(configs);

Review Comment:
   nit: call super at the top of the function, here and in the 
MockVaultConfigProvider.



##########
clients/src/test/java/org/apache/kafka/common/config/provider/FileConfigProviderTest.java:
##########
@@ -17,34 +17,56 @@
 package org.apache.kafka.common.config.provider;
 
 import org.apache.kafka.common.config.ConfigData;
+import org.apache.kafka.test.TestUtils;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.stream.StreamSupport;
 
+import static 
org.apache.kafka.common.config.provider.DirectoryConfigProvider.ALLOWED_PATHS_CONFIG;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class FileConfigProviderTest {
 
     private FileConfigProvider configProvider;
+    @TempDir
+    private File parent;
+    private String dir;
+    private String dirFile;
+    private String siblingDir;
+    private String siblingDirFile;
 
     @BeforeEach
-    public void setup() {
+    public void setup() throws IOException {
         configProvider = new TestFileConfigProvider();
+        configProvider.configure(Collections.emptyMap());
+        parent = TestUtils.tempDirectory();

Review Comment:
   Same as DirectoryConfigProviderTest



##########
clients/src/test/java/org/apache/kafka/common/config/provider/DirectoryConfigProviderTest.java:
##########
@@ -22,57 +22,67 @@
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Locale;
+import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.stream.StreamSupport;
 
 import static java.util.Arrays.asList;
+
+import static 
org.apache.kafka.common.config.provider.DirectoryConfigProvider.ALLOWED_PATHS_CONFIG;
 import static org.apache.kafka.test.TestUtils.toSet;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class DirectoryConfigProviderTest {
 
     private DirectoryConfigProvider provider;
+    @TempDir
     private File parent;
-    private File dir;
-    private File bar;
-    private File foo;
-    private File subdir;
-    private File subdirFile;
-    private File siblingDir;
-    private File siblingDirFile;
-    private File siblingFile;
-
-    private static File writeFile(File file) throws IOException {
-        Files.write(file.toPath(), 
file.getName().toUpperCase(Locale.ENGLISH).getBytes(StandardCharsets.UTF_8));
-        return file;
+    private String dir;
+    private final String bar = "bar";
+    private final String foo = "foo";
+    private String subdir;
+    private final String subdirFileName = "subdirFile";
+    private String siblingDir;
+    private final String siblingDirFileName = "siblingDirFile";
+    private final String siblingFileName = "siblingFile";
+
+    private static Path writeFile(Path path) throws IOException {
+        return Files.write(path, 
String.valueOf(path.getFileName()).toUpperCase(Locale.ENGLISH).getBytes(StandardCharsets.UTF_8));
     }
 
     @BeforeEach
     public void setup() throws IOException {
         provider = new DirectoryConfigProvider();
         provider.configure(Collections.emptyMap());
+
         parent = TestUtils.tempDirectory();

Review Comment:
   This is unnecessary now with the annotation. `@TempDir` behaves like 
`@Mock`, in that the field is filled out by the test framework before the test 
execution starts.



##########
clients/src/test/java/org/apache/kafka/common/config/provider/AllowedPathsTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.kafka.common.config.provider;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.apache.kafka.common.config.internals.AllowedPaths;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class AllowedPathsTest {
+
+    private AllowedPaths allowedPaths;
+    private String dir;
+    private String myFile;
+    private String dir2;
+
+    @BeforeEach
+    public void setup() throws IOException {
+        File parent = TestUtils.tempDirectory();

Review Comment:
   I see that you've used `@TempDir` in DirectoryConfigProviderTest and 
FileConfigProviderTest, but can you also use it here?



##########
clients/src/test/java/org/apache/kafka/common/config/provider/FileConfigProviderTest.java:
##########
@@ -17,34 +17,56 @@
 package org.apache.kafka.common.config.provider;
 
 import org.apache.kafka.common.config.ConfigData;
+import org.apache.kafka.test.TestUtils;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.stream.StreamSupport;
 
+import static 
org.apache.kafka.common.config.provider.DirectoryConfigProvider.ALLOWED_PATHS_CONFIG;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class FileConfigProviderTest {
 
     private FileConfigProvider configProvider;
+    @TempDir
+    private File parent;
+    private String dir;
+    private String dirFile;
+    private String siblingDir;
+    private String siblingDirFile;
 
     @BeforeEach
-    public void setup() {
+    public void setup() throws IOException {
         configProvider = new TestFileConfigProvider();
+        configProvider.configure(Collections.emptyMap());
+        parent = TestUtils.tempDirectory();
+
+        dir = Files.createDirectory(Paths.get(parent.getAbsolutePath(), 
"dir")).toString();
+        dirFile = Files.createFile(Paths.get(dir, "dirFile")).toString();
+
+        siblingDir = Files.createDirectory(Paths.get(parent.toString(), 
"siblingDir")).toString();
+        siblingDirFile = Files.createFile(Paths.get(siblingDir, 
"siblingDirFile")).toString();
     }
 
     @Test
     public void testGetAllKeysAtPath() {
-        ConfigData configData = configProvider.get("dummy");
+        ConfigData configData = configProvider.get("/dummy");

Review Comment:
   These tests still pass with the dummy string, can you keep the original test?



-- 
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