Skip to content

Commit

Permalink
Merge branch 'master' into hadoop
Browse files Browse the repository at this point in the history
  • Loading branch information
ruippeixotog authored Mar 15, 2018
2 parents 499c562 + b1d0157 commit bb0f3fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package pureconfig.modules

import org.http4s.Uri
import pureconfig.ConfigReader
import pureconfig.error.CannotConvert

package object http4s {

implicit val uriReader: ConfigReader[Uri] =
ConfigReader[String].map(str => Uri(path = str))
ConfigReader.fromString(str =>
Uri.fromString(str).fold(
err => Left(CannotConvert(str, "Uri", err.sanitized)),
uri => Right(uri)))
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package pureconfig.modules.http4s

import pureconfig.syntax._
import com.typesafe.config.ConfigFactory
import org.http4s.Uri
import pureconfig.BaseSuite
import pureconfig.error.{ CannotConvert, ConfigReaderFailures, ConvertFailure }
import pureconfig.syntax._

class Http4sTest extends BaseSuite {

Expand All @@ -12,6 +13,14 @@ class Http4sTest extends BaseSuite {
"reading the uri config" should "parse the uri" in {
val conf = ConfigFactory.parseString(s"""{uri:"http://http4s.org/"}""")

conf.to[ServerConfig].right.value shouldEqual ServerConfig(Uri(path = "http://http4s.org/"))
conf.to[ServerConfig].right.value shouldEqual ServerConfig(Uri.unsafeFromString("http://http4s.org/"))
}

"reading the uri config" should "get a CannotConvert error" in {
val conf = ConfigFactory.parseString(s"""{uri:"\\\\"}""")

val errors = ConfigReaderFailures(ConvertFailure(CannotConvert("\\", "Uri", "Invalid URI"), None, "uri"))

conf.to[ServerConfig].left.value shouldEqual errors
}
}

0 comments on commit bb0f3fd

Please sign in to comment.