From 218c0114c28b8b72aa265fd7ae1f4f6f6dfdca49 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 11 May 2019 06:24:35 +0100 Subject: [PATCH] [syncsuite] improve tests for s3client thunk --- .../scala/net/kemitix/s3thorp/SyncSuite.scala | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala b/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala index c921b3a..47c0860 100644 --- a/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala +++ b/src/test/scala/net/kemitix/s3thorp/SyncSuite.scala @@ -1,26 +1,53 @@ package net.kemitix.s3thorp +import java.io.File import java.time.Instant import cats.effect.IO +import net.kemitix.s3thorp.Sync.{Bucket, LocalFile, MD5Hash, RemoteKey} import net.kemitix.s3thorp.awssdk.S3Client import org.scalatest.FunSpec class SyncSuite extends FunSpec { describe("s3client thunk") { - val hash = "hash" - val lastModified = Instant.now() - val sync = new Sync(new S3Client with DummyS3Client { - override def objectHead(bucket: String, key: String) = - IO(Some((hash, lastModified))) - }) + val testBucket = "bucket" + val testRemoteKey = "prefix/file" describe("objectHead") { - it("return the hash and lastModified expected") { - assertResult(Some((hash, lastModified)))( - sync.objectHead("", ""). + val md5Hash = "md5Hash" + val lastModified = Instant.now() + val sync = new Sync(new S3Client with DummyS3Client { + override def objectHead(bucket: String, key: String) = { + assert(bucket == testBucket) + assert(key == testRemoteKey) + IO(Some((md5Hash, lastModified))) + } + }) + it("delegates unmodified to the S3Client") { + assertResult(Some((md5Hash, lastModified)))( + sync.objectHead(testBucket, testRemoteKey). + unsafeRunSync()) + } + } + describe("upload") { + val md5Hash = "the-hash" + val testLocalFile = new File("file") + val sync = new Sync(new S3Client with DummyS3Client { + override def upload(localFile: LocalFile, bucket: Bucket, remoteKey: RemoteKey): IO[Either[Throwable, MD5Hash]] = { + assert(localFile == testLocalFile) + assert(bucket == testBucket) + assert(remoteKey == testRemoteKey) + IO(Right(md5Hash)) + } + }) + it("delegates unmodified to the S3Client") { + assertResult(Right(md5Hash))( + sync.upload(testLocalFile, testBucket, testRemoteKey). unsafeRunSync()) } } } + describe("run") { + + } }