gcloud函数调用给出背景错误

问题描述 投票:0回答:1

我正在使用mocha和assert测试节点js app。

this link获取示例代码

我在本地和gcloud中成功部署了helloBackground函数

然后我尝试执行mocha测试用例。

也尝试了所有方式调用gcloud函数描述here

然后在CMD中执行以下命令

functions call helloBackground --data '{\"name\": \"John\"}'

这应该返回“你好约翰!”在命令提示符下。

但我收到一个错误

错误:TypeError:无法读取未定义的属性“name”

请告诉我如何在CMD中传递适当的数据进行测试。

先感谢您。

node.js google-cloud-functions gcloud
1个回答
1
投票

查看您的错误消息,很可能是由您在部署应用程序时使用的触发器参数引起的。 helloBackground函数是背景函数,而不是--trigger-http,您应该使用背景函数触发器。

例如:$ gcloud functions deploy helloBackground --runtime nodejs6 --trigger-resource you_bucket_name --trigger-event google.storage.object.finalize

您需要在应用的同一目录中创建一个空的.txt文件,然后将其上传到云存储

$ gsutil cp test.txt gs://[ the name of your cloud storage bucket ]

您可以再次运行该应用程序。

你会发现有关函数类型的更多解释here你可以按照这个有关云存储here的详细记录教程

© www.soinside.com 2019 - 2024. All rights reserved.