From 14454bd573f85d3bfd41fca3beddc331b465b758 Mon Sep 17 00:00:00 2001 From: Marc LAMY Date: Wed, 10 Apr 2024 19:16:44 +0200 Subject: [PATCH] add the FileSystemSpec trait --- .../amadeus/dataio/test/FileSystemSpec.scala | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/src/main/scala/com/amadeus/dataio/test/FileSystemSpec.scala diff --git a/test/src/main/scala/com/amadeus/dataio/test/FileSystemSpec.scala b/test/src/main/scala/com/amadeus/dataio/test/FileSystemSpec.scala new file mode 100644 index 0000000..b27e52d --- /dev/null +++ b/test/src/main/scala/com/amadeus/dataio/test/FileSystemSpec.scala @@ -0,0 +1,36 @@ +package com.amadeus.dataio.test + +import org.apache.hadoop.conf.Configuration +import org.apache.hadoop.fs.{FileSystem, Path} +import org.scalatest.{BeforeAndAfter, TestSuite} + +/** + * Provides the Hadoop LocalFileSystem for tests needing direct access to an instance of FileSystem. + * + * Provides a dedicated instance initialized before each test and automatically closed after each test, providing as + * much isolation as possible between tests. It also deletes the dataio-test temporary directory (/tmp/dataio-test/) and + * sub-directories, before closing the FileSystem. + * + * e.g. + * {{{ + * class MyClassTest extends WordSpec with FileSystemSpec{ + * // provided by FileSystemSpec: + * // fs: FileSystem + * // val tmpPath: String = "file:///tmp/dataio-test/" + * } + * }}} + */ +trait FileSystemSpec extends TestSuite with BeforeAndAfter { + val tmpPath = "file:///tmp/dataio-test/" + + var fs: FileSystem = _ + + before { + fs = FileSystem.newInstance(new Configuration()) + } + + after { + fs.delete(new Path(tmpPath), true) + fs.close() + } +}