You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/08/29 09:26:59 UTC

[GitHub] markusthoemmes commented on a change in pull request #3979: Treat blackbox action code as attachment

markusthoemmes commented on a change in pull request #3979: Treat blackbox action code as attachment
URL: https://github.com/apache/incubator-openwhisk/pull/3979#discussion_r213591702
 
 

 ##########
 File path: tests/src/test/scala/whisk/core/entity/test/ExecTests.scala
 ##########
 @@ -168,6 +170,132 @@ class ExecTests extends FlatSpec with Matchers with StreamLogging with BeforeAnd
     ExecManifest.initialize(config)
   }
 
+  behavior of "blackbox exec deserialization"
+
+  it should "read existing code string as attachment" in {
+    val json = """{
+                 |  "name": "action_tests_name2",
+                 |  "_id": "anon-Yzycx8QnIYDp3Tby0Fnj23KcMtH/action_tests_name2",
+                 |  "publish": false,
+                 |  "annotations": [],
+                 |  "version": "0.0.1",
+                 |  "updated": 1533623651650,
+                 |  "entityType": "action",
+                 |  "exec": {
+                 |    "kind": "blackbox",
+                 |    "image": "docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1",
+                 |    "code": "foo",
+                 |    "binary": false
+                 |  },
+                 |  "parameters": [
+                 |    {
+                 |      "key": "x",
+                 |      "value": "b"
+                 |    }
+                 |  ],
+                 |  "limits": {
+                 |    "timeout": 60000,
+                 |    "memory": 256,
+                 |    "logs": 10
+                 |  },
+                 |  "namespace": "anon-Yzycx8QnIYDp3Tby0Fnj23KcMtH"
+                 |}""".stripMargin.parseJson.asJsObject
+    val action = WhiskAction.serdes.read(json)
+    action.exec should matchPattern { case BlackBoxExec(_, Some(Inline("foo")), None, false, false) => }
+  }
+
+  it should "properly determine binary property" in {
+    val j1 = """{
+               |    "kind": "blackbox",
+               |    "image": "docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1",
+               |    "code": "SGVsbG8gT3BlbldoaXNr",
+               |    "binary": false
+               |}""".stripMargin.parseJson.asJsObject
+    Exec.serdes.read(j1) should matchPattern {
+      case BlackBoxExec(_, Some(Inline("SGVsbG8gT3BlbldoaXNr")), None, false, true) =>
+    }
+
+    val j2 = """{
+               |  "kind": "blackbox",
+               |  "image": "docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1",
+               |  "code":  "while (true)",
+               |  "binary": false
+               |}""".stripMargin.parseJson.asJsObject
+    Exec.serdes.read(j2) should matchPattern {
+      case BlackBoxExec(_, Some(Inline("while (true)")), None, false, false) =>
+    }
+
+    //Empty code should resolve as None
+    val j3 = """{
+               |  "kind": "blackbox",
+               |  "image": "docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1",
+               |  "code": " "
+               |}""".stripMargin.parseJson.asJsObject
+    Exec.serdes.read(j3) should matchPattern {
+      case BlackBoxExec(_, None, None, false, false) =>
+    }
+
+    val j4 = """{
+                 |  "kind": "blackbox",
+                 |  "image": "docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1",
+                 |  "code": {
+                 |    "attachmentName": "foo:bar",
+                 |    "attachmentType": "application/octet-stream",
+                 |    "length": 32768,
+                 |    "digest": "sha256-foo"
+                 |  },
+                 |  "binary": true,
+                 |  "main": "hello"
+                 |}""".stripMargin.parseJson.asJsObject
+    Exec.serdes.read(j4) should matchPattern {
+      case BlackBoxExec(_, Some(Attached("foo:bar", _, Some(32768), Some("sha256-foo"))), Some("hello"), false, true) =>
+    }
+  }
+
+  behavior of "blackbox exec serialization"
+
+  it should "serialize with inline attachment" in {
+    val bb = BlackBoxExec(
+      ImageName.fromString("docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1").get,
+      Some(Inline("foo")),
+      None,
+      false,
+      false)
+    val js = Exec.serdes.write(bb)
+
+    val js2 = """{
+                |  "kind": "blackbox",
+                |  "image": "docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1",
+                |  "binary": false,
+                |  "code": "foo"
+                |}""".stripMargin.parseJson.asJsObject
+    js shouldBe js2
+  }
+
+  it should "serialize with attached attachment" in {
+    val bb = BlackBoxExec(
+      ImageName.fromString("docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1").get,
+      Some(Attached("foo", ContentTypes.`application/octet-stream`, Some(42), Some("sha1-42"))),
+      None,
+      false,
+      true)
+    val js = Exec.serdes.write(bb)
+    println(js)
+
+    val js2 = """{
+                |  "kind": "blackbox",
+                |  "image": "docker-custom.com/openwhisk-runtime/magic/nodejs:0.0.1",
+                |  "binary": true,
+                |  "code": {
+                |    "attachmentName": "foo",
+                |    "attachmentType": "application/octet-stream",
+                |    "length": 42,
+                |    "digest": "sha1-42"
+                |  }
+                |}""".stripMargin.parseJson.asJsObject
+    js shouldBe js2
+  }
 
 Review comment:
   Nice tests, I like 👍 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services