diff --git a/src/main/resources/collector-micro.conf b/src/main/resources/collector-micro.conf index 28aa7c2..ec1020b 100644 --- a/src/main/resources/collector-micro.conf +++ b/src/main/resources/collector-micro.conf @@ -5,6 +5,9 @@ collector { } interface = "0.0.0.0" port = 9090 + ssl { + port = 9543 + } streams { good = "good" diff --git a/src/main/scala/com.snowplowanalytics.snowplow.micro/Configuration.scala b/src/main/scala/com.snowplowanalytics.snowplow.micro/Configuration.scala index 8d12606..c46991f 100644 --- a/src/main/scala/com.snowplowanalytics.snowplow.micro/Configuration.scala +++ b/src/main/scala/com.snowplowanalytics.snowplow.micro/Configuration.scala @@ -76,7 +76,7 @@ object Configuration { } } - def loadCollectorConfig(path: Option[Path]): EitherT[IO, String, CollectorConfig[SinkConfig]] = { + private def loadCollectorConfig(path: Option[Path]): EitherT[IO, String, CollectorConfig[SinkConfig]] = { val resolveOrder = (config: TypesafeConfig) => namespaced(ConfigFactory.load(namespaced(config.withFallback(namespaced(ConfigFactory.parseResources("collector-micro.conf")))))) @@ -84,7 +84,7 @@ object Configuration { .map(adjustSslConfig) } - def loadIgluResources(path: Option[Path]): EitherT[IO, String, IgluResources] = { + private def loadIgluResources(path: Option[Path]): EitherT[IO, String, IgluResources] = { val resolveOrder = (config: TypesafeConfig) => config.withFallback(ConfigFactory.parseResources("default-iglu-resolver.conf")) @@ -92,7 +92,7 @@ object Configuration { .flatMap(buildIgluResources) } - def loadEnrichmentConfig(igluClient: IgluCirceClient[IO]): EitherT[IO, String, List[EnrichmentConf]] = { + private def loadEnrichmentConfig(igluClient: IgluCirceClient[IO]): EitherT[IO, String, List[EnrichmentConf]] = { Option(getClass.getResource("/enrichments")) match { case Some(definedEnrichments) => val path = Paths.get(definedEnrichments.toURI) @@ -135,11 +135,12 @@ object Configuration { } private def buildJSConfig(script: FS2Path): IO[EnrichmentConf.JavascriptScriptConf] = { + val schemaKey = SchemaKey("com.snowplowanalytics.snowplow", "javascript_script_config", "jsonschema", SchemaVer.Full(1, 0, 0)) Files[IO] .readUtf8Lines(script) .compile .toList - .map(lines => EnrichmentConf.JavascriptScriptConf(null, lines.mkString("\n"))) + .map(lines => EnrichmentConf.JavascriptScriptConf(schemaKey, lines.mkString("\n"))) } private def listAvailableEnrichments(enrichmentsDirectory: Path, fileType: String) = { diff --git a/src/test/scala/com.snowplowanalytics.snowplow.micro/ConfigHelperSpec.scala b/src/test/scala/com.snowplowanalytics.snowplow.micro/ConfigHelperSpec.scala index a6eb260..ff511ec 100644 --- a/src/test/scala/com.snowplowanalytics.snowplow.micro/ConfigHelperSpec.scala +++ b/src/test/scala/com.snowplowanalytics.snowplow.micro/ConfigHelperSpec.scala @@ -12,16 +12,33 @@ */ package com.snowplowanalytics.snowplow.micro +import cats.effect.IO import cats.effect.testing.specs2.CatsEffect +import com.monovore.decline.Command +import com.snowplowanalytics.snowplow.micro.Configuration.MicroConfig import org.specs2.mutable.Specification class ConfigHelperSpec extends Specification with CatsEffect { - "ConfigHelper" >> { - "will produce a valid parsed collector config if `--collector-config` is not present" >> { - Configuration.loadCollectorConfig(None).value.map { - case Right(_) => ok - case Left(_) => ko - } + "Configuration loader should work when" >> { + "no custom args are provided and only defaults are used" >> { + load(args = List.empty) + .map { result => + result must beRight[MicroConfig].like { + case config => + config.collector.port must beEqualTo(9090) + config.collector.ssl.enable must beFalse + config.collector.ssl.port must beEqualTo(9543) + + config.enrichmentsConfig.isEmpty must beTrue + config.iglu.resolver.repos.map(_.config.name) must containTheSameElementsAs(List("Iglu Central", "Iglu Central - Mirror 01")) + + config.outputEnrichedTsv must beFalse + } + } } } + + private def load(args: List[String]): IO[Either[String, MicroConfig]] = { + Command("test-app", "test")(Configuration.load()).parse(args).right.get.value + } }