Skip to content

Commit

Permalink
Correct ConfigReader derivations + test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Jan 5, 2025
1 parent 9da9deb commit d20ab3d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 31 deletions.
40 changes: 20 additions & 20 deletions backend/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ val circeUtils = (project in file("circe-utils"))
val dataAccess = (project in file("dataAccess"))
.settings(Settings.common)
.settings(
scalacOptions += "-language:experimental.macros",
libraryDependencies ++= Dependencies.alleycats ++ Dependencies.cats ++ Dependencies.zio ++ Dependencies.mouse ++ Dependencies.oolong ++ Seq(
"com.beachape" %% "enumeratum" % "1.7.5",
"org.mongodb.scala" %% "mongo-scala-driver" % Versions.mongoScalaDriver cross CrossVersion.for3Use2_13,
Expand Down Expand Up @@ -55,25 +54,26 @@ val mockingbird = (project in file("mockingbird"))
Dependencies.logback
).flatten,
libraryDependencies ++= Seq(
"com.github.pureconfig" %% "pureconfig-core" % "0.17.8",
"com.lihaoyi" %% "scalatags" % "0.13.1",
"org.webjars.npm" % "swagger-ui-dist" % "3.32.5",
"eu.timepit" %% "fs2-cron-cron4s" % "0.9.0",
"com.softwaremill.sttp.client4" %% "zio" % Versions.sttp,
"com.softwaremill.sttp.client4" %% "circe" % Versions.sttp,
"org.apache.tika" % "tika-core" % "2.1.0",
"io.scalaland" %% "chimney" % "1.6.0",
"com.ironcorelabs" %% "cats-scalatest" % "4.0.0" % Test,
"com.google.code.findbugs" % "jsr305" % "3.0.2" % Optional,
"com.github.dwickern" %% "scala-nameof" % "4.0.0" % Provided,
"com.github.os72" % "protobuf-dynamic" % "1.0.1",
"com.github.geirolz" %% "advxml-core" % "2.5.1",
"com.github.geirolz" %% "advxml-xpath" % "2.5.1",
"io.github.kitlangton" %% "neotype" % "0.3.8",
"com.softwaremill.common" %% "tagging" % "2.3.5",
"org.mozilla" % "rhino" % "1.7.14",
"org.graalvm.polyglot" % "js" % "23.1.+",
"org.slf4j" % "slf4j-api" % "1.7.30" % Provided
"com.github.pureconfig" %% "pureconfig-core" % "0.17.8",
"com.github.pureconfig" %% "pureconfig-generic-scala3" % "0.17.8",
"com.lihaoyi" %% "scalatags" % "0.13.1",
"org.webjars.npm" % "swagger-ui-dist" % "3.32.5",
"eu.timepit" %% "fs2-cron-cron4s" % "0.9.0",
"com.softwaremill.sttp.client4" %% "zio" % Versions.sttp,
"com.softwaremill.sttp.client4" %% "circe" % Versions.sttp,
"org.apache.tika" % "tika-core" % "2.1.0",
"io.scalaland" %% "chimney" % "1.6.0",
"com.ironcorelabs" %% "cats-scalatest" % "4.0.0" % Test,
"com.google.code.findbugs" % "jsr305" % "3.0.2" % Optional,
"com.github.dwickern" %% "scala-nameof" % "4.0.0" % Provided,
"com.github.os72" % "protobuf-dynamic" % "1.0.1",
"com.github.geirolz" %% "advxml-core" % "2.5.1",
"com.github.geirolz" %% "advxml-xpath" % "2.5.1",
"io.github.kitlangton" %% "neotype" % "0.3.8",
"com.softwaremill.common" %% "tagging" % "2.3.5",
"org.mozilla" % "rhino" % "1.7.14",
"org.graalvm.polyglot" % "js" % "23.1.+",
"org.slf4j" % "slf4j-api" % "1.7.30" % Provided
),
Compile / unmanagedResourceDirectories += file("../frontend/dist")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final case class BsonOptic private[optics] (private val BsonPath: Seq[Either[Int
if (validate(bson))
deferModify { case _ => v }.apply(bson)
else {
bson +: BsonPath.foldRight(v)((p, b) =>
bson :+ BsonPath.foldRight(v)((p, b) =>
p match {
case Right(f) => BsonDocument(f -> b)
case Left(i) => BsonArray.fromIterable(Seq.fill(i)(BsonNull()) :+ b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ class EnumBsonHandlerSpec extends AnyFunSpec with Matchers {
}
}

def writeTests(theWriter: BsonEncoder[Dummy]): Unit =
def writeTests(theWriter: BsonEncoder[Dummy]): Unit = {
given BsonEncoder[Dummy] = theWriter
it("should write enum values to BSONString") {
expectedWrites.foreach { case (k, v) =>
k.bson shouldBe BsonString(v)
}
}
}

describe("BSONReader") {
readTests(reader)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package ru.tinkoff.tcb.mockingbird.config

import scala.concurrent.duration.FiniteDuration

import com.github.dwickern.macros.NameOf.*
import com.typesafe.config.Config
import enumeratum.*
import pureconfig.*
import pureconfig.error.CannotConvert
import pureconfig.generic.ProductHint
import pureconfig.generic.semiauto.*

final case class JsSandboxConfig(allowedClasses: Set[String] = Set())

final case class JsSandboxConfig(allowedClasses: Set[String] = Set()) derives ConfigReader
object JsSandboxConfig {
given ProductHint[JsSandboxConfig] = ProductHint[JsSandboxConfig](ConfigFieldMapping(CamelCase, CamelCase))
given ConfigReader[JsSandboxConfig] = deriveReader
}

final case class ServerConfig(
interface: String,
Expand All @@ -17,7 +23,12 @@ final case class ServerConfig(
healthCheckRoute: Option[String],
sandbox: JsSandboxConfig = JsSandboxConfig(),
vertx: Config
) derives ConfigReader
)

object ServerConfig {
given ProductHint[ServerConfig] = ProductHint[ServerConfig](ConfigFieldMapping(CamelCase, CamelCase))
given ConfigReader[ServerConfig] = deriveReader
}

final case class SecurityConfig(secret: String) derives ConfigReader

Expand All @@ -37,7 +48,12 @@ final case class ProxyServerConfig(
nonProxy: Seq[String] = Seq(),
onlyProxy: Seq[String] = Seq(),
auth: Option[ProxyServerAuth]
) derives ConfigReader
)

object ProxyServerConfig {
given ProductHint[ProxyServerConfig] = ProductHint[ProxyServerConfig](ConfigFieldMapping(CamelCase, CamelCase))
given ConfigReader[ProxyServerConfig] = deriveReader
}

sealed trait HttpVersion extends EnumEntry
object HttpVersion extends Enum[HttpVersion] {
Expand All @@ -63,9 +79,19 @@ final case class ProxyConfig(
logOutgoingRequests: Boolean,
disableAutoDecompressForRaw: Boolean,
httpVersion: HttpVersion
) derives ConfigReader
)

final case class EventConfig(fetchInterval: FiniteDuration, reloadInterval: FiniteDuration) derives ConfigReader
object ProxyConfig {
given ProductHint[ProxyConfig] = ProductHint[ProxyConfig](ConfigFieldMapping(CamelCase, CamelCase))
given ConfigReader[ProxyConfig] = deriveReader
}

final case class EventConfig(fetchInterval: FiniteDuration, reloadInterval: FiniteDuration)

object EventConfig {
given ProductHint[EventConfig] = ProductHint[EventConfig](ConfigFieldMapping(CamelCase, CamelCase))
given ConfigReader[EventConfig] = deriveReader
}

final case class MongoConfig(uri: String, collections: MongoCollections) derives ConfigReader

Expand All @@ -79,13 +105,23 @@ final case class MongoCollections(
grpcMethodDescription: String,
source: String,
destination: String
) derives ConfigReader
)

object MongoCollections {
given ProductHint[MongoCollections] = ProductHint[MongoCollections](ConfigFieldMapping(CamelCase, CamelCase))
given ConfigReader[MongoCollections] = deriveReader
}

final case class TracingConfig(
required: List[String] = List.empty,
incomingHeaders: Map[String, String] = Map.empty,
outcomingHeaders: Map[String, String] = Map.empty,
) derives ConfigReader
)

object TracingConfig {
given ProductHint[TracingConfig] = ProductHint[TracingConfig](ConfigFieldMapping(CamelCase, CamelCase))
given ConfigReader[TracingConfig] = deriveReader
}

final case class MockingbirdConfiguration(
server: ServerConfig,
Expand Down
2 changes: 1 addition & 1 deletion backend/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object Dependencies {
"oolong-bson",
"oolong-bson-refined",
"oolong-mongo",
).map("io.github.leviysoft" %% _ % "0.4.3")
).map("io.github.leviysoft" %% _ % "0.4.4")

lazy val logback = Seq(
"logback-core",
Expand Down

0 comments on commit d20ab3d

Please sign in to comment.