Skip to content

Commit

Permalink
tolerate missing settings for repositories
Browse files Browse the repository at this point in the history
closes #409
  • Loading branch information
lmenezes committed Feb 14, 2020
1 parent 9dbece3 commit 2bed332
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/repository/Repositories.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Repositories {
Json.obj(
"name" -> name,
"type" -> (info \ "type").as[JsValue],
"settings" -> (info \ "settings").as[JsValue]
"settings" -> (info \ "settings").asOpt[JsObject].getOrElse[JsObject](Json.obj())
)
}.toSeq
)
Expand Down
61 changes: 61 additions & 0 deletions test/models/repository/RepositoriesSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package models.repository

import org.specs2.Specification
import play.api.libs.json.Json

object RepositoriesSpec extends Specification {

def is =
s2"""
Repositories should
parse all repository info $repositories
tolerate missing settings for repository $missingSettings

"""

def repositories = {
val data = Json.parse(
"""
|{
| "some_repo_with_settings": {
| "type": "s3",
| "settings": {
| "bucket": "bucket_name",
| "region": "us"
| }
| }
|}
""".stripMargin
)
Repositories(data) mustEqual Json.arr(
Json.obj(
"name" -> "some_repo_with_settings",
"type" -> "s3",
"settings" -> Json.obj(
"bucket" -> "bucket_name",
"region" -> "us"
)
)
)
}

def missingSettings = {
val data = Json.parse(
"""
|{
| "some_repo_with_settings": {
| "type": "s3"
| }
|}
""".stripMargin
)
Repositories(data) mustEqual Json.arr(
Json.obj(
"name" -> "some_repo_with_settings",
"type" -> "s3",
"settings" -> Json.obj()
)
)
}

}

0 comments on commit 2bed332

Please sign in to comment.