Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

fixed SysPropsResource prefix config values #42

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/src/main/scala/knobs/Pattern.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
//: ----------------------------------------------------------------------------
package knobs

import scalaz.std.string._
import scalaz.syntax.equal._

/**
* A pattern that matches a `Name` either exactly or as a prefix.
*/
Expand All @@ -25,8 +28,8 @@ sealed trait Pattern {
case Prefix(s) => Prefix(pfx ++ s)
}
final def matches(n: Name): Boolean = this match {
case Exact(s) => s == n
case Prefix(s) => n startsWith n
case Exact(s) => s === n
case Prefix(s) => n startsWith s
}
}

Expand Down
14 changes: 14 additions & 0 deletions core/src/test/scala/knobs/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ object Test extends Properties("Knobs") {
cfg.lookup[String]("path.separator").map(_.isDefined)
}

lazy val propertiesSubconfigTest: Task[Prop] =
withLoad(List(Required(SysPropsResource(Prefix("user"))))) { cfg =>
cfg.subconfig("user").lookup[String]("name").map(_.isDefined)
}

lazy val propertiesNegativeTest: Task[Prop] =
withLoad(List(Required(SysPropsResource(Prefix("user"))))) { cfg =>
cfg.lookup[String]("path.separator").map(_.isEmpty)
}

lazy val fallbackTest: Task[Prop] =
withLoad(List(Required(
ClassPathResource("foobar.cfg") or
Expand Down Expand Up @@ -122,6 +132,10 @@ object Test extends Properties("Knobs") {

property("load-system-properties") = loadPropertiesTest.unsafePerformSync

property("system-properties-negative") = propertiesNegativeTest.unsafePerformSync

property("system-properties-subconfig") = propertiesSubconfigTest.unsafePerformSync

property("load-fallback-chain") = fallbackTest.unsafePerformSync

property("fallback-chain-errors") = fallbackErrorTest.unsafePerformSync
Expand Down