【问题标题】:gcloud functions call giving an error for backgroundgcloud 函数调用给出背景错误
【发布时间】:2019-01-25 13:03:30
【问题描述】:
我正在使用 mocha 和 assert 测试 node js 应用程序。
从this link获取示例代码
我在本地和 gcloud 中都成功部署了 helloBackground 函数
然后我尝试执行 mocha 测试用例。
还尝试了各种方式调用gcloud函数描述here
然后在CMD中执行下面的命令
functions call helloBackground --data '{\"name\": \"John\"}'
这应该返回“你好约翰!”在命令提示符下。
但我收到一个错误
错误:TypeError:无法读取未定义的属性“名称”
请告诉我如何在 CMD 中传递正确的数据进行测试。
提前谢谢你。
【问题讨论】:
标签:
node.js
google-cloud-functions
gcloud
【解决方案1】:
查看您的错误消息,很可能是您在部署应用时使用的触发器参数引起的。 helloBackground 函数是一个后台函数,你应该使用后台函数触发器而不是--trigger-http。
例如:$ gcloud functions deploy helloBackground --runtime nodejs6 --trigger-resource you_bucket_name --trigger-event google.storage.object.finalize
您需要在应用的同一目录中创建一个空的 .txt 文件并将其上传到 Cloud Storage
$ gsutil cp test.txt gs://[ the name of your cloud storage bucket ]
您可以再次运行该应用程序。
你会发现更多关于函数类型的解释here
您可以在 Cloud Storage here
上关注这个文档齐全的教程