From 359ae1a900e11ab74440935994f4e3164b2b0487 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 11 May 2019 07:52:27 +0100 Subject: [PATCH] [syncsuite] add tests for run --- .../scala/net/kemitix/s3thorp/SyncSuite.scala | 48 ++++++++++++++++++- .../net/kemitix/s3thorp/upload/root-file | 1 + .../kemitix/s3thorp/upload/subdir/leaf-file | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/test/scala/net/kemitix/s3thorp/upload/root-file create mode 100644 src/test/scala/net/kemitix/s3thorp/upload/subdir/leaf-file diff --git a/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala b/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala index 47c0860..e7d6d3e 100644 --- a/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala +++ b/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala @@ -48,6 +48,52 @@ class SyncSuite extends FunSpec { } } describe("run") { - + val testBucket = "bucket" + val source = new File(Sync.getClass.getResource("upload").getPath) + // source contains the files root-file and subdir/leaf-file + val config = Config("bucket", "prefix", source) + describe("when all files should be uploaded") { + var uploadsRecord: Map[String, RemoteKey] = Map() + val sync = new Sync(new S3Client { + override def objectHead(bucket: Bucket, remoteKey: RemoteKey) = + IO(None) + override def upload(localFile: LocalFile, bucket: Bucket, remoteKey: RemoteKey) = { + if (bucket == testBucket) + uploadsRecord += (source.toPath.relativize(localFile.toPath).toString -> remoteKey) + IO(Right("some hash value")) + } + }) + it("uploads all files") { + sync.run(config).unsafeRunSync + val expected = Map( + "subdir/leaf-file" -> "prefix/subdir/leaf-file", + "root-file" -> "prefix/root-file" + ) + assertResult(expected)(uploadsRecord) + } + } + describe("when no files should be uploaded") { + val rootHash = "a3a6ac11a0eb577b81b3bb5c95cc8a6e" + val leafHash = "208386a650bdec61cfcd7bd8dcb6b542" + var uploadsRecord: Map[String, RemoteKey] = Map() + val sync = new Sync(new S3Client { + override def objectHead(bucket: Bucket, remoteKey: RemoteKey) = IO( + remoteKey match { + case "prefix/root-file" => Some((rootHash, Instant.now)) + case "prefix/subdir/leaf-file" => Some((leafHash, Instant.now)) + case _ => None + }) + override def upload(localFile: LocalFile, bucket: Bucket, remoteKey: RemoteKey) = { + if (bucket == testBucket) + uploadsRecord += (source.toPath.relativize(localFile.toPath).toString -> remoteKey) + IO(Right("some hash value")) + } + }) + it("uploads nothing") { + sync.run(config).unsafeRunSync + val expected = Map() + assertResult(expected)(uploadsRecord) + } + } } } diff --git a/src/test/scala/net/kemitix/s3thorp/upload/root-file b/src/test/scala/net/kemitix/s3thorp/upload/root-file new file mode 100644 index 0000000..996f41a --- /dev/null +++ b/src/test/scala/net/kemitix/s3thorp/upload/root-file @@ -0,0 +1 @@ +This file is in the root directory of the upload tree. diff --git a/src/test/scala/net/kemitix/s3thorp/upload/subdir/leaf-file b/src/test/scala/net/kemitix/s3thorp/upload/subdir/leaf-file new file mode 100644 index 0000000..b3d8af7 --- /dev/null +++ b/src/test/scala/net/kemitix/s3thorp/upload/subdir/leaf-file @@ -0,0 +1 @@ +This file is in the subdir folder within the upload tree.