From 43f1d800b92241d86703b5518aab171e039fde4e Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 9 Feb 2017 21:54:46 +0100 Subject: Add test for unmarshalling github issue form JSON --- bot/test/PRServiceTests.scala | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 bot/test/PRServiceTests.scala (limited to 'bot/test/PRServiceTests.scala') diff --git a/bot/test/PRServiceTests.scala b/bot/test/PRServiceTests.scala new file mode 100644 index 000000000..a8fdba6e2 --- /dev/null +++ b/bot/test/PRServiceTests.scala @@ -0,0 +1,34 @@ +package dotty.tools.bot + +import org.junit.Assert._ +import org.junit.Test + +import io.circe._ +import io.circe.generic.auto._ +import io.circe.syntax._ +import io.circe.parser.decode + +import model.Github._ +import org.http4s.client.blaze._ +import scalaz.concurrent.Task + +class PRServiceTests extends PullRequestService { + val user = sys.env("USER") + val token = sys.env("TOKEN") + + def getResource(r: String): String = + Option(getClass.getResourceAsStream(r)).map(scala.io.Source.fromInputStream) + .map(_.mkString) + .getOrElse(throw new Exception(s"resource not found: $r")) + + + @Test def canUnmarshalIssueJson = { + val json = getResource("/test-pr.json") + val issue: Issue = decode[Issue](json) match { + case Right(is: Issue) => is + case Left(ex) => throw ex + } + + assert(issue.pull_request.isDefined, "missing pull request") + } +} -- cgit v1.2.3