From c802bd5fa00e90766d6f927bbe350a25a22a4e91 Mon Sep 17 00:00:00 2001 From: amanjpro Date: Wed, 26 Aug 2020 18:00:44 -0400 Subject: [PATCH] Add tupled method to convert EnvVar to Pair of Strings --- src/main/scala/models/EnvVar.scala | 11 +++++++---- src/test/scala/models/EnvVarSpec.scala | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/scala/models/EnvVar.scala b/src/main/scala/models/EnvVar.scala index 1fe771f..8511da9 100644 --- a/src/main/scala/models/EnvVar.scala +++ b/src/main/scala/models/EnvVar.scala @@ -7,6 +7,7 @@ sealed trait EnvVar { type T <: AnyRef def name: String def value: T + def tupled: (String, String) } object EnvVar { private[this] val pattern = """secure\((.*)\)""".r @@ -33,11 +34,12 @@ object EnvVar { } } -case class SecureEnvVar private(name: String, value: Seq[Char]) extends EnvVar { +private[models] case class SecureEnvVar(name: String, value: Seq[Char]) extends EnvVar { type T = Seq[Char] + def tupled: (String, String) = (name, value.mkString("")) } -object SecureEnvVar { +private[models] object SecureEnvVar { val HIDDEN_PASSWORD = "****" implicit val secureEnvVarEncoder: Encoder[SecureEnvVar] = new Encoder[SecureEnvVar] { @@ -60,10 +62,11 @@ object SecureEnvVar { } } -case class PlainEnvVar private(name: String, value: String) extends EnvVar { +private[models] case class PlainEnvVar(name: String, value: String) extends EnvVar { type T = String + def tupled: (String, String) = (name, value) } -object PlainEnvVar { +private[models] object PlainEnvVar { implicit val plainEnvVarEncoder: Encoder[PlainEnvVar] = new Encoder[PlainEnvVar] { final def apply(v: PlainEnvVar): Json = Json.obj( diff --git a/src/test/scala/models/EnvVarSpec.scala b/src/test/scala/models/EnvVarSpec.scala index 977b5b7..d92a87c 100644 --- a/src/test/scala/models/EnvVarSpec.scala +++ b/src/test/scala/models/EnvVarSpec.scala @@ -27,5 +27,22 @@ class EnvVarSpec() extends Matchers with AnyWordSpecLike { } } + "EnvVar.tupled" must { + "work for secure variables" in { + val (name, value) = ("username", "secure(Homa)") + val origin = EnvVar(name, value) + val expected = (name, "Homa") + val actual = origin.tupled + actual shouldBe expected + } + + "work for plain variables" in { + val (name, value) = ("username", "Homa") + val origin = EnvVar(name, value) + val expected = (name, value) + val actual = origin.tupled + actual shouldBe expected + } + } }