Skip to content

Commit

Permalink
Upd specs
Browse files Browse the repository at this point in the history
  • Loading branch information
tampler committed Mar 9, 2020
1 parent 0e75d47 commit 87ac25b
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 121 deletions.
261 changes: 140 additions & 121 deletions src/test/scala/BaseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,123 +25,144 @@ import java.io.IOException
import setup._
import Helper._

object Tests {

val bucketsSuite = suite("AWS S3 Buckets suite")(
testM("list all buckets") {
println(s"Using Region: ${region} and Endpoint: ${endpoint}")
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.listBuckets(s3)
_ = println(out)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
}
)

val objectsSuite = suite("AWS S3 Objects suite")(
testM("lookup an object. True if present") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.lookupObject(bucket, prefix, key)(s3)
_ = println(s"Found objects: ${out}")
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
},
testM("list all keys, related to a specific prefix") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.listObjectsKeys(bucket, prefix)(s3)
_ = println(out)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
}
)
val delSuite = suite("Delete suite")(
testM("list and delete object") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.listObjectsKeys(bucket, prefix)(s3)
_ = println(out)
_ = println("**** Carefully ! This method will ACTUALLY remove your AWS content !!!! ***")
_ = println("*** If you REALLY wanna remove it, uncomment the line below ***")
// _ <- aws.service.delAllObjects(bucket, prefix)(s3)

} yield ()

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
}
)

val redirSuite = suite("Redirection suite")(
testM("set a single object redirection") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.redirectObject(bucket, prefix, fullKey, url)(s3)
_ = println(out)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
} @@ ignore,
testM("set a multiple object redirection with a single prefix") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.redirectPack(bucket, prefix, url)(s3)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
}
)

val aclSuite = suite("ACL suite")(
testM("get pack ACL") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.getPackAcl(bucket, prefix)(s3)
_ = println(out)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
},
testM("set pack ACL") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.putPackAcl(bucket, prefix, false)(s3)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
} @@ ignore
)

val blockSuite = suite("Block suite")(
testM("block content pack by removing ACL grant") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.blockPack(bucket, prefix)(s3)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
} @@ ignore,
testM("unblock content pack by adding ACL grant") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.unblockPack(bucket, prefix)(s3)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
}
)
object BuckSpec extends ZIOBaseSpec {
def spec =
suite("AwsSpec")(
suite("blah")(
testM("list all buckets") {
println(s"Using Region: ${region} and Endpoint: ${endpoint}")
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.listBuckets(s3)
_ = println(out)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
}
)
)
}

object BuckSpec extends ZIOBaseSpec(suite("Bucket Spec")(Tests.bucketsSuite))
// object ObjSpec extends DefaultRunnableSpec(suite("Object Spec")(Tests.objectsSuite))
// object RedirSpec extends DefaultRunnableSpec(suite("Redirection Spec")(Tests.redirSuite))
// object AclSpec extends DefaultRunnableSpec(suite("ACL Spec")(Tests.aclSuite))
// object DelSpec extends DefaultRunnableSpec(suite("Redirection Spec")(Tests.delSuite))
// object BlockSpec extends DefaultRunnableSpec(suite("Blocking Spec")(Tests.blockSuite))
object ObjSpec extends ZIOBaseSpec {
def spec =
suite("AwsSpec")(
suite("blah")(
testM("lookup an object. True if present") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.lookupObject(bucket, prefix, key)(s3)
_ = println(s"Found objects: ${out}")
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
},
testM("list all keys, related to a specific prefix") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.listObjectsKeys(bucket, prefix)(s3)
_ = println(out)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
}
)
)
}

object DelSpec extends ZIOBaseSpec {
def spec =
suite("AwsSpec")(
suite("blah")(
testM("list and delete object") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.listObjectsKeys(bucket, prefix)(s3)
_ = println(out)
_ = println("**** Carefully ! This method will ACTUALLY remove your AWS content !!!! ***")
_ = println("*** If you REALLY wanna remove it, uncomment the line below ***")
// _ <- aws.service.delAllObjects(bucket, prefix)(s3)

} yield ()

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
}
)
)
}

object RedirSpec extends ZIOBaseSpec {
def spec =
suite("AwsSpec")(
suite("blah")(
testM("set a single object redirection") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.redirectObject(bucket, prefix, fullKey, url)(s3)
_ = println(out)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
} @@ ignore,
testM("set a multiple object redirection with a single prefix") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.redirectPack(bucket, prefix, url)(s3)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
}
)
)
}

object AclSpec extends ZIOBaseSpec {
def spec =
suite("AwsSpec")(
suite("blah")(
testM("get pack ACL") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.getPackAcl(bucket, prefix)(s3)
_ = println(out)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
},
testM("set pack ACL") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.putPackAcl(bucket, prefix, false)(s3)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
} @@ ignore
)
)
}

object BlockSpec extends ZIOBaseSpec {
def spec =
suite("AwsSpec")(
suite("blah")(
testM("block content pack by removing ACL grant") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.blockPack(bucket, prefix)(s3)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
} @@ ignore,
testM("unblock content pack by adding ACL grant") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.unblockPack(bucket, prefix)(s3)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")))(equalTo("ok"))
}
)
)
}

object Helper {
import java.nio.file.{ Files }
Expand All @@ -154,12 +175,10 @@ object Helper {
Files.createFile(path).toFile
}

val aws = new AwsLink {}
val key = "42x42.jpg"
val url = "backup"
val prefix = "media/uploads/images/cf3a53e4-37bd-11ea-b430-6f9a089d05d1"
// val prefix = "media/uploads/images/a3565a30-e465-11e9-a274-456d87bf0d45"
// val prefix = "media/uploads/images/dea5c048-37bd-11ea-8194-399b761e9b96"
val aws = new AwsLink {}
val key = "42x42.jpg"
val url = "backup"
val prefix = "media/uploads/images/cf3a53e4-37bd-11ea-b430-6f9a089d05d1"
val fullKey = prefix + "/" + key

}
16 changes: 16 additions & 0 deletions src/test/scala/ZIOBaseSpec.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 Neurodyne Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio_aws_s3

import zio.duration._
Expand Down

0 comments on commit 87ac25b

Please sign in to comment.