|
| 1 | +## Integration Tests |
| 2 | + |
| 3 | +The google-cloud-ruby integration tests are end-to-end tests that validate library functionality on real Google Cloud Platform hosting environments. The integration process deploys several Rack-based applications to Google Cloud Platform one by one, then validates google-cloud-ruby code by making requests to these test applications. |
| 4 | + |
| 5 | +All integration tests require [Cloud SDK](https://cloud.google.com/sdk/) for deployment. Following the instructions in [Authentication guide](../AUTHENTICATION.md) for installation and authentication. |
| 6 | + |
| 7 | +### Configuration |
| 8 | +First, make sure a Google Cloud Platform project is setup that satisfies the following requirements: |
| 9 | +* [Stackdriver Error Reporting API](https://console.cloud.google.com/apis/api/clouderrorreporting.googleapis.com/overview) is enabled. |
| 10 | +* Make sure a [Google Container Engine Cluster](https://cloud.google.com/container-engine/docs/clusters/operations) with permissions to access all the GCP services this library implements is properly setup and ready to use. It's easier to create the Cluster through [Cloud Platform Console](https://console.cloud.google.com/kubernetes/list). Keep in mind once the Cluster is create, the service permissions cannot be updated. |
| 11 | + |
| 12 | +Once Google Cloud SDK is installed and authenticated, make sure the following items are also configured properly: |
| 13 | +* Project ID is set: |
| 14 | +```sh |
| 15 | +$ gcloud config set project PROJECT_ID |
| 16 | +``` |
| 17 | +* Container Cluster is set: |
| 18 | +```sh |
| 19 | +$ gcloud config set container/cluster CLUSTER_NAME |
| 20 | +``` |
| 21 | +* Extend Cloud Build timeout to an hour: |
| 22 | +```sh |
| 23 | +$ gcloud config set container/build_timeout 3600 |
| 24 | +``` |
| 25 | +Additinoal to Cloud SDK, Google Container Engine requires [docker](https://www.docker.com/) for building docker images, and the [Kubernetes commandline tool](http://kubernetes.io/docs/user-guide/kubectl-overview/) for image deployment. |
| 26 | + |
| 27 | +Follow the [docker website](https://www.docker.com/products/docker) for docker installation instructions. The Kubernetes commandline tool can be installed through Cloud SDK: |
| 28 | +```sh |
| 29 | +$ gcloud components install kubectl |
| 30 | +``` |
| 31 | + |
| 32 | +### Usage |
| 33 | +To kick off the full integration test suite: |
| 34 | +```sh |
| 35 | +$ rake integration |
| 36 | +``` |
| 37 | + |
| 38 | +### Integration tests on Google App Engine |
| 39 | +To run the integration tests just on Google App Engine: |
| 40 | +```sh |
| 41 | +$ rake integration:gae |
| 42 | +``` |
| 43 | +This rake task automates the Google App Engine deployment by deploying the google-cloud-ruby libraries with sample application using the `gcloud app deploy` shell command. Each of the sample applications contains an app.yaml.example file that defines specific deployment procedure for that application. For example, the [Rails 5 app.yaml.example](rails5_app/app.yaml.example) file defines a custom entrypoint that allows bundler to install the sample application's dependencies and launch the application. |
| 44 | + |
| 45 | +After a successful deployment, each google-cloud-ruby libraries can then run its integration tests again the deployed sample application. For example, the [google-cloud-logging tests](google-cloud-logging/integration/) send HTTP requests to redefined routes on the sample application to trigger logs being generated. Then it's able to verify the result logs through gcloud sdk. |
| 46 | + |
| 47 | +### Integration tests on Google Container Engine |
| 48 | +To run the integration tests on Google Container Engine: |
| 49 | +```sh |
| 50 | +$ rake integration:gke |
| 51 | +``` |
| 52 | +Similar to the workflow of `integration:gae` task, the `integration:gke` task uses the Dockerfile.example file from each sample application as the template to build a docker image, deploy it to Google Container Registry, and deploy Google Container pods to launch the application. In the case of GKE pods configuration, all sample application shares a same configuration defined in [integration_rc.yaml.example](integration_rc.yaml.example) file. |
| 53 | + |
| 54 | +After the integration tests finish run against the deployed GKE sample application, the `integration:gke` application is also able to clean up all the resources created during the deployment. These resources include local test docker image, GCR test docker image, GKE ReplicationController, and GKE pods. |
| 55 | + |
| 56 | +### Integration tests on Google Compute Engine |
| 57 | +We're currently not supporting automated tests on Google Compute Engine environment for the following reasons: |
| 58 | +* Major functionalities such as metadata service accisibility, application default authentication are, operating system, and API accessibility are already covered by other automated tests. |
| 59 | +* Both GAE and GKE are currently hosted on GCE VMs. |
| 60 | +* It's harder to automate deployment on GCE environment than GAE or GKE, due to GCE's IaaS nature. |
| 61 | + |
| 62 | +### Write tests |
| 63 | + |
| 64 | +Each google-cloud-ruby libraries should define its own set of integration tests. It it doesn't already, make sure a corresponding `integration:gae` or `integration:gke` task exists at the package level. These tasks will be invoked by top level `integration` task when deployment is finished. Otherwise these package level tasks can also be invoked independently assume deployment already happened. |
| 65 | + |
| 66 | +Common test cases defined in google-cloud-*/integration/ directory will be run on both GAE and GKE environments. Environment specific test cases can be defined in google-cloud-*/integration/gae/ or google-cloud-*/integration/gke/ directories. Such test cases will only be run against the corresponding environment. |
0 commit comments