mirror of
https://github.com/lightbend/config.git
synced 2025-02-19 07:40:31 +08:00
add a test-lib and use it to test resource loading behavior
This commit is contained in:
parent
70fad92b50
commit
7e22880cd0
@ -386,4 +386,20 @@ class PublicApiTest extends TestUtils {
|
||||
assertEquals("A", fromResources.getString("fromJsonA"))
|
||||
assertEquals("true", fromResources.getString("fromProps.bool"))
|
||||
}
|
||||
|
||||
@Test
|
||||
def resourceFromAnotherClasspath() {
|
||||
val conf = ConfigFactory.parseResource(classOf[PublicApiTest], "/test-lib.conf", ConfigParseOptions.defaults())
|
||||
|
||||
assertEquals("This is to test classpath searches.", conf.getString("test-lib.description"))
|
||||
}
|
||||
|
||||
@Test
|
||||
def onlyFirstResourceUsed() {
|
||||
val conf = ConfigFactory.parseResource(classOf[PublicApiTest], "/test01.conf", ConfigParseOptions.defaults())
|
||||
|
||||
assertEquals(42, conf.getInt("ints.fortyTwo"))
|
||||
assertFalse(conf.hasPath("test-lib"))
|
||||
assertFalse(conf.hasPath("test-lib.fromTestLib"))
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,11 @@ import Keys._
|
||||
|
||||
object ConfigBuild extends Build {
|
||||
lazy val root = Project(id = "root",
|
||||
base = file(".")) aggregate(configLib)
|
||||
base = file(".")) aggregate(testLib, configLib)
|
||||
|
||||
lazy val configLib = Project(id = "config",
|
||||
base = file("config"))
|
||||
base = file("config")) dependsOn(testLib % "test->test")
|
||||
|
||||
lazy val testLib = Project(id = "test-lib",
|
||||
base = file("test-lib"))
|
||||
}
|
||||
|
9
test-lib/build.sbt
Normal file
9
test-lib/build.sbt
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
// no binary
|
||||
publishArtifact in (Compile, packageBin) := false
|
||||
|
||||
// no javadoc
|
||||
publishArtifact in (Compile, packageDoc) := false
|
||||
|
||||
// no source
|
||||
publishArtifact in (Compile, packageSrc) := false
|
7
test-lib/src/test/resources/test-lib.conf
Normal file
7
test-lib/src/test/resources/test-lib.conf
Normal file
@ -0,0 +1,7 @@
|
||||
# don't copy anything about how this is done; look at the
|
||||
# examples/ directory and the docs for things that should be
|
||||
# copied. this is weird test suite stuff.
|
||||
|
||||
test-lib {
|
||||
description = This is to test classpath searches.
|
||||
}
|
11
test-lib/src/test/resources/test01.conf
Normal file
11
test-lib/src/test/resources/test01.conf
Normal file
@ -0,0 +1,11 @@
|
||||
# don't copy anything about how this is done; look at the
|
||||
# examples/ directory and the docs for things that should be
|
||||
# copied. this is weird test suite stuff.
|
||||
|
||||
## Here we are testing that this file test01.conf is NOT seen
|
||||
## since there's another resource with that name earlier in
|
||||
## classpath
|
||||
test-lib {
|
||||
fromTestLib = true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user