Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Overview
You can use this template to deploy some IBM Cloud Functions assets for you. The assets created by this template are described in the manifest.yaml file, which can be found at `template-hello-world/runtimes/your_language_choice/manifest.yaml`

The only assets described by this hello world template are a single action, named helloworld, which takes as input a message parameter.
The only assets described by this hello world template are a single action, named helloworld, which takes as input a name parameter.

You can use the wskdeploy tool to deploy this asset yourself using the manifest and available code.

Expand Down
22 changes: 22 additions & 0 deletions runtimes/nodejs-6/actions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
*
* main() will be invoked when you Run This Action.
*
* @param Cloud Functions actions accept a single parameter,
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "name": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
function main(params) {
if (params.name) {
return { greeting: `Hello ${params.name}` };
}
return { greeting: 'Hello stranger!' };
}

exports.main = main;
15 changes: 15 additions & 0 deletions runtimes/nodejs-6/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Wskdeploy manifest for hello-world

# Deployment using this manifest file creates the following OpenWhisk components:
# Package: openwhisk-helloworld
# Action: openwhisk-helloworld/helloworld.js

packages:
$PACKAGE_NAME:
version: 1.0
license: Apache-2.0
namespace: _
actions:
helloworld:
function: actions/helloworld.js
runtime: nodejs:6
22 changes: 22 additions & 0 deletions runtimes/nodejs-8/actions/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
*
* main() will be invoked when you Run This Action.
*
* @param Cloud Functions actions accept a single parameter,
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "name": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
function main(params) {
if (params.name) {
return { greeting: `Hello ${params.name}` };
}
return { greeting: 'Hello stranger!' };
}

exports.main = main;
15 changes: 15 additions & 0 deletions runtimes/nodejs-8/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Wskdeploy manifest for hello-world

# Deployment using this manifest file creates the following OpenWhisk components:
# Package: openwhisk-helloworld
# Action: openwhisk-helloworld/helloworld.js

packages:
$PACKAGE_NAME:
version: 1.0
license: Apache-2.0
namespace: _
actions:
helloworld:
function: actions/helloworld.js
runtime: nodejs:8
6 changes: 3 additions & 3 deletions runtimes/nodejs/actions/helloworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "message": "xxxx" }
* { "name": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
function main(params) {
if (params.message) {
return { "greeting": "Hello " + params.message };
if (params.name) {
return { "greeting": "Hello " + params.name };
} else {
return {"greeting": "Hello stranger!"}
}
Expand Down
22 changes: 22 additions & 0 deletions runtimes/php-7.1/actions/helloworld.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
*
* main() will be invoked when you Run This Action.
*
* @param Cloud Functions actions accept a single parameter,
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "name": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
function main(array $args) : array
{
$name = $args["name"] ?? "stranger";
$greeting = "Hello $name!";
echo $greeting;
return ["greeting" => $greeting];
}
15 changes: 15 additions & 0 deletions runtimes/php-7.1/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Wskdeploy manifest for hello-world

# Deployment using this manifest file creates the following OpenWhisk components:
# Package: openwhisk-helloworld
# Action: openwhisk-helloworld/helloworld.js

packages:
$PACKAGE_NAME:
version: 1.0
license: Apache-2.0
namespace: _
actions:
helloworld:
function: actions/helloworld.php
runtime: php:7.1
4 changes: 2 additions & 2 deletions runtimes/php/actions/helloworld.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "message": "xxxx" }
* { "name": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
function main(array $args) : array
{
$name = $args["message"] ?? "stranger";
$name = $args["name"] ?? "stranger";
$greeting = "Hello $name!";
echo $greeting;
return ["greeting" => $greeting];
Expand Down
21 changes: 21 additions & 0 deletions runtimes/python-3.6.4/actions/helloworld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
#
# main() will be invoked when you Run This Action.
#
# @param Cloud Functions actions accept a single parameter,
# which must be a JSON object.
#
# @return which must be a JSON object.
# It will be the output of this action.
#
#
import sys

def main(dict):
if 'name' in dict:
name = dict['name']
else:
name = 'stranger'
greeting = 'Hello ' + name + '!'
print(greeting)
return {'greeting':greeting}
15 changes: 15 additions & 0 deletions runtimes/python-3.6.4/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Wskdeploy manifest for hello-world

# Deployment using this manifest file creates the following OpenWhisk components:
# Package: openwhisk-helloworld
# Action: openwhisk-helloworld/helloworld.js

packages:
$PACKAGE_NAME:
version: 1.0
license: Apache-2.0
namespace: _
actions:
helloworld:
function: actions/helloworld.py
runtime: python-jessie:3
4 changes: 2 additions & 2 deletions runtimes/python/actions/helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import sys

def main(dict):
if 'message' in dict:
name = dict['message']
if 'name' in dict:
name = dict['name']
else:
name = 'stranger'
greeting = 'Hello ' + name + '!'
Expand Down
21 changes: 21 additions & 0 deletions runtimes/swift-3.1.1/actions/helloworld.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
*
* main() will be invoked when you Run This Action.
*
* @param Cloud Functions actions accept a single parameter,
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "name": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
func main(args: [String:Any]) -> [String:Any] {
if let name = args["name"] as? String {
return [ "greeting" : "Hello \(name)!" ]
} else {
return [ "greeting" : "Hello stranger!" ]
}
}
15 changes: 15 additions & 0 deletions runtimes/swift-3.1.1/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Wskdeploy manifest for hello-world

# Deployment using this manifest file creates the following OpenWhisk components:
# Package: openwhisk-helloworld
# Action: openwhisk-helloworld/helloworld.js

packages:
$PACKAGE_NAME:
version: 1.0
license: Apache-2.0
namespace: _
actions:
helloworld:
function: actions/helloworld.swift
runtime: swift:3.1.1
6 changes: 3 additions & 3 deletions runtimes/swift/actions/helloworld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "message": "xxxx" }
* { "name": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
func main(args: [String:Any]) -> [String:Any] {
if let message = args["message"] as? String {
return [ "greeting" : "Hello \(message)!" ]
if let name = args["name"] as? String {
return [ "greeting" : "Hello \(name)!" ]
} else {
return [ "greeting" : "Hello stranger!" ]
}
Expand Down
59 changes: 43 additions & 16 deletions tests/src/test/scala/templates/HelloTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ class HelloTests extends TestHelpers
val wsk = new Wsk()

//set parameters for deploy tests
val nodejsfolder = "../runtimes/nodejs/actions";
val phpfolder = "../runtimes/php/actions";
val pythonfolder = "../runtimes/python/actions";
val swiftfolder = "../runtimes/swift/actions";
val nodejs8folder = "../runtimes/nodejs-8/actions";
val nodejs6folder = "../runtimes/nodejs-6/actions";
val phpfolder = "../runtimes/php-7.1/actions";
val pythonfolder = "../runtimes/python-3/actions";
val swiftfolder = "../runtimes/swift-3.1.1/actions";

behavior of "Hello World Template"

/**
* Test the nodejs "hello world" template
* Test the nodejs 8 "hello world" template
*/
it should "invoke helloworld.js and get the result" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
it should "invoke nodejs 8 helloworld.js and get the result" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val name = "helloNode"
val file = Some(new File(nodejsfolder, "helloworld.js").toString());
val file = Some(new File(nodejs8folder, "helloworld.js").toString());
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, file)
}

withActivation(wsk.activation, wsk.action.invoke(name, Map("message" -> "Mindy".toJson))) {
withActivation(wsk.activation, wsk.action.invoke(name, Map("name" -> "Mindy".toJson))) {
_.response.result.get.toString should include("Mindy")
}
}
it should "invoke helloworld.js without input and get stranger" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
it should "invoke nodejs 8 helloworld.js without input and get stranger" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val name = "helloNode"
val file = Some(new File(nodejsfolder, "helloworld.js").toString());
val file = Some(new File(nodejs8folder, "helloworld.js").toString());
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, file)
}
Expand All @@ -67,8 +68,34 @@ class HelloTests extends TestHelpers
_.response.result.get.toString should include("stranger")
}
}

