[syncsuite] improve tests for s3client thunk
This commit is contained in:
parent
960e336867
commit
218c0114c2
1 changed files with 36 additions and 9 deletions
|
@ -1,26 +1,53 @@
|
||||||
package net.kemitix.s3thorp
|
package net.kemitix.s3thorp
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
import cats.effect.IO
|
import cats.effect.IO
|
||||||
|
import net.kemitix.s3thorp.Sync.{Bucket, LocalFile, MD5Hash, RemoteKey}
|
||||||
import net.kemitix.s3thorp.awssdk.S3Client
|
import net.kemitix.s3thorp.awssdk.S3Client
|
||||||
import org.scalatest.FunSpec
|
import org.scalatest.FunSpec
|
||||||
|
|
||||||
class SyncSuite extends FunSpec {
|
class SyncSuite extends FunSpec {
|
||||||
|
|
||||||
describe("s3client thunk") {
|
describe("s3client thunk") {
|
||||||
val hash = "hash"
|
val testBucket = "bucket"
|
||||||
|
val testRemoteKey = "prefix/file"
|
||||||
|
describe("objectHead") {
|
||||||
|
val md5Hash = "md5Hash"
|
||||||
val lastModified = Instant.now()
|
val lastModified = Instant.now()
|
||||||
val sync = new Sync(new S3Client with DummyS3Client {
|
val sync = new Sync(new S3Client with DummyS3Client {
|
||||||
override def objectHead(bucket: String, key: String) =
|
override def objectHead(bucket: String, key: String) = {
|
||||||
IO(Some((hash, lastModified)))
|
assert(bucket == testBucket)
|
||||||
|
assert(key == testRemoteKey)
|
||||||
|
IO(Some((md5Hash, lastModified)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
describe("objectHead") {
|
it("delegates unmodified to the S3Client") {
|
||||||
it("return the hash and lastModified expected") {
|
assertResult(Some((md5Hash, lastModified)))(
|
||||||
assertResult(Some((hash, lastModified)))(
|
sync.objectHead(testBucket, testRemoteKey).
|
||||||
sync.objectHead("", "").
|
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())
|
unsafeRunSync())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
describe("run") {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue