Skip to content

Commit b14628c

Browse files
committed
Add test cases
1 parent 188944c commit b14628c

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed

core/controller/src/main/resources/apiv1swagger.json

+7
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,13 @@
19101910
},
19111911
"description": "annotations on the item"
19121912
},
1913+
"delAnnotations": {
1914+
"type": "array",
1915+
"items": {
1916+
"type": "string"
1917+
},
1918+
"description": "del annotations on the item"
1919+
},
19131920
"parameters": {
19141921
"type": "array",
19151922
"items": {

tests/src/test/scala/common/WskCliOperations.scala

+5
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class CliActionOperations(override val wsk: RunCliCmd)
195195
docker: Option[String] = None,
196196
parameters: Map[String, JsValue] = Map.empty,
197197
annotations: Map[String, JsValue] = Map.empty,
198+
delAnnotations: Array[String] = Array(),
198199
parameterFile: Option[String] = None,
199200
annotationFile: Option[String] = None,
200201
timeout: Option[Duration] = None,
@@ -229,6 +230,10 @@ class CliActionOperations(override val wsk: RunCliCmd)
229230
annotations flatMap { p =>
230231
Seq("-a", p._1, p._2.compactPrint)
231232
}
233+
} ++ {
234+
delAnnotations flatMap { p =>
235+
Seq("--del-annotation", p)
236+
}
232237
} ++ {
233238
parameterFile map { pf =>
234239
Seq("-P", pf)

tests/src/test/scala/common/WskOperations.scala

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ trait ActionOperations extends DeleteFromCollectionOperations with ListOrGetFrom
234234
docker: Option[String] = None,
235235
parameters: Map[String, JsValue] = Map.empty,
236236
annotations: Map[String, JsValue] = Map.empty,
237+
delAnnotations: Array[String] = Array(),
237238
parameterFile: Option[String] = None,
238239
annotationFile: Option[String] = None,
239240
timeout: Option[Duration] = None,

tests/src/test/scala/common/rest/WskRestOperations.scala

+3
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class RestActionOperations(implicit val actorSystem: ActorSystem)
264264
docker: Option[String] = None,
265265
parameters: Map[String, JsValue] = Map.empty,
266266
annotations: Map[String, JsValue] = Map.empty,
267+
delAnnotations: Array[String] = Array(),
267268
parameterFile: Option[String] = None,
268269
annotationFile: Option[String] = None,
269270
timeout: Option[Duration] = None,
@@ -364,6 +365,8 @@ class RestActionOperations(implicit val actorSystem: ActorSystem)
364365
content = content + ("annotations" -> annos.toJson)
365366
if (limits.nonEmpty)
366367
content = content + ("limits" -> limits.toJson)
368+
if (delAnnotations.nonEmpty)
369+
content = content + ("delAnnotations" -> delAnnotations.toJson)
367370
content
368371
}
369372

tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskRestBasicUsageTests.scala

+32
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,38 @@ class WskRestBasicUsageTests extends TestHelpers with WskTestHelpers with WskAct
131131
}
132132
}
133133

134+
it should "update an action via passing delAnnotations" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
135+
val name = "hello"
136+
137+
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
138+
val annotations = Map("key1" -> "value1".toJson, "key2" -> "value2".toJson)
139+
action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), annotations = annotations)
140+
val annotationString = wsk.parseJsonString(wsk.action.get(name).stdout).fields("annotations").toString
141+
142+
annotationString should include(""""key":"key1"""")
143+
annotationString should include(""""value":"value1"""")
144+
annotationString should include(""""key":"key2"""")
145+
annotationString should include(""""value":"value2"""")
146+
147+
//Delete key1 only
148+
val delAnnotations = Array("key1")
149+
150+
action.create(
151+
name,
152+
Some(TestUtils.getTestActionFilename("hello.js")),
153+
delAnnotations = delAnnotations,
154+
update = true)
155+
val newAnnotationString = wsk.parseJsonString(wsk.action.get(name).stdout).fields("annotations").toString
156+
157+
newAnnotationString should not include (""""key":"key1"""")
158+
newAnnotationString should not include (""""value":"value1"""")
159+
newAnnotationString should include(""""key":"key2"""")
160+
newAnnotationString should include(""""value":"value2"""")
161+
162+
action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), update = true)
163+
}
164+
}
165+
134166
it should "create, and get an action to verify file parameter and annotation parsing" in withAssetCleaner(wskprops) {
135167
(wp, assetHelper) =>
136168
val name = "actionAnnotAndParamParsing"

tests/src/test/scala/system/basic/WskActionTests.scala

+35
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,39 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers with
357357
}
358358
}
359359

360+
it should "not delete previous annotation when update action with new annotation" in withAssetCleaner(wskprops) {
361+
(wp, assetHelper) =>
362+
val name = "hello"
363+
364+
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
365+
val annotations = Map("key1" -> "value1".toJson, "key2" -> "value2".toJson)
366+
action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), annotations = annotations)
367+
val annotationString = wsk.parseJsonString(wsk.action.get(name).stdout).fields("annotations").toString
368+
369+
annotationString should include(""""key":"key1"""")
370+
annotationString should include(""""value":"value1"""")
371+
annotationString should include(""""key":"key2"""")
372+
annotationString should include(""""value":"value2"""")
373+
374+
val newAnnotations = Map("key3" -> "value3".toJson, "key4" -> "value4".toJson)
375+
action.create(
376+
name,
377+
Some(TestUtils.getTestActionFilename("hello.js")),
378+
annotations = newAnnotations,
379+
update = true)
380+
val newAnnotationString = wsk.parseJsonString(wsk.action.get(name).stdout).fields("annotations").toString
381+
382+
newAnnotationString should include(""""key":"key1"""")
383+
newAnnotationString should include(""""value":"value1"""")
384+
newAnnotationString should include(""""key":"key2"""")
385+
newAnnotationString should include(""""value":"value2"""")
386+
newAnnotationString should include(""""key":"key3"""")
387+
newAnnotationString should include(""""value":"value3"""")
388+
newAnnotationString should include(""""key":"key4"""")
389+
newAnnotationString should include(""""value":"value4"""")
390+
391+
action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), update = true)
392+
}
393+
}
394+
360395
}

0 commit comments

Comments
 (0)