Skip to content

Commit

Permalink
adapt tests for provide-api-key annotation upstream (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskubik authored and rabbah committed Apr 11, 2019
1 parent 67fcbc1 commit 8861d4b
Showing 1 changed file with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
// Some action invocation environments will not have an api key; so allow this check to be conditionally skipped
val apiKeyCheck = true

val requireAPIKeyAnnotation = WhiskProperties.getBooleanProperty("whisk.feature.requireApiKeyAnnotation", true);

behavior of "Wsk CLI usage"

it should "show help and usage info" in {
Expand Down Expand Up @@ -620,15 +622,20 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {

wsk.action.create(name, file, web = Some(flag), update = true)

val stdout =
wsk.action.get(name, fieldFilter = Some("annotations")).stdout
assert(stdout.startsWith(s"ok: got action $name, displaying field annotations\n"))
removeCLIHeader(stdout).parseJson shouldBe JsArray(
JsObject("key" -> JsString("web-export"), "value" -> JsBoolean(webEnabled || rawEnabled)),
JsObject("key" -> JsString("raw-http"), "value" -> JsBoolean(rawEnabled)),
JsObject("key" -> JsString("final"), "value" -> JsBoolean(webEnabled || rawEnabled)),
JsObject("key" -> JsString(WhiskAction.provideApiKeyAnnotationName), "value" -> JsBoolean(false)),
JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
val action = wsk.action.get(name)

val baseAnnotations = Parameters("web-export", JsBoolean(webEnabled || rawEnabled)) ++
Parameters("raw-http", JsBoolean(rawEnabled)) ++
Parameters("final", JsBoolean(webEnabled || rawEnabled)) ++
Parameters("exec", "nodejs:6")
val testAnnotations = if (requireAPIKeyAnnotation) {
baseAnnotations ++ Parameters(WhiskAction.provideApiKeyAnnotationName, JsFalse)
} else baseAnnotations

removeCLIHeader(action.stdout).parseJson.asJsObject
.fields("annotations")
.convertTo[Set[JsObject]] shouldBe testAnnotations.toJsArray
.convertTo[Set[JsObject]]
}
}

Expand Down Expand Up @@ -688,14 +695,25 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
action.create(name, file, web = Some("true"), update = true)
}

val stdout = wsk.action.get(name, fieldFilter = Some("annotations")).stdout
assert(stdout.startsWith(s"ok: got action $name, displaying field annotations\n"))
removeCLIHeader(stdout).parseJson shouldBe JsArray(
JsObject("key" -> JsString("web-export"), "value" -> JsBoolean(true)),
JsObject("key" -> JsString("raw-http"), "value" -> JsBoolean(false)),
JsObject("key" -> JsString("final"), "value" -> JsBoolean(true)),
JsObject("key" -> JsString(WhiskAction.provideApiKeyAnnotationName), "value" -> JsBoolean(false)),
JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
val baseAnnotations =
Parameters("web-export", JsBoolean(true)) ++
Parameters("raw-http", JsBoolean(false)) ++
Parameters("final", JsBoolean(true))

val testAnnotations = if (requireAPIKeyAnnotation) {
baseAnnotations ++
Parameters(WhiskAction.provideApiKeyAnnotationName, JsBoolean(false)) ++
Parameters("exec", "nodejs:6")
} else {
baseAnnotations ++
Parameters("exec", "nodejs:6")
}

val action = wsk.action.get(name)
removeCLIHeader(action.stdout).parseJson.asJsObject
.fields("annotations")
.convertTo[Set[JsObject]] shouldBe testAnnotations.toJsArray
.convertTo[Set[JsObject]]
}

it should "reject action create and update with invalid --web flag input" in withAssetCleaner(wskprops) {
Expand Down

0 comments on commit 8861d4b

Please sign in to comment.