Skip to content

Commit

Permalink
Merge pull request #46 from clhodapp/feature/json-in-types
Browse files Browse the repository at this point in the history
JSON in types
  • Loading branch information
dangerousben authored May 26, 2018
2 parents 1166608 + 4e23133 commit 3d4ab10
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: trusty
language: scala

scala:
Expand All @@ -7,6 +8,9 @@ scala:
jdk:
- oraclejdk8

addons:
postgresql: "9.5"

services:
- postgresql

Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ val baseSettings = Seq(
"com.twitter" %% "finagle-netty3" % "18.2.0",
"org.scalatest" %% "scalatest" % "3.0.4" % "test,it",
"org.scalacheck" %% "scalacheck" % "1.13.5" % "test,it",
"org.scalamock" %% "scalamock-scalatest-support" % "3.4.2" % "test,it"
"org.scalamock" %% "scalamock-scalatest-support" % "3.4.2" % "test,it",
"io.circe" %% "circe-testing" % "0.8.0" % "test,it"
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object PostgresClient {

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

private[finagle] val defaultTypes = Map(
val defaultTypes = Map(
Types.BOOL -> TypeSpecifier("boolrecv", "bool"),
Types.BYTE_A -> TypeSpecifier("bytearecv", "bytea"),
Types.CHAR -> TypeSpecifier("charrecv", "char"),
Expand All @@ -95,6 +95,7 @@ object PostgresClient {
Types.TID -> TypeSpecifier("tidrecv", "tid"),
Types.XID -> TypeSpecifier("xidrecv", "xid"),
Types.CID -> TypeSpecifier("cidrecv", "cid"),
Types.JSON -> TypeSpecifier("json_recv", "json"),
Types.XML -> TypeSpecifier("xml_recv", "xml"),
Types.POINT -> TypeSpecifier("point_recv", "point"),
Types.L_SEG -> TypeSpecifier("lseg_recv", "lseg"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object Types {
val TID = 27
val XID = 28
val CID = 29
val JSON = 114
val XML = 142
val POINT = 600
val L_SEG = 601
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import com.twitter.finagle.postgres.messages.DataRow
import com.twitter.finagle.postgres.messages.Field
import com.twitter.util.Await
import org.jboss.netty.buffer.ChannelBuffers
import org.scalacheck.Arbitrary
import org.scalacheck.{Arbitrary, Gen}
import Arbitrary.arbitrary
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import io.circe.testing.instances.arbitraryJson

class ValuesSpec extends Spec with GeneratorDrivenPropertyChecks {

Expand Down Expand Up @@ -156,6 +158,17 @@ class ValuesSpec extends Spec with GeneratorDrivenPropertyChecks {
val decoded = ValueDecoder[JSONB].decodeBinary("", createBuffer(), Charset.defaultCharset()).get()
JSONB.stringify(decoded) must equal(json)
}

"parse json" in test(ValueDecoder.string, ValueEncoder.string)("json_send", "json")(
Arbitrary(
Gen.oneOf(
arbitraryJson.arbitrary.map(_.noSpaces),
arbitraryJson.arbitrary.map(_.spaces4),
arbitraryJson.arbitrary.map(_.spaces2)
).map(_.replace("\u0000", "\\u0000"))
),
client
)
}
}
}

0 comments on commit 3d4ab10

Please sign in to comment.