Skip to content

Commit 3d4ab10

Browse files
authored
Merge pull request #46 from clhodapp/feature/json-in-types
JSON in types
2 parents 1166608 + 4e23133 commit 3d4ab10

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist: trusty
12
language: scala
23

34
scala:
@@ -7,6 +8,9 @@ scala:
78
jdk:
89
- oraclejdk8
910

11+
addons:
12+
postgresql: "9.5"
13+
1014
services:
1115
- postgresql
1216

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ val baseSettings = Seq(
1414
"com.twitter" %% "finagle-netty3" % "18.2.0",
1515
"org.scalatest" %% "scalatest" % "3.0.4" % "test,it",
1616
"org.scalacheck" %% "scalacheck" % "1.13.5" % "test,it",
17-
"org.scalamock" %% "scalamock-scalatest-support" % "3.4.2" % "test,it"
17+
"org.scalamock" %% "scalamock-scalatest-support" % "3.4.2" % "test,it",
18+
"io.circe" %% "circe-testing" % "0.8.0" % "test,it"
1819
)
1920
)
2021

src/main/scala/com/twitter/finagle/postgres/PostgresClient.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ object PostgresClient {
8181

8282
case class TypeSpecifier(receiveFunction: String, typeName: String, elemOid: Long = 0)
8383

84-
private[finagle] val defaultTypes = Map(
84+
val defaultTypes = Map(
8585
Types.BOOL -> TypeSpecifier("boolrecv", "bool"),
8686
Types.BYTE_A -> TypeSpecifier("bytearecv", "bytea"),
8787
Types.CHAR -> TypeSpecifier("charrecv", "char"),
@@ -95,6 +95,7 @@ object PostgresClient {
9595
Types.TID -> TypeSpecifier("tidrecv", "tid"),
9696
Types.XID -> TypeSpecifier("xidrecv", "xid"),
9797
Types.CID -> TypeSpecifier("cidrecv", "cid"),
98+
Types.JSON -> TypeSpecifier("json_recv", "json"),
9899
Types.XML -> TypeSpecifier("xml_recv", "xml"),
99100
Types.POINT -> TypeSpecifier("point_recv", "point"),
100101
Types.L_SEG -> TypeSpecifier("lseg_recv", "lseg"),

src/main/scala/com/twitter/finagle/postgres/values/Types.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ object Types {
1717
val TID = 27
1818
val XID = 28
1919
val CID = 29
20+
val JSON = 114
2021
val XML = 142
2122
val POINT = 600
2223
val L_SEG = 601

src/test/scala/com/twitter/finagle/postgres/values/ValuesSpec.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import com.twitter.finagle.postgres.messages.DataRow
1515
import com.twitter.finagle.postgres.messages.Field
1616
import com.twitter.util.Await
1717
import org.jboss.netty.buffer.ChannelBuffers
18-
import org.scalacheck.Arbitrary
18+
import org.scalacheck.{Arbitrary, Gen}
19+
import Arbitrary.arbitrary
1920
import org.scalatest.prop.GeneratorDrivenPropertyChecks
21+
import io.circe.testing.instances.arbitraryJson
2022

2123
class ValuesSpec extends Spec with GeneratorDrivenPropertyChecks {
2224

@@ -156,6 +158,17 @@ class ValuesSpec extends Spec with GeneratorDrivenPropertyChecks {
156158
val decoded = ValueDecoder[JSONB].decodeBinary("", createBuffer(), Charset.defaultCharset()).get()
157159
JSONB.stringify(decoded) must equal(json)
158160
}
161+
162+
"parse json" in test(ValueDecoder.string, ValueEncoder.string)("json_send", "json")(
163+
Arbitrary(
164+
Gen.oneOf(
165+
arbitraryJson.arbitrary.map(_.noSpaces),
166+
arbitraryJson.arbitrary.map(_.spaces4),
167+
arbitraryJson.arbitrary.map(_.spaces2)
168+
).map(_.replace("\u0000", "\\u0000"))
169+
),
170+
client
171+
)
159172
}
160173
}
161174
}

0 commit comments

Comments
 (0)