File tree 2 files changed +62
-1
lines changed
2 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ object Repositories {
13
13
Json .obj(
14
14
" name" -> name,
15
15
" type" -> (info \ " type" ).as[JsValue ],
16
- " settings" -> (info \ " settings" ).as[ JsValue ]
16
+ " settings" -> (info \ " settings" ).asOpt[ JsObject ].getOrElse[ JsObject ]( Json .obj())
17
17
)
18
18
}.toSeq
19
19
)
Original file line number Diff line number Diff line change
1
+ package models .repository
2
+
3
+ import org .specs2 .Specification
4
+ import play .api .libs .json .Json
5
+
6
+ object RepositoriesSpec extends Specification {
7
+
8
+ def is =
9
+ s2 """
10
+ Repositories should
11
+ parse all repository info $repositories
12
+ tolerate missing settings for repository $missingSettings
13
+
14
+ """
15
+
16
+ def repositories = {
17
+ val data = Json .parse(
18
+ """
19
+ |{
20
+ | "some_repo_with_settings": {
21
+ | "type": "s3",
22
+ | "settings": {
23
+ | "bucket": "bucket_name",
24
+ | "region": "us"
25
+ | }
26
+ | }
27
+ |}
28
+ """ .stripMargin
29
+ )
30
+ Repositories (data) mustEqual Json .arr(
31
+ Json .obj(
32
+ " name" -> " some_repo_with_settings" ,
33
+ " type" -> " s3" ,
34
+ " settings" -> Json .obj(
35
+ " bucket" -> " bucket_name" ,
36
+ " region" -> " us"
37
+ )
38
+ )
39
+ )
40
+ }
41
+
42
+ def missingSettings = {
43
+ val data = Json .parse(
44
+ """
45
+ |{
46
+ | "some_repo_with_settings": {
47
+ | "type": "s3"
48
+ | }
49
+ |}
50
+ """ .stripMargin
51
+ )
52
+ Repositories (data) mustEqual Json .arr(
53
+ Json .obj(
54
+ " name" -> " some_repo_with_settings" ,
55
+ " type" -> " s3" ,
56
+ " settings" -> Json .obj()
57
+ )
58
+ )
59
+ }
60
+
61
+ }
You can’t perform that action at this time.
0 commit comments