diff --git a/http4s/src/main/resources/reference.conf b/http4s/src/main/resources/reference.conf index b4c83f3f9..e6acbc7ef 100644 --- a/http4s/src/main/resources/reference.conf +++ b/http4s/src/main/resources/reference.conf @@ -1,4 +1,4 @@ -collector { +{ paths {} p3p { diff --git a/http4s/src/test/resources/test-config.hocon b/http4s/src/test/resources/test-config.hocon new file mode 100644 index 000000000..71202d62f --- /dev/null +++ b/http4s/src/test/resources/test-config.hocon @@ -0,0 +1,18 @@ +collector { + interface = "0.0.0.0" + port = 8080 + + streams { + good = "good" + bad = "bad" + + sink { + foo = "hello" + bar = "world" + } + } + + ssl { + enable = true + } +} diff --git a/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParserSpec.scala b/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParserSpec.scala new file mode 100644 index 000000000..8106ab345 --- /dev/null +++ b/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParserSpec.scala @@ -0,0 +1,40 @@ +package com.snowplowanalytics.snowplow.collector.core + +import java.nio.file.Paths + +import org.specs2.mutable.Specification + +import cats.effect.IO + +import cats.effect.testing.specs2.CatsEffect + +import io.circe.generic.semiauto._ + +class ConfigParserSpec extends Specification with CatsEffect { + + "Loading the configuration" should { + "use reference.conf and the hocon specified in the path" in { + case class SinkConfig(foo: String, bar: String) + implicit val decoder = deriveDecoder[SinkConfig] + + val path = Paths.get(getClass.getResource(("/test-config.hocon")).toURI()) + + val expectedStreams = Config.Streams[SinkConfig]( + "good", + "bad", + TestUtils.testConfig.streams.useIpAddressAsPartitionKey, + SinkConfig("hello", "world"), + TestUtils.testConfig.streams.buffer + ) + val expected = TestUtils + .testConfig + .copy[SinkConfig]( + paths = Map.empty[String, String], + streams = expectedStreams, + ssl = TestUtils.testConfig.ssl.copy(enable = true) + ) + + ConfigParser.fromPath[IO, SinkConfig](Some(path)).value.map(_ should beRight(expected)) + } + } +} diff --git a/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/TestUtils.scala b/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/TestUtils.scala index 334229b0c..3937b2580 100644 --- a/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/TestUtils.scala +++ b/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/TestUtils.scala @@ -102,6 +102,6 @@ object TestUtils { ), enableDefaultRedirect = false, redirectDomains = Set.empty[String], - preTerminationPeriod = 5.minutes + preTerminationPeriod = 10.seconds ) }