[s3uploader] implement with (basic) test

This commit is contained in:
Paul Campbell 2019-05-09 18:34:17 +01:00
parent befd6975fa
commit e43b7dc0e3
3 changed files with 40 additions and 10 deletions

View file

@ -7,15 +7,19 @@ import cats.effect.IO
import net.kemitix.s3thorp.Main.putStrLn
import net.kemitix.s3thorp.awssdk.S3Client
import scala.concurrent.Promise
trait S3Uploader
extends S3Client
with KeyGenerator {
trait S3Uploader extends S3Client {
def performUpload: File => Stream[IO, Promise[Unit]] =
file => Stream.eval(for {
def performUpload(c: Config): File => Stream[IO, Unit] = {
val remoteKey = generateKey(c) _
file =>
Stream.eval(for {
_ <- putStrLn(s"uploading: $file")
// upload
p = Promise[Unit]()
} yield p)
key = remoteKey(file)
_ <- upload(file, c.bucket, key)
_ <- putStrLn(s"uploaded: ${c.bucket}/$key")
} yield ())
}
}

View file

@ -26,7 +26,7 @@ class Sync(s3Client: S3Client)
streamDirectoryPaths(c.source).flatMap(
enrichWithS3MetaData(c)).flatMap(
uploadRequiredFilter).flatMap(
performUpload).compile.drain
performUpload(c)).compile.drain
}
} yield ()

View file

@ -0,0 +1,26 @@
package net.kemitix.s3thorp
import java.io.File
import cats.effect.IO
import net.kemitix.s3thorp.Sync.{Bucket, LastModified, LocalFile, MD5Hash, RemoteKey}
import org.scalatest.FunSpec
class S3UploaderSuite extends FunSpec {
new S3Uploader {
override def objectHead(bucket: String, key: String): IO[Option[(MD5Hash, LastModified)]] = ???
override def upload(localFile: LocalFile, bucket: Bucket, remoteKey: RemoteKey): IO[Unit] = IO()
describe("upload") {
val config: Config = Config("bucket", "prefix", new File("/path/to/files"))
def invoke(file: File) =
performUpload(config)(file).compile.toList.unsafeRunSync()
it("should return") {
val result = invoke(new File("/path/to/files/a-file-to-upload.txt"))
assertResult(List(()))(result)
}
}
}
}