Normalize property reading from file and consul.
diff --git a/tests/src/whisk/common/CommonTests.scala b/tests/src/whisk/common/CommonTests.scala
deleted file mode 100644
index f474957..0000000
--- a/tests/src/whisk/common/CommonTests.scala
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2015-2016 IBM Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package whisk.common
-
-import scala.concurrent.Await
-import scala.concurrent.duration._
-
-import org.junit.runner.RunWith
-import org.scalatest.FlatSpec
-import org.scalatest.Matchers
-import org.scalatest.junit.JUnitRunner
-
-import common.WskActorSystem
-import whisk.core.WhiskConfig
-
-@RunWith(classOf[JUnitRunner])
-class CommonTests extends FlatSpec with Matchers with WskActorSystem {
-
- "WhiskConfig" should "get required property" in {
- val config = new WhiskConfig(WhiskConfig.edgeHost)
- assert(config.isValid)
- assert(config.edgeHost.nonEmpty)
- }
-
- it should "get property with no value" in {
- val config = new WhiskConfig(Map(WhiskConfig.dockerRegistry -> null))
- println(s"${WhiskConfig.dockerRegistry} is: '${config.dockerRegistry}'")
- assert(config.isValid)
- }
-
- it should "read properties from consulserver" in {
- val tester = new WhiskConfig(WhiskConfig.consulServer);
- val consul = new ConsulClient(tester.consulServer)
-
- val key = "whiskprops/CONSUL_TEST_CASE"
- Await.result(consul.kv.put(key, "thiswastested"), 10.seconds)
-
- val config = new WhiskConfig(Map("consul.test.case" -> null))
-
- assert(config.isValid)
- assert(config("consul.test.case").equals("thiswastested"))
-
- consul.kv.del(key)
- }
-}
diff --git a/tests/src/whisk/common/ConfigTests.scala b/tests/src/whisk/common/ConfigTests.scala
index f352f19..0341d8c 100644
--- a/tests/src/whisk/common/ConfigTests.scala
+++ b/tests/src/whisk/common/ConfigTests.scala
@@ -30,8 +30,8 @@
}
it should "get value from environemnt" in {
- val config = new Config(Map("a" -> null))(Map("A" -> "xyz"))
- assert(config.isValid && config("a") == "xyz")
+ val config = new Config(Map("a" -> null, "b" -> ""))(Map("A" -> "xyz"))
+ assert(config.isValid && config("a") == "xyz" && config("b") == "")
}
it should "not be valid when environment does not provide value" in {
@@ -39,15 +39,32 @@
assert(!config.isValid && config("a") == null)
}
+ it should "be invalid if same property is required and optional and still not defined" in {
+ val config = new Config(Map("a" -> null), optionalProperties = Set("a"))(Map())
+ assert(!config.isValid)
+ }
+
it should "read optional value" in {
- val config = new Config(Map("a" -> "A"), Set("b", "c"))(Map("B" -> "xyz"))
- assert(config.isValid && config("a") == "A" && config("b") == "xyz" && config("c") == null)
+ val config = new Config(Map("a" -> "A", "x" -> "X"), optionalProperties = Set("b", "c", "x"))(Map("B" -> "B"))
+ assert(config.isValid)
+ assert(config("a") == "A")
+ assert(config("b") == "B")
+ assert(config("c") == "")
+ assert(config("x") == "X")
}
it should "override a value with optional value" in {
- val config = new Config(Map("a" -> null), optionalProperties = Set("b", "c"))(Map("A" -> "xyz", "B" -> "zyx"))
- assert(config.isValid && config("a") == "xyz" && config("b") == "zyx")
- assert(config("a", "b") == "zyx")
- assert(config("a", "c") == "xyz")
+ val config = new Config(Map("a" -> null, "x" -> "X"), optionalProperties = Set("b", "c", "x"))(Map("A" -> "A", "B" -> "B"))
+ assert(config.isValid && config("a") == "A" && config("b") == "B")
+ assert(config("a", "b") == "B")
+ assert(config("a", "c") == "A")
+ assert(config("c") == "")
+ assert(config("x") == "X")
+ assert(config("x", "c") == "X")
+ assert(config("x", "d") == "X")
+ assert(config("d", "x") == "X")
+ assert(config("c", "x") == "X")
+ assert(config("c", "d") == "")
}
+
}
diff --git a/tests/src/whisk/core/WhiskConfigTests.scala b/tests/src/whisk/core/WhiskConfigTests.scala
index bd8d9b1..30bf282 100644
--- a/tests/src/whisk/core/WhiskConfigTests.scala
+++ b/tests/src/whisk/core/WhiskConfigTests.scala
@@ -20,21 +20,34 @@
import java.io.File
import java.io.FileWriter
+import scala.concurrent.Await
+import scala.concurrent.duration._
+
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.Matchers
import org.scalatest.junit.JUnitRunner
+
import common.WskActorSystem
+import whisk.common.ConsulClient
@RunWith(classOf[JUnitRunner])
class WhiskConfigTests extends FlatSpec with Matchers with WskActorSystem {
+ behavior of "WhiskConfig"
+
+ it should "get required property" in {
+ val config = new WhiskConfig(WhiskConfig.edgeHost)
+ assert(config.isValid)
+ assert(config.edgeHost.nonEmpty)
+ }
+
it should "be valid when a prop file is provided defining required props" in {
val file = File.createTempFile("cxt", ".txt")
file.deleteOnExit()
val bw = new BufferedWriter(new FileWriter(file))
- bw.write("a=A")
+ bw.write("a=A\n")
bw.close()
val config = new WhiskConfig(Map("a" -> null), Set(), file)
@@ -46,10 +59,53 @@
file.deleteOnExit()
val bw = new BufferedWriter(new FileWriter(file))
- bw.write("a=A")
+ bw.write("a=A\n")
bw.close()
val config = new WhiskConfig(Map("a" -> null, "b" -> null), Set(), file)
assert(!config.isValid && config("b") == null)
}
+
+ it should "be valid when a prop file is provided defining required props and optional properties" in {
+ val file = File.createTempFile("cxt", ".txt")
+ file.deleteOnExit()
+
+ val bw = new BufferedWriter(new FileWriter(file))
+ bw.write("a=A\n")
+ bw.write("b=B\n")
+ bw.write("c=C\n")
+ bw.close()
+
+ val config = new WhiskConfig(Map("a" -> null, "b" -> "???"), Set("c", "d"), file, env = Map())
+ assert(config.isValid && config("a") == "A" && config("b") == "B")
+ assert(config("c") == "C")
+ assert(config("d") == "")
+ assert(config("a", "c") == "C")
+ assert(config("a", "d") == "A")
+ assert(config("d", "a") == "A")
+ assert(config("c", "a") == "A")
+ }
+
+ it should "get property with no value from whisk.properties file" in {
+ val config = new WhiskConfig(Map(WhiskConfig.dockerRegistry -> null))
+ println(s"${WhiskConfig.dockerRegistry} is: '${config.dockerRegistry}'")
+ assert(config.isValid)
+ }
+
+ it should "read properties from consulserver" in {
+ val tester = new WhiskConfig(WhiskConfig.consulServer);
+ val consul = new ConsulClient(tester.consulServer)
+
+ val key = "whiskprops/CONSUL_TEST_CASE"
+ Await.result(consul.kv.put(key, "thiswastested"), 10.seconds)
+
+ // set optional value which will not be available in environment, it should still be read from consul
+ val config = new WhiskConfig(WhiskConfig.consulServer ++ Map("consul.test.case" -> null), Set("consul.test.case"))
+
+ assert(config.isValid)
+ assert(config("consul.test.case").equals("thiswastested"))
+
+ consul.kv.del(key)
+ }
+
}
diff --git a/tests/src/whisk/core/container/test/ContainerPoolTests.scala b/tests/src/whisk/core/container/test/ContainerPoolTests.scala
index 29ed535..81be9c0 100644
--- a/tests/src/whisk/core/container/test/ContainerPoolTests.scala
+++ b/tests/src/whisk/core/container/test/ContainerPoolTests.scala
@@ -46,7 +46,6 @@
import common.WskActorSystem
-
/**
* Unit tests for ContainerPool and, by association, Container and WhiskContainer.
*
@@ -60,13 +59,15 @@
implicit val transid = TransactionId.testing
val config = new WhiskConfig(
+ WhiskEntityStore.requiredProperties ++
+ WhiskAuthStore.requiredProperties ++
+ ContainerPool.requiredProperties ++
Map(selfDockerEndpoint -> "localhost",
dockerEndpoint -> null,
edgeHostName -> "localhost",
invokerSerializeDockerOp -> "true",
- invokerSerializeDockerPull -> "true")
- ++ WhiskEntityStore.requiredProperties
- ++ WhiskAuthStore.requiredProperties)
+ invokerSerializeDockerPull -> "true"))
+
assert(config.isValid)
val pool = new ContainerPool(config, 0, InfoLevel, true, true)
diff --git a/tests/src/whisk/core/controller/test/ControllerTestCommon.scala b/tests/src/whisk/core/controller/test/ControllerTestCommon.scala
index af6b8fb..0e5a360 100644
--- a/tests/src/whisk/core/controller/test/ControllerTestCommon.scala
+++ b/tests/src/whisk/core/controller/test/ControllerTestCommon.scala
@@ -59,7 +59,7 @@
implicit val actorSystem = system // defined in ScalatestRouteTest
val executionContext = actorSystem.dispatcher
- override val whiskConfig = new WhiskConfig(WhiskActionsApi.requiredProperties)
+ override val whiskConfig = new WhiskConfig(WhiskAuthStore.requiredProperties ++ WhiskActionsApi.requiredProperties)
assert(whiskConfig.isValid)
override val loadBalancer = new DegenerateLoadBalancerService(whiskConfig, InfoLevel)
diff --git a/tests/src/whisk/core/entity/test/DatastoreTests.scala b/tests/src/whisk/core/entity/test/DatastoreTests.scala
index 7d6f498..7527b2c 100644
--- a/tests/src/whisk/core/entity/test/DatastoreTests.scala
+++ b/tests/src/whisk/core/entity/test/DatastoreTests.scala
@@ -44,7 +44,7 @@
with DbUtils {
val namespace = EntityPath("test namespace")
- val config = new WhiskConfig(WhiskEntityStore.requiredProperties)
+ val config = new WhiskConfig(WhiskAuthStore.requiredProperties ++ WhiskEntityStore.requiredProperties)
val datastore = WhiskEntityStore.datastore(config)
val authstore = WhiskAuthStore.datastore(config)
datastore.setVerbosity(InfoLevel)