diff --git a/src/main/scala/io/findify/s3mock/provider/FileProvider.scala b/src/main/scala/io/findify/s3mock/provider/FileProvider.scala index 81527d0..b0ac29f 100644 --- a/src/main/scala/io/findify/s3mock/provider/FileProvider.scala +++ b/src/main/scala/io/findify/s3mock/provider/FileProvider.scala @@ -46,7 +46,7 @@ class FileProvider(dir:String) extends Provider with LazyLogging { val files = bucketFiles.map(f => {Content(f.toString.drop(bucketFileString.length+1).dropWhile(_ == '/'), DateTime(f.lastModifiedTime.toEpochMilli), "0", f.size, "STANDARD")}).toList logger.debug(s"listing bucket contents: ${files.map(_.key)}") val commonPrefixes = delimiter match { - case Some(del) => files.flatMap(f => commonPrefix(f.key, prefixNoLeadingSlash, del)).distinct + case Some(del) => files.flatMap(f => commonPrefix(f.key, prefixNoLeadingSlash, del)).distinct.sorted case None => Nil } val filteredFiles = files.filterNot(f => commonPrefixes.exists(p => f.key.startsWith(p))) diff --git a/src/test/scala/io/findify/s3mock/ListBucketTest.scala b/src/test/scala/io/findify/s3mock/ListBucketTest.scala index f03bcba..74396da 100644 --- a/src/test/scala/io/findify/s3mock/ListBucketTest.scala +++ b/src/test/scala/io/findify/s3mock/ListBucketTest.scala @@ -154,14 +154,14 @@ class ListBucketTest extends S3MockTest { s3.putObject("list7", "dev/40/2017/03/13/00/_SUCCESS", "xxx") s3.putObject("list7", "dev/40/2017/03/13/01/_SUCCESS", "xxx") s3.putObject("list7", "dev/50/2017/03/13/00/_SUCCESS", "xxx") - s3.putObject("list7", "dev/60/2017/03/13/01/_SUCCESS", "xxx") + s3.putObject("list7", "dev/50/2017/03/13/01/_SUCCESS", "xxx") val req2 = new ListObjectsRequest() req2.setBucketName("list7") req2.setDelimiter("/") req2.setPrefix("dev/") val list2 = s3.listObjects(req2) val summaries2 = list2.getObjectSummaries.map(_.getKey).toList - list2.getCommonPrefixes.asScala.toList shouldBe List("dev/10", "dev/20", "dev/30", "dev/40", "dev/50") + list2.getCommonPrefixes.asScala.toList shouldBe List("dev/10/", "dev/20/", "dev/30/", "dev/40/", "dev/50/") summaries2 shouldBe Nil } }