/**
* Test the nodejs 6 "hello world" template
*/
it should "invoke nodejs 6 helloworld.js and get the result" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val name = "helloNode"
val file = Some(new File(nodejs6folder, "helloworld.js").toString());
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, file)
}

withActivation(wsk.activation, wsk.action.invoke(name, Map("name" -> "Mindy".toJson))) {
_.response.result.get.toString should include("Mindy")
}
}
it should "invoke nodejs 6 helloworld.js without input and get stranger" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val name = "helloNode"
val file = Some(new File(nodejs6folder, "helloworld.js").toString());
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, file)
}

withActivation(wsk.activation, wsk.action.invoke(name)) {
_.response.result.get.toString should include("stranger")
}
}
/**
* Test the php "hello world" template
* Test the php 7.1 "hello world" template
*/
it should "invoke helloworld.php and get the result" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val name = "helloPhp"
Expand All @@ -77,7 +104,7 @@ class HelloTests extends TestHelpers
action.create(name, file)
}

withActivation(wsk.activation, wsk.action.invoke(name, Map("message" -> "Mindy".toJson))) {
withActivation(wsk.activation, wsk.action.invoke(name, Map("name" -> "Mindy".toJson))) {
_.response.result.get.toString should include("Mindy")
}
}
Expand All @@ -93,7 +120,7 @@ class HelloTests extends TestHelpers
}
}
/**
* Test the python "hello world" template
* Test the python 3 "hello world" template
*/
it should "invoke helloworld.py and get the result" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val name = "helloPython"
Expand All @@ -102,7 +129,7 @@ class HelloTests extends TestHelpers
action.create(name, file)
}

withActivation(wsk.activation, wsk.action.invoke(name, Map("message" -> "Mindy".toJson))) {
withActivation(wsk.activation, wsk.action.invoke(name, Map("name" -> "Mindy".toJson))) {
_.response.result.get.toString should include("Mindy")
}
}
Expand All @@ -118,7 +145,7 @@ class HelloTests extends TestHelpers
}
}
/**
* Test the swift "hello world" template
* Test the swift 3.1.1 "hello world" template
*/
it should "invoke helloworld.swift and get the result" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val name = "helloSwift"
Expand All @@ -127,7 +154,7 @@ class HelloTests extends TestHelpers
action.create(name, file)
}

withActivation(wsk.activation, wsk.action.invoke(name, Map("message" -> "Mindy".toJson))) {
withActivation(wsk.activation, wsk.action.invoke(name, Map("name" -> "Mindy".toJson))) {
_.response.result.get.toString should include("Mindy")
}
}
Expand Down