[resource] test helper for loading resources

This commit is contained in:
Paul Campbell 2019-05-11 13:20:23 +01:00
parent d3d5784cb0
commit e963827fc5
3 changed files with 15 additions and 2 deletions

View file

@ -0,0 +1,13 @@
package net.kemitix.s3thorp
import java.io.{File, FileNotFoundException}
import scala.util.Try
object Resource {
def apply(base: AnyRef,
name: String): File =
Try(new File(base.getClass.getResource(name).getPath))
.getOrElse(throw new FileNotFoundException(name))
}

View file

@ -49,7 +49,7 @@ class SyncSuite extends FunSpec {
} }
describe("run") { describe("run") {
val testBucket = "bucket" val testBucket = "bucket"
val source = new File(Sync.getClass.getResource("upload").getPath) val source = Resource(this, "upload")
// source contains the files root-file and subdir/leaf-file // source contains the files root-file and subdir/leaf-file
val config = Config("bucket", "prefix", source) val config = Config("bucket", "prefix", source)
describe("when all files should be uploaded") { describe("when all files should be uploaded") {

View file

@ -9,7 +9,7 @@ class UploadSelectionFilterSuite extends FunSpec {
new UploadSelectionFilter { new UploadSelectionFilter {
describe("uploadRequiredFilter") { describe("uploadRequiredFilter") {
val localFile = new File("src/test/scala/net/kemitix/s3thorp/test-file-for-hash.txt") val localFile = Resource(this, "test-file-for-hash.txt")
val localHash = "0cbfe978783bd7950d5da4ff85e4af37" val localHash = "0cbfe978783bd7950d5da4ff85e4af37"
val config = Config("bucket", "prefix", localFile.getParentFile) val config = Config("bucket", "prefix", localFile.getParentFile)
def invokeSubject(input: Either[File, S3MetaData]) = def invokeSubject(input: Either[File, S3MetaData]) =