@@ -66,7 +66,7 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
6666 // Some action invocation environments will not have an api key; so allow this check to be conditionally skipped
6767 val apiKeyCheck = true
6868
69- val requireAPIKeyAnnotation = WhiskProperties .getBooleanProperty(" whisk.feature.requireApiKeyAnnotation" , true );
69+ val requireAPIKeyAnnotation = WhiskProperties .getBooleanProperty(" whisk.feature.requireApiKeyAnnotation" , true )
7070
7171 behavior of " Wsk CLI usage"
7272
@@ -653,37 +653,43 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
653653 val createAnnots = Map (createKey -> createValue, origKey -> origValue)
654654 val updateAnnots =
655655 Map (updateKey -> updateValue, origKey -> overwrittenValue)
656+ val baseAnnotations =
657+ Parameters (" web-export" , JsTrue ) ++
658+ Parameters (" raw-http" , JsFalse ) ++
659+ Parameters (" final" , JsTrue ) ++
660+ Parameters (" exec" , " nodejs:6" )
661+ val createAnnotations = if (requireAPIKeyAnnotation) {
662+ baseAnnotations ++
663+ Parameters (WhiskAction .provideApiKeyAnnotationName, JsFalse ) ++
664+ Parameters (createKey, createValue) ++
665+ Parameters (origKey, origValue)
666+ } else {
667+ baseAnnotations ++
668+ Parameters (createKey, createValue) ++
669+ Parameters (origKey, origValue)
670+ }
671+ val updateAnnotations = baseAnnotations ++ Parameters (updateKey, updateValue) ++ Parameters (
672+ origKey,
673+ overwrittenValue)
656674
657675 assetHelper.withCleaner(wsk.action, name) { (action, _) =>
658676 action.create(name, file, annotations = createAnnots)
659677 }
660678
661679 wsk.action.create(name, file, web = Some (" true" ), update = true )
662680
663- val existinAnnots =
664- wsk.action.get(name, fieldFilter = Some (" annotations" )).stdout
665- assert(existinAnnots.startsWith(s " ok: got action $name, displaying field annotations \n " ))
666- removeCLIHeader(existinAnnots).parseJson shouldBe JsArray (
667- JsObject (" key" -> JsString (" web-export" ), " value" -> JsBoolean (true )),
668- JsObject (" key" -> JsString (origKey), " value" -> origValue),
669- JsObject (" key" -> JsString (" raw-http" ), " value" -> JsBoolean (false )),
670- JsObject (" key" -> JsString (" final" ), " value" -> JsBoolean (true )),
671- JsObject (" key" -> JsString (createKey), " value" -> createValue),
672- JsObject (" key" -> JsString (WhiskAction .provideApiKeyAnnotationName), " value" -> JsBoolean (false )),
673- JsObject (" key" -> JsString (" exec" ), " value" -> JsString (" nodejs:6" )))
681+ val existingAnnots = wsk.action.get(name, fieldFilter = Some (" annotations" )).stdout
682+ assert(existingAnnots.startsWith(s " ok: got action $name, displaying field annotations \n " ))
683+ removeCLIHeader(existingAnnots).parseJson.convertTo[Set [JsObject ]] shouldBe createAnnotations.toJsArray
684+ .convertTo[Set [JsObject ]]
674685
675686 wsk.action.create(name, file, web = Some (" true" ), update = true , annotations = updateAnnots)
676687
677688 val updatedAnnots =
678689 wsk.action.get(name, fieldFilter = Some (" annotations" )).stdout
679690 assert(updatedAnnots.startsWith(s " ok: got action $name, displaying field annotations \n " ))
680- removeCLIHeader(updatedAnnots).parseJson shouldBe JsArray (
681- JsObject (" key" -> JsString (" web-export" ), " value" -> JsBoolean (true )),
682- JsObject (" key" -> JsString (origKey), " value" -> overwrittenValue),
683- JsObject (" key" -> JsString (updateKey), " value" -> updateValue),
684- JsObject (" key" -> JsString (" raw-http" ), " value" -> JsBoolean (false )),
685- JsObject (" key" -> JsString (" final" ), " value" -> JsBoolean (true )),
686- JsObject (" key" -> JsString (" exec" ), " value" -> JsString (" nodejs:6" )))
691+ removeCLIHeader(updatedAnnots).parseJson.convertTo[Set [JsObject ]] shouldBe updateAnnotations.toJsArray
692+ .convertTo[Set [JsObject ]]
687693 }
688694
689695 it should " ensure action update creates an action with --web flag" in withAssetCleaner(wskprops) {
@@ -696,24 +702,22 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
696702 }
697703
698704 val baseAnnotations =
699- Parameters (" web-export" , JsBoolean (true )) ++
700- Parameters (" raw-http" , JsBoolean (false )) ++
701- Parameters (" final" , JsBoolean (true ))
705+ Parameters (" web-export" , JsTrue ) ++
706+ Parameters (" raw-http" , JsFalse ) ++
707+ Parameters (" final" , JsTrue ) ++
708+ Parameters (" exec" , " nodejs:6" )
702709
703710 val testAnnotations = if (requireAPIKeyAnnotation) {
704711 baseAnnotations ++
705- Parameters (WhiskAction .provideApiKeyAnnotationName, JsBoolean (false )) ++
706- Parameters (" exec" , " nodejs:6" )
712+ Parameters (WhiskAction .provideApiKeyAnnotationName, JsFalse )
707713 } else {
708- baseAnnotations ++
709- Parameters (" exec" , " nodejs:6" )
714+ baseAnnotations
710715 }
711716
712717 val action = wsk.action.get(name)
713718 removeCLIHeader(action.stdout).parseJson.asJsObject
714719 .fields(" annotations" )
715- .convertTo[Set [JsObject ]] shouldBe testAnnotations.toJsArray
716- .convertTo[Set [JsObject ]]
720+ .convertTo[Set [JsObject ]] shouldBe testAnnotations.toJsArray.convertTo[Set [JsObject ]]
717721 }
718722
719723 it should " reject action create and update with invalid --web flag input" in withAssetCleaner(wskprops) {
@@ -864,7 +868,6 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
864868 var stdout = wsk.action.get(name, fieldFilter = Some (" annotations" )).stdout
865869 var existingAnnotations =
866870 removeCLIHeader(stdout).parseJson.convertTo[JsArray ].elements
867- println(" existingAnnotations: " + existingAnnotations)
868871 existingAnnotations.contains(JsObject (" key" -> JsString (" exec" ), " value" -> JsString (" nodejs:6" ))) shouldBe true
869872 existingAnnotations.contains(JsObject (" key" -> JsString (" web-export" ), " value" -> JsBoolean (true ))) shouldBe true
870873 existingAnnotations.contains(JsObject (" key" -> JsString (" raw-http" ), " value" -> JsBoolean (false ))) shouldBe true
@@ -877,7 +880,6 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
877880 stdout = wsk.action.get(name, fieldFilter = Some (" annotations" )).stdout
878881 var updatedAnnotations =
879882 removeCLIHeader(stdout).parseJson.convertTo[JsArray ].elements
880- println(" updatedAnnotations: " + updatedAnnotations)
881883 updatedAnnotations.contains(JsObject (" key" -> JsString (" exec" ), " value" -> JsString (" nodejs:6" ))) shouldBe true
882884 updatedAnnotations.contains(JsObject (" key" -> JsString (" web-export" ), " value" -> JsBoolean (true ))) shouldBe true
883885 updatedAnnotations.contains(JsObject (" key" -> JsString (" raw-http" ), " value" -> JsBoolean (false ))) shouldBe true
@@ -1183,6 +1185,59 @@ class WskCliBasicUsageTests extends TestHelpers with WskTestHelpers {
11831185 .stderr should include(" Cannot save action sequences" )
11841186 }
11851187
1188+ it should " create an action, and get its individual fields" in withAssetCleaner(wskprops) {
1189+ val name = " actionFields"
1190+ val paramInput = Map (" payload" -> " test" .toJson)
1191+ val successMsg = s " ok: got action $name, displaying field "
1192+ val requireAPIKeyAnnotation = WhiskProperties .getBooleanProperty(" whisk.feature.requireApiKeyAnnotation" , true )
1193+ val expectedParam = JsObject (" payload" -> JsString (" test" ))
1194+ val ns = wsk.namespace.whois()
1195+ val expectedExec = JsObject (" kind" -> " nodejs:6" .toJson, " binary" -> JsFalse )
1196+ val expectedParams = Parameters (" payload" , " test" )
1197+ val baseAnnotations =
1198+ Parameters (" exec" , " nodejs:6" )
1199+ val expectedAnnots = if (requireAPIKeyAnnotation) {
1200+ baseAnnotations ++
1201+ Parameters (WhiskAction .provideApiKeyAnnotationName, JsFalse )
1202+ } else {
1203+ baseAnnotations
1204+ }
1205+ val expectedLimits =
1206+ JsObject (" timeout" -> 60000 .toJson, " memory" -> 256 .toJson, " logs" -> 10 .toJson, " concurrency" -> 1 .toJson)
1207+
1208+ (wp, assetHelper) =>
1209+ assetHelper.withCleaner(wsk.action, name) { (action, _) =>
1210+ action.create(name, defaultAction, parameters = paramInput)
1211+ }
1212+
1213+ wsk.action.get(name, fieldFilter = Some (" name" )).stdout should include(s """ $successMsg name\n" $name" """ )
1214+ wsk.action.get(name, fieldFilter = Some (" version" )).stdout should include(s """ $successMsg version\n"0.0.1" """ )
1215+ wsk.action
1216+ .get(name, fieldFilter = Some (" namespace" ))
1217+ .stdout should include regex (s """ (?i) $successMsg namespace\n" $ns" """ )
1218+ wsk.action.get(name, fieldFilter = Some (" invalid" ), expectedExitCode = MISUSE_EXIT ).stderr should include(
1219+ " error: Invalid field filter 'invalid'." )
1220+ wsk.action.get(name, fieldFilter = Some (" publish" )).stdout should include(s " $successMsg publish \n false " )
1221+
1222+ val exec = wsk.action.get(name, fieldFilter = Some (" exec" )).stdout
1223+ assert(exec.startsWith(s " $successMsg exec " ))
1224+ removeCLIHeader(exec).parseJson.asJsObject shouldBe expectedExec
1225+
1226+ val params = wsk.action.get(name, fieldFilter = Some (" parameters" )).stdout
1227+ assert(params.startsWith(s " $successMsg parameters " ))
1228+ removeCLIHeader(params).parseJson.convertTo[Set [JsObject ]] shouldBe expectedParams.toJsArray
1229+ .convertTo[Set [JsObject ]]
1230+
1231+ val annots = wsk.action.get(name, fieldFilter = Some (" annotations" )).stdout
1232+ assert(annots.startsWith(s " $successMsg annotations " ))
1233+ removeCLIHeader(annots).parseJson.convertTo[Set [JsObject ]] shouldBe expectedAnnots.toJsArray
1234+ .convertTo[Set [JsObject ]]
1235+
1236+ val limits = wsk.action.get(name, fieldFilter = Some (" limits" )).stdout
1237+ assert(limits.startsWith(s " $successMsg limits " ))
1238+ removeCLIHeader(limits).parseJson.asJsObject shouldBe expectedLimits
1239+ }
1240+
11861241 behavior of " Wsk packages"
11871242
11881243 it should " create, and delete a package" in {
0 commit comments