Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
create workdir if it does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
romangrebennikov committed Aug 30, 2016
1 parent de65d00 commit 3ded264
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.0" % "test",
"com.amazonaws" % "aws-java-sdk-s3" % "1.11.29" % "test",
"com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion % "test",
//"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"commons-io" % "commons-io" % "2.5" % "test",
"ch.qos.logback" % "logback-classic" % "1.1.7" % "test"
)
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/io/findify/s3mock/provider/FileProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import scala.util.Random
* Created by shutty on 8/9/16.
*/
class FileProvider(dir:String) extends Provider with LazyLogging {
val workDir = File(dir)
if (!workDir.exists) workDir.createDirectories()

def listBuckets: ListAllMyBuckets = {
val buckets = File(dir).list.map(f => Bucket(f.name, DateTime(f.lastModifiedTime.toEpochMilli))).toList
logger.debug(s"listing buckets: ${buckets.map(_.name)}")
Expand Down
37 changes: 37 additions & 0 deletions src/test/scala/io/findify/s3mock/ListBucketEmptyWorkdirTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.findify.s3mock

import java.util.UUID

import scala.collection.JavaConverters._
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.services.s3.AmazonS3Client
import io.findify.s3mock.provider.FileProvider
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}

/**
* Created by shutty on 8/30/16.
*/
class ListBucketEmptyWorkdirTest extends FlatSpec with Matchers with BeforeAndAfterAll {
lazy val s3 = new AmazonS3Client(new BasicAWSCredentials("hello", "world"))

val workDir = s"/tmp/${UUID.randomUUID()}"
lazy val server = new S3Mock(8001, new FileProvider(workDir))

override def beforeAll = {
s3.setEndpoint("http://127.0.0.1:8001")
server.start
}
override def afterAll = {
server.stop
}

"s3mock" should "list bucket with empty prefix" in {
s3.createBucket("list")
s3.putObject("list", "foo1", "xxx")
s3.putObject("list", "foo2", "xxx")
val list = s3.listObjects("list").getObjectSummaries.asScala.toList
list.map(_.getKey).forall(_.startsWith("/foo")) shouldBe true
}


}

0 comments on commit 3ded264

Please sign in to comment.