如何为云函数编写e2e或集成测试,到目前为止,我已经可以使用bash自动化脚本,但在部署时,我无法轻松检测到它
gcloud functions deploy MyFunction --entry-point MyFunction --runtime go111 --trigger-http
发布于 2019-01-31 23:53:49
Bash是一个很好的起点,如何使用一些e2e测试工具,例如使用endly workflow e2e runner,您的部署工作流可能如下所示
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、sqs、sns、bigquery等)。
serverless_e2e
https://stackoverflow.com/questions/54451565
复制相似问题