1

I am developing different Cloud Functions. Most of the functions have Google-Datastore, Pub/Sub and IoT external dependencies. I would like to run integration tests while deploying using cloudbuild.yaml.
I can test the unittest via pytest by having this in the cloudbuild.yaml file

steps:

- name: 'python:3.7'
  entrypoint: 'bash'
  args: 
    - '-c'
    - |
        pip3 install -r requirements.txt
        pytest 

- name: 'gcr.io/cloud-builders/gcloud'
  args:
  - functions
  - deploy
  - My-Function
  - --runtime=python37
  - --source=Soure_Dir
  - --entry-point=main
  - --trigger-topic=My-Function-Topic
  - --region=REGION

Is there any way of writing integration tests to test datastore, pub/sub, iot in this pipline? or is there any other way of testing the function locally?
What is the efficient way of testing the cloud-functions?

Hsn
  • 1,168
  • 2
  • 16
  • 39
  • I believe this question is too broad, so I recommending you to narrow it down to more specific inquiries. What I would do is first test the code itself as you have done and then have a a Cloud Function reserved for the testing stage once it has been deployed. – llompalles Apr 21 '20 at 11:42
  • thanks @llompalles, can you please elaborate what do you mean by reserving a Cloud function? do i need to make a new function for the testing? – Hsn Apr 21 '20 at 12:25
  • 1
    That exactly what I meant, creating a Cloud Function just for testing purposes. This approach is quite similar to many workflows which have a testing environment and then a production environment. – llompalles Apr 22 '20 at 13:57
  • 1
    One thing to notice is that by following [the instructions in this answer](https://stackoverflow.com/a/54898684/1119153) you can find some way to separate your unit tests from integration tests and describe that on your cloudbuild file – manasouza May 17 '20 at 14:32

0 Answers0