From 1172ba3a6c8367fc61d7c0610997ce0c22f6afc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20L=C3=B6vgren?= Date: Sat, 16 Jun 2018 12:11:03 +0100 Subject: [PATCH] Add ConfigEntry#toStringWithValues --- .../shared/src/main/scala/ciris/ConfigEntry.scala | 13 ++++++++++++- .../src/test/scala/ciris/ConfigEntrySpec.scala | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/core/shared/src/main/scala/ciris/ConfigEntry.scala b/modules/core/shared/src/main/scala/ciris/ConfigEntry.scala index 03943034..e0f3d397 100644 --- a/modules/core/shared/src/main/scala/ciris/ConfigEntry.scala +++ b/modules/core/shared/src/main/scala/ciris/ConfigEntry.scala @@ -173,7 +173,18 @@ final class ConfigEntry[F[_]: Apply, K, S, V] private ( def transformF[G[_]: Apply](implicit f: F ~> G): ConfigEntry[G, K, S, V] = new ConfigEntry(key, keyType, f(sourceValue), f(value)) - override def toString: String = { + override def toString: String = + s"ConfigEntry($key, $keyType)" + + /** + * Returns a [[String]] representation of this [[ConfigEntry]] + * including both the source value and value. If the values + * include potentially sensitive details, be careful to + * not include them in log output. + * + * @return a [[String]] representation with values + */ + def toStringWithValues: String = { val sourceValueString = sourceValue.toString val valueString = value.toString diff --git a/tests/shared/src/test/scala/ciris/ConfigEntrySpec.scala b/tests/shared/src/test/scala/ciris/ConfigEntrySpec.scala index 8143cde6..a9a906a2 100644 --- a/tests/shared/src/test/scala/ciris/ConfigEntrySpec.scala +++ b/tests/shared/src/test/scala/ciris/ConfigEntrySpec.scala @@ -4,10 +4,19 @@ import ciris.api._ final class ConfigEntrySpec extends PropertySpec { "ConfigEntry" when { - "converting to String" should { - "include the key, keyType, and value" in { + "using toString" should { + "include the key and keyType" in { forAll { value: String => existingEntry(value).toString shouldBe + s"ConfigEntry(key, ConfigKeyType(test key))" + } + } + } + + "using toStringWithValues" should { + "include the key, keyType, and value" in { + forAll { value: String => + existingEntry(value).toStringWithValues shouldBe s"ConfigEntry(key, ConfigKeyType(test key), Right($value))" } } @@ -16,7 +25,7 @@ final class ConfigEntrySpec extends PropertySpec { forAll { value: String => existingEntry(value) .mapValue(_ + "2") - .toString shouldBe { + .toStringWithValues shouldBe { s"ConfigEntry(key, ConfigKeyType(test key), Right($value), Right(${value}2))" } }