LuciferYang commented on code in PR #56590:
URL: https://github.com/apache/spark/pull/56590#discussion_r3489419558


##########
common/utils/src/test/scala/org/apache/spark/util/SparkFileUtilsSuite.scala:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.spark.util
+
+import java.io.File
+import java.nio.file.Files
+
+import org.scalatest.funsuite.AnyFunSuite // scalastyle:ignore funsuite
+
+class SparkFileUtilsSuite extends AnyFunSuite { // scalastyle:ignore funsuite
+
+  test("recursiveList lists all nested files and directories") {
+    val root = Files.createTempDirectory("spark-recursive-list").toFile
+    try {
+      val sub = new File(root, "sub")
+      assert(sub.mkdir())
+      val nested = new File(sub, "nested")
+      assert(nested.mkdir())
+      val topFile = new File(root, "top.txt")
+      assert(topFile.createNewFile())
+      val subFile = new File(sub, "sub.txt")
+      assert(subFile.createNewFile())
+
+      assert(SparkFileUtils.recursiveList(root).toSet === Set(sub, nested, 
topFile, subFile))
+    } finally {
+      SparkFileUtils.deleteQuietly(root)
+    }
+  }
+
+  test("recursiveList returns empty instead of throwing when a directory 
cannot be listed") {

Review Comment:
   Done in f3d18c048e5. `withLogAppender` lives in `SparkFunSuite` (core), 
which is not on the classpath here -- `common/utils` suites only extend 
`AnyFunSuite`. I considered moving the suite to core to use it, but that would 
push a low-level module's test up a layer (and pull in the `SparkFunSuite` base 
just for a file-walk unit test), which is not worth it. Instead I followed the 
existing `captureLogOutput` pattern from `StructuredLoggingSuite`: added a 
dedicated file appender for the `SparkFileUtils` logger in `log4j2.properties`, 
and the test now asserts the warning ("Failed to list directory" + the skipped 
path) is emitted, not just that no exception is thrown.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to