Google Cloud Professional Cloud Developer — Question 165
Your team is developing unit tests for Cloud Function code. The code is stored in a Cloud Source Repositories repository. You are responsible for implementing the tests. Only a specific service account has the necessary permissions to deploy the code to Cloud Functions. You want to ensure that the code cannot be deployed without first passing the tests. How should you configure the unit testing process?
Answer options
- A. Configure Cloud Build to deploy the Cloud Function. If the code passes the tests, a deployment approval is sent to you.
- B. Configure Cloud Build to deploy the Cloud Function, using the specific service account as the build agent. Run the unit tests after successful deployment.
- C. Configure Cloud Build to run the unit tests. If the code passes the tests, the developer deploys the Cloud Function.
- D. Configure Cloud Build to run the unit tests, using the specific service account as the build agent. If the code passes the tests, Cloud Build deploys the Cloud Function.
Correct answer: D
Explanation
Option D is correct because it ensures that the unit tests are run under the specific service account, and only if they pass will the deployment occur, thus enforcing the testing requirement before deployment. Option A sends an approval after deployment, which does not prevent code from being deployed without passing tests. Option B runs tests after deployment, which does not ensure compliance before deployment. Option C allows the developer to deploy without any enforcement of the tests being run in the Cloud Build pipeline.