title: How do I test event trigger cloud function?
body: <p>I want to do unit testing on cloud functions, however, the function itself is an event trigger function that contains some helper functions. I want to test those helper functions as well. Here is the code sample</p>
  <pre><code>import os
  from google.cloud import vision
  from google.cloud import storage
  
  
  def face_detection(uri):
      &quot;&quot;&quot;
      This function detects the faces in the file
      located in Google Cloud Storage or the web
      Args:
          uri: the file located in Google Cloud Storage or the web
      returns:
          None: Prints the likelihood of the face expressions
          or returns an errors resonse in string format
      &quot;&quot;&quot;
  
  def trigger_event(event, context):
      &quot;&quot;&quot;
      Background Cloud Function to be triggered by Cloud Storage.
      This generic function logs relevant data when a file is changed.
      Args:
          event (dict):  The dictionary with data specific to this type of event.
                          The `data` field contains a description of the event in
                          the Cloud Storage `object` format described here:
                          https://cloud.google.com/storage/docs/json_api/v1/objects#resource
          context (google.cloud.functions.Context): Metadata of triggering event.
      Returns:
          None; the output is written to Stackdriver Logging
      &quot;&quot;&quot;
  
      bucket_name = event[&quot;bucket&quot;]
      source_img = event[&quot;name&quot;]
      tmp_download_path = f&quot;/tmp/{source_img}&quot;
  
      try:
          download_image(bucket_name, source_img, tmp_download_path)
          print(f&quot;Image {source_img} downloaded to {tmp_download_path}&quot;)
          # currenlty this makes sure there's one person
          # in the frame and prints a few other details
          face_detection(tmp_download_path)
      except Exception:
          pass
      finally:
          if os.path.isfile(tmp_download_path):
              os.remove(tmp_download_path)
          else:
              print(&quot;Error: %s file not found&quot; % tmp_download_path)
  
  
  def download_image(bucket_name, source_blob_name, destination_file_name):
      &quot;&quot;&quot;Downloads the specified image from cloud storage
      Args:
          bucket_name = &quot;your-bucket-name&quot;
          source_blob_name = &quot;image-name&quot;
          destination_file_name = &quot;local/path/to/file&quot;
      Returns:
          Local path to downloaded image
      &quot;&quot;&quot;
  
  def upload_processed_images(bucket_name, source_file_folder):
      &quot;&quot;&quot;Uploads images to the bucket.
      Args:
          bucket_name = &quot;your-bucket-name&quot;
          source_file_folder = Path to the folder that contains
                                  all the processed images
      Returns:
          None;
      &quot;&quot;&quot;
  
      storage_client = storage.Client()
      bucket = storage_client.bucket(bucket_name)
  
      for file_name in os.listdir(source_file_folder):
          blob = bucket.blob(file_name)
          blob.upload_from_filename(os.path.join(source_file_folder, file_name))
  
          print(&quot;File {} uploaded to {}.&quot;.format(file_name, bucket_name))
  </code></pre>
  <p>For example, if I want to test if the function upload_processed_images is actually working. I want it to be an unit test. Should I test locally? If the function is tested locally, will it connect to GCP with correct storage.Client()? Or I need to test it on the GCP platform?</p>
  <p>Thanks for any help.</p>