[reactives3client] objectHead response okay then return Some
This commit is contained in:
parent
3eddc09a20
commit
1944d6620c
5 changed files with 68 additions and 5 deletions
|
@ -1,12 +1,9 @@
|
|||
package net.kemitix.s3thorp.awssdk
|
||||
|
||||
import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient
|
||||
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
|
||||
import software.amazon.awssdk.services.s3.{S3AsyncClient => JavaS3AsyncClient}
|
||||
|
||||
trait CatsIOS3Client {
|
||||
|
||||
def s3Client = S3CatsIOClient(S3AsyncClient(JavaS3AsyncClient.create))
|
||||
trait CatsIOS3Client extends S3CatsIOClientProvider {
|
||||
|
||||
def s3Client = S3CatsIOClient(underlying)
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ private class ReactiveS3Client
|
|||
_ <- putStrLn(s" -- ${response.eTag()} : ${response.lastModified()}")
|
||||
} yield Some((response.eTag(), response.lastModified()))
|
||||
} catch {
|
||||
//FIXME: this isn't catching the exception
|
||||
case _: NoSuchKeyException => IO(None)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package net.kemitix.s3thorp.awssdk
|
||||
|
||||
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
|
||||
|
||||
trait S3CatsIOClientProvider extends UnderlyingS3AsyncClient {
|
||||
|
||||
def s3Client: S3CatsIOClient
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package net.kemitix.s3thorp.awssdk
|
||||
|
||||
import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient
|
||||
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
|
||||
import software.amazon.awssdk.services.s3.{S3AsyncClient => JavaS3AsyncClient}
|
||||
|
||||
trait UnderlyingS3AsyncClient extends S3CatsIOClient{
|
||||
|
||||
override val underlying: S3AsyncClient = S3AsyncClient(JavaS3AsyncClient.create)
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package net.kemitix.s3thorp.awssdk
|
||||
|
||||
import java.time.Instant
|
||||
|
||||
import cats.effect.IO
|
||||
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
|
||||
import org.scalatest.FunSpec
|
||||
import software.amazon.awssdk.services.s3.model.{HeadObjectRequest, HeadObjectResponse}
|
||||
|
||||
class ReactiveS3ClientTest extends FunSpec {
|
||||
|
||||
describe("testObjectHead") {
|
||||
def invoke(self: S3Client) = {
|
||||
self.objectHead("bucket", "remoteKey").unsafeRunSync()
|
||||
}
|
||||
|
||||
describe("when response is okay") {
|
||||
val expectedHash = "hash"
|
||||
val expectedLastModified = Instant.now
|
||||
new ReactiveS3Client { self: S3Client => {
|
||||
it("should return Some(expected values)") {
|
||||
val result: Option[(String, Instant)] = invoke(self)
|
||||
assertResult(Some((expectedHash, expectedLastModified)))(result)
|
||||
}
|
||||
}
|
||||
override def s3Client: S3CatsIOClient = new S3CatsIOClient with UnderlyingS3AsyncClient {
|
||||
override def headObject(headObjectRequest: HeadObjectRequest): IO[HeadObjectResponse] =
|
||||
IO(HeadObjectResponse.builder().
|
||||
eTag(expectedHash).
|
||||
lastModified(expectedLastModified).
|
||||
build())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// describe("when throws NoSuchKeyException") {
|
||||
// new ReactiveS3Client with S3CatsIOClientProvider { self =>
|
||||
// it("should return None") {
|
||||
// assertResult(None)(result)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue