Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ningyougang committed Aug 12, 2020
1 parent 37f979b commit 60334a2
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/src/test/scala/common/WskCliOperations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class CliActionOperations(override val wsk: RunCliCmd)
docker: Option[String] = None,
parameters: Map[String, JsValue] = Map.empty,
annotations: Map[String, JsValue] = Map.empty,
delAnnotations: Array[String] = Array(),
parameterFile: Option[String] = None,
annotationFile: Option[String] = None,
timeout: Option[Duration] = None,
Expand Down Expand Up @@ -229,6 +230,10 @@ class CliActionOperations(override val wsk: RunCliCmd)
annotations flatMap { p =>
Seq("-a", p._1, p._2.compactPrint)
}
} ++ {
delAnnotations flatMap { p =>
Seq("--del-annotation", p)
}
} ++ {
parameterFile map { pf =>
Seq("-P", pf)
Expand Down
1 change: 1 addition & 0 deletions tests/src/test/scala/common/WskOperations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ trait ActionOperations extends DeleteFromCollectionOperations with ListOrGetFrom
docker: Option[String] = None,
parameters: Map[String, JsValue] = Map.empty,
annotations: Map[String, JsValue] = Map.empty,
delAnnotations: Array[String] = Array(),
parameterFile: Option[String] = None,
annotationFile: Option[String] = None,
timeout: Option[Duration] = None,
Expand Down
3 changes: 3 additions & 0 deletions tests/src/test/scala/common/rest/WskRestOperations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class RestActionOperations(implicit val actorSystem: ActorSystem)
docker: Option[String] = None,
parameters: Map[String, JsValue] = Map.empty,
annotations: Map[String, JsValue] = Map.empty,
delAnnotations: Array[String] = Array(),
parameterFile: Option[String] = None,
annotationFile: Option[String] = None,
timeout: Option[Duration] = None,
Expand Down Expand Up @@ -364,6 +365,8 @@ class RestActionOperations(implicit val actorSystem: ActorSystem)
content = content + ("annotations" -> annos.toJson)
if (limits.nonEmpty)
content = content + ("limits" -> limits.toJson)
if (delAnnotations.nonEmpty)
content = content + ("delAnnotations" -> delAnnotations.toJson)
content
}

Expand Down
68 changes: 68 additions & 0 deletions tests/src/test/scala/system/basic/WskActionTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,72 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers with
}
}

it should "not delete previous annotation when update action with new annotation" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val name = "hello"

assetHelper.withCleaner(wsk.action, name) { (action, _) =>
val annotations = Map("key1" -> "value1".toJson, "key2" -> "value2".toJson)
action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), annotations = annotations)
val annotationString = wsk.parseJsonString(wsk.action.get(name).stdout).fields("annotations").toString

annotationString should include(""""key":"key1"""")
annotationString should include(""""value":"value1"""")
annotationString should include(""""key":"key2"""")
annotationString should include(""""value":"value2"""")

val newAnnotations = Map("key3" -> "value3".toJson, "key4" -> "value4".toJson)
action.create(
name,
Some(TestUtils.getTestActionFilename("hello.js")),
annotations = newAnnotations,
update = true)
val newAnnotationString = wsk.parseJsonString(wsk.action.get(name).stdout).fields("annotations").toString

newAnnotationString should include(""""key":"key1"""")
newAnnotationString should include(""""value":"value1"""")
newAnnotationString should include(""""key":"key2"""")
newAnnotationString should include(""""value":"value2"""")
newAnnotationString should include(""""key":"key3"""")
newAnnotationString should include(""""value":"value3"""")
newAnnotationString should include(""""key":"key4"""")
newAnnotationString should include(""""value":"value4"""")

action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), update = true)
}
}

it should "support to delete previous annotation when passing delAnnotations body" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val name = "hello"

assetHelper.withCleaner(wsk.action, name) { (action, _) =>
val annotations = Map("key1" -> "value1".toJson, "key2" -> "value2".toJson)
action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), annotations = annotations)
val annotationString = wsk.parseJsonString(wsk.action.get(name).stdout).fields("annotations").toString

annotationString should include(""""key":"key1"""")
annotationString should include(""""value":"value1"""")
annotationString should include(""""key":"key2"""")
annotationString should include(""""value":"value2"""")

//Delete key1 only
val delAnnotations = Array("key1")

action.create(
name,
Some(TestUtils.getTestActionFilename("hello.js")),
delAnnotations = delAnnotations,
update = true)
val newAnnotationString = wsk.parseJsonString(wsk.action.get(name).stdout).fields("annotations").toString

newAnnotationString should not include (""""key":"key1"""")
newAnnotationString should not include (""""value":"value1"""")
newAnnotationString should include(""""key":"key2"""")
newAnnotationString should include(""""value":"value2"""")

action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), update = true)
}
}

}

0 comments on commit 60334a2

Please sign in to comment.