到目前为止,我该如何针对云功能编写e2e或集成测试
我已经能够使用bash自动化脚本,但是在部署时我无法轻易地检测到它
gcloud functions deploy MyFunction --entry-point MyFunction --runtime go111 --trigger-http
最佳答案
Bash是一个很好的起点,例如,如何使用某些e2e测试工具
使用endly工作流e2e运行程序,您的部署工作流可能如下所示
pipeline:
deploy:
action: exec:run
comments: deploy HelloWord triggered by http
target: $target
sleepTimeMs: 1500
terminators:
- Do you want to continue
errors:
- ERROR
env:
GOOGLE_APPLICATION_CREDENTIALS: ${env.HOME}/.secret/${gcSecrets}.json
commands:
- cd $appPath
- export PATH=$PATH:${env.HOME}/google-cloud-sdk/bin/
- gcloud config set project $projectID
- ${cmd[4].stdout}:/Do you want to continue/ ? Y
- gcloud functions deploy HelloWorld --entry-point HelloWorld --runtime go111 --trigger-http
extract:
- key: triggerURL
regExpr: (?sm).+httpsTrigger:[^u]+url:[\s\t]+([^\r\n]+)
validateTriggerURL:
action: validator:assert
actual: ${deploy.Data.triggerURL}
expected: /HelloWorld/
post:
triggerURL: ${deploy.Data.triggerURL}
您也可以使用cloudfunction服务API调用来达到相同的效果
defaults:
credentials: $gcSecrets
pipeline:
deploy:
action: gcp/cloudfunctions:deploy
'@name': HelloWorld
entryPoint: HelloWorldFn
runtime: go111
source:
URL: ${appPath}/hello/
最后,您可以研究实用的无服务器e2e测试示例(cloudfunctions,lambda,firebase,firestore,dynamodb,pubsub,sms,sns,bigquery等)。
serverless_e2e