Skip to content

Commit

Permalink
add the FileSystemSpec trait
Browse files Browse the repository at this point in the history
  • Loading branch information
marclamy committed Apr 10, 2024
1 parent 5b47c88 commit 14454bd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/src/main/scala/com/amadeus/dataio/test/FileSystemSpec.scala
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 14454bd

Please sign in to comment.