From e963827fc5238e06fa7e42c045d7022b608d86df Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 11 May 2019 13:20:23 +0100 Subject: [PATCH] [resource] test helper for loading resources --- src/test/scala/net/kemitix/s3thorp/Resource.scala | 13 +++++++++++++ src/test/scala/net/kemitix/s3thorp/SyncSuite.scala | 2 +- .../s3thorp/UploadSelectionFilterSuite.scala | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/test/scala/net/kemitix/s3thorp/Resource.scala diff --git a/src/test/scala/net/kemitix/s3thorp/Resource.scala b/src/test/scala/net/kemitix/s3thorp/Resource.scala new file mode 100644 index 0000000..57d14c4 --- /dev/null +++ b/src/test/scala/net/kemitix/s3thorp/Resource.scala @@ -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)) +} diff --git a/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala b/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala index e7d6d3e..4c08023 100644 --- a/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala +++ b/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala @@ -49,7 +49,7 @@ class SyncSuite extends FunSpec { } describe("run") { 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 val config = Config("bucket", "prefix", source) describe("when all files should be uploaded") { diff --git a/src/test/scala/net/kemitix/s3thorp/UploadSelectionFilterSuite.scala b/src/test/scala/net/kemitix/s3thorp/UploadSelectionFilterSuite.scala index 2ad50a0..205c5f4 100644 --- a/src/test/scala/net/kemitix/s3thorp/UploadSelectionFilterSuite.scala +++ b/src/test/scala/net/kemitix/s3thorp/UploadSelectionFilterSuite.scala @@ -9,7 +9,7 @@ class UploadSelectionFilterSuite extends FunSpec { new UploadSelectionFilter { 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 config = Config("bucket", "prefix", localFile.getParentFile) def invokeSubject(input: Either[File, S3MetaData]) =