Skip to content

Commit

Permalink
Add ConfigEntry#toStringWithValues
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Lövgren committed Jun 16, 2018
1 parent 1603a0d commit 1172ba3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 12 additions & 1 deletion modules/core/shared/src/main/scala/ciris/ConfigEntry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 12 additions & 3 deletions tests/shared/src/test/scala/ciris/ConfigEntrySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
}
}
Expand All @@ -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))"
}
}
Expand Down

0 comments on commit 1172ba3

Please sign in to comment.