How do I write e2e or integration testig for cloud function, so far I've been able to use bash automation script, but when deployment I can not easily detect it
gcloud functions deploy MyFunction --entry-point MyFunction --runtime go111 --trigger-http
Bash is a good starting point, how about using some e2e testing tools, for instance with endly workflow e2e runner your deployment workflow may look like the following
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]+([^
]+)
validateTriggerURL:
action: validator:assert
actual: ${deploy.Data.triggerURL}
expected: /HelloWorld/
post:
triggerURL: ${deploy.Data.triggerURL}
you can also achive the same with using cloudfunction service API calls
defaults:
credentials: $gcSecrets
pipeline:
deploy:
action: gcp/cloudfunctions:deploy
'@name': HelloWorld
entryPoint: HelloWorldFn
runtime: go111
source:
URL: ${appPath}/hello/
Finally, you can look into practical serverless e2e testing examples(cloudfunctions, lambda, firebase, firestore, dynamodb,pubsub, sqs,sns,bigquery etc ...